|
@@ -1,15 +1,71 @@
|
|
|
-#include "ModuleMath.h"
|
|
|
+#include "ModuleBase.h"
|
|
|
+
|
|
|
#include <iostream>
|
|
|
#include <cmath>
|
|
|
|
|
|
namespace mdd {
|
|
|
- ModuleMath::ModuleMath(MathOperation operation) {
|
|
|
- _operation = operation;
|
|
|
+
|
|
|
+ class ModuleMath : public ModuleBase {
|
|
|
+ enum class MathOperation : char {
|
|
|
+ ADD = 1,
|
|
|
+ SUBTRACT = 2,
|
|
|
+ MULTIPLY = 3,
|
|
|
+ DIVIDE = 4,
|
|
|
+ POWER = 5,
|
|
|
+ LOGARITHM = 6,
|
|
|
+ MINIMUM = 7,
|
|
|
+ MAXIMUM = 8,
|
|
|
+ LESS_THAN = 9,
|
|
|
+ GREATER_THAN = 10
|
|
|
+ };
|
|
|
+ const std::map<std::string, std::function<double(double, double)>> _ops = {
|
|
|
+ {"mutiply", [](double a, double b) {return a * b; }}
|
|
|
+ };
|
|
|
+ std::function<double(double, double)> operation;
|
|
|
+ private:
|
|
|
+ MathOperation _operation;
|
|
|
+ Property<std::string>::Ptr _operation_prop;
|
|
|
+
|
|
|
+ static std::vector<double> add(const std::vector<double>& val1, const std::vector<double>& val2);
|
|
|
+ static std::vector<double> subtract(const std::vector<double>& val1, const std::vector<double>& val2);
|
|
|
+ static std::vector<double> multiply(const std::vector<double>& val1, const std::vector<double>& val2);
|
|
|
+ static std::vector<double> divide(const std::vector<double>& val1, const std::vector<double>& val2);
|
|
|
+ static std::vector<double> power(const std::vector<double>& val1, const std::vector<double>& val2);
|
|
|
+ static std::vector<double> logarithm(const std::vector<double>& val1, const std::vector<double>& val2);
|
|
|
+ static std::vector<double> minimum(const std::vector<double>& val1, const std::vector<double>& val2);
|
|
|
+ static std::vector<double> maximum(const std::vector<double>& val1, const std::vector<double>& val2);
|
|
|
+ static std::vector<double> less(const std::vector<double>& val1, const std::vector<double>& val2);
|
|
|
+ static std::vector<double> greater(const std::vector<double>& val1, const std::vector<double>& val2);
|
|
|
+
|
|
|
+ public:
|
|
|
+ explicit ModuleMath();
|
|
|
+ void configure();
|
|
|
+ state update() override;
|
|
|
+ void setMathOperation(MathOperation operation);
|
|
|
+ MathOperation getMathOperation();
|
|
|
+ };
|
|
|
+
|
|
|
+ ModuleMath::ModuleMath() {
|
|
|
std::vector<double> default_val = {1};
|
|
|
addInput("Value", default_val);
|
|
|
addInput("Value", default_val);
|
|
|
addOutput("Value", default_val);
|
|
|
setType("Math");
|
|
|
+ _operation_prop = addSubProperty<std::string>("operation");
|
|
|
+ }
|
|
|
+
|
|
|
+ void ModuleMath::configure()
|
|
|
+ {
|
|
|
+ _operation = ModuleMath::MathOperation::ADD;
|
|
|
+ /*if (_operation_prop->Value() == "multiply")
|
|
|
+ {
|
|
|
+ _operation = ModuleMath::MathOperation::MULTIPLY;
|
|
|
+ }
|
|
|
+ else if (_operation_prop->Value() == "add")
|
|
|
+ {
|
|
|
+ _operation = ModuleMath::MathOperation::ADD;
|
|
|
+ }
|
|
|
+ */
|
|
|
}
|
|
|
|
|
|
std::vector<double> ModuleMath::add(const std::vector<double>&val1, const std::vector<double>&val2) {
|
|
@@ -236,10 +292,12 @@ namespace mdd {
|
|
|
_operation = operation;
|
|
|
}
|
|
|
|
|
|
- MathOperation ModuleMath::getMathOperation(){
|
|
|
+ ModuleMath::MathOperation ModuleMath::getMathOperation(){
|
|
|
return _operation;
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
+ADD_GENERATOR(mdd::ModuleMath);
|
|
|
|
|
|
//gdb
|
|
|
//catch throw
|