MotorControlModuleSDFM_TMS3.../Projects/EFC_Communication/UMLibrary/schematic/ValueMath.hpp
2024-06-07 11:12:56 +03:00

77 lines
1.8 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* ValueMath.hpp
*
* Created on: 25 окт. 2021 г.
* Author: titov
*/
#ifndef UMLIBRARY_SCHEMATIC_VALUEMATH_HPP_
#define UMLIBRARY_SCHEMATIC_VALUEMATH_HPP_
#include "../systemic/IValueAsync.hpp"
#include <cmath>
#include <functional>
namespace schematic {
class EquationBase2 {
public:
typedef float ValueType;
typedef systemic::IValueType<ValueType> ValueInterface;
struct Setting {
ValueType left; //!<Левая часть выражения.
ValueType right; //!<Правая часть выражения.
bool isValid();
};
bool configure( Setting & config );
ValueInterface & left(); //!<Левая часть выражения.
ValueInterface & right(); //!<Правая часть выражения.
protected:
virtual void update() = 0;
struct EquationPart: public ValueInterface {
float value;
EquationBase2 & equation;
void set( ValueType new_value );
ValueType get() const;
EquationPart( EquationBase2 & equation );
} a, b;
EquationBase2();
};
template<typename Functor>
class Equation : public EquationBase2 {
public:
Equation( ValueInterface & result, Functor functor = Functor() ) :
result(result), functor(functor) {}
private:
ValueInterface & result;
Functor functor;
void update() {
result.set( functor( a.value, b.value ) );
}
};
typedef Equation< std::minus<float> > EquationSubtraction;
typedef Equation< std::plus<float> > EquationAddition;
typedef Equation< std::multiplies<float> > EquationMultiplication;
typedef Equation< std::divides<float> > EquationDivision;
typedef Equation< std::pointer_to_binary_function<float, float, float> > EquationCustom;
}
#endif /* UMLIBRARY_SCHEMATIC_VALUEMATH_HPP_ */