77 lines
1.7 KiB
C++
77 lines
1.7 KiB
C++
|
|
/*
|
|||
|
|
* ValueMath.hpp
|
|||
|
|
*
|
|||
|
|
* Created on: 25 <EFBFBD><EFBFBD><EFBFBD>. 2021 <EFBFBD>.
|
|||
|
|
* 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; //!<<3C><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
|||
|
|
ValueType right; //!<<3C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
|||
|
|
|
|||
|
|
bool isValid();
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
bool configure( Setting & config );
|
|||
|
|
|
|||
|
|
ValueInterface & left(); //!<<3C><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
|||
|
|
ValueInterface & right(); //!<<3C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
|||
|
|
|
|||
|
|
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_ */
|