Pārlūkot izejas kodu

changed update methode

Willi Zschiebsch 5 gadi atpakaļ
vecāks
revīzija
aef2c32545

+ 3 - 1
lib/CMakeLists.txt

@@ -5,12 +5,13 @@ project(mdd_lib)
 
 add_library(${PROJECT_NAME} STATIC
         include/HandlerModule
-        include/Input.h
+        include/IInput.h
         include/IListener.h
         include/IModule.h
         include/Input.h
         include/IOutput.h
         include/IProcessor.h
+	include/IState.h
         include/IUnique.h
         include/ModuleBase.h
         include/ModuleHTTP.h
@@ -24,6 +25,7 @@ add_library(${PROJECT_NAME} STATIC
         include/ProcessorBase.h
         include/ProcessorEvolution.h
 	include/ProcessorManual.h
+	include/state.h
 
         src/Input.cpp
         src/ModuleBase.cpp

+ 3 - 1
lib/include/IInput.h

@@ -3,8 +3,10 @@
 
 #include "IUnique.h"
 #include "IOutput.h"
+#include "IState.h"
+
 namespace mdd{
-    class IInput : public IUnique{
+    class IInput : public IUnique, public IState{
     public:
         virtual const json& getValue() = 0;
         virtual json& setDefaultValue() = 0;

+ 2 - 1
lib/include/IModule.h

@@ -3,6 +3,7 @@
 
 #include "IOutput.h"
 #include "IInput.h"
+#include "state.h"
 #include <string>
 #include <vector>
 #include <memory>
@@ -19,7 +20,7 @@ namespace mdd {
         virtual std::vector<std::string> getOutputIDs() = 0;
         virtual std::shared_ptr<IOutput> getOutput(std::string output_id) = 0;
         virtual std::shared_ptr<IInput> getInput(std::string input_id) = 0;
-        virtual bool update() = 0;
+        virtual state update() = 0;
         virtual ~IModule() = default;
     };
 }

+ 2 - 3
lib/include/IOutput.h

@@ -3,17 +3,16 @@
 #include "json.hpp"
 #include <memory>
 #include "IUnique.h"
+#include "IState.h"
 
 namespace mdd
 {
     class IModule;
 
-    class IOutput : public IUnique{
+    class IOutput : public IUnique, public IState{
     public:
         virtual const json& getValue() = 0;
         virtual json& getValueInternal() = 0;
-        virtual bool hasChanged() = 0;
-        virtual void resetChange() = 0;
         virtual ~IOutput() = default;
     };
 }

+ 0 - 1
lib/include/IProcessor.h

@@ -6,7 +6,6 @@
 
 namespace mdd
 {
-
     class IProcessor: public  IModule{
     public:
         virtual std::string  addModule(std::shared_ptr<IModule> module) = 0;

+ 14 - 0
lib/include/IState.h

@@ -0,0 +1,14 @@
+#ifndef MDD_ISTATE_H
+#define MDD_ISTATE_H
+#include "state.h"
+
+namespace mdd
+{
+    class IState{
+    public:
+        virtual state getState() = 0;
+        virtual void resetState() = 0;
+    };
+}
+
+#endif //MDD_IOUTPUT_H

+ 5 - 2
lib/include/Input.h

@@ -3,7 +3,8 @@
 
 #include <string>
 #include <functional>
-#include "Output.h"
+#include "IInput.h"
+#include "IOutput.h"
 #include <memory>
 #include "IUnique.h"
 
@@ -28,11 +29,13 @@ namespace mdd {
         std::string setPrefix(std::string prefix) override;
         std::string setAppendix(int appendix) override;
 
+        state getState() override;
+        void resetState() override;
+
         const json& getValue() override;
         json& setDefaultValue() override;
         bool verify(const json & data) override;
         bool connect(std::shared_ptr<IOutput> output) override;
-
     };
 }
 

+ 1 - 0
lib/include/ModuleBase.h

@@ -2,6 +2,7 @@
 #define MDD_ModuleBase_H
 
 #include "Input.h"
+#include "Output.h"
 #include "IModule.h"
 
 namespace mdd {

+ 3 - 3
lib/include/ModuleHTTP.h

@@ -20,14 +20,14 @@ namespace mdd{
     protected:
         bool connect();
         std::string str_to_json(const std::string& input);
-        bool updateInputs();
-        bool updateOutputs();
+        state updateInputs();
+        state updateOutputs();
         void updateLayout();
 
     public:
         ModuleHTTP(std::string fname, std::string id, int port);
         ~ModuleHTTP();
-        bool update() override;
+        state update() override;
     };
 }
 

+ 3 - 3
lib/include/ModuleMath.h

@@ -3,7 +3,7 @@
 #include "ModuleBase.h"
 
 namespace mdd {
-    enum MathOperation {
+    enum class MathOperation : char {
         ADD = 1,
         SUBTRACT = 2,
         MULTIPLY = 3,
@@ -32,8 +32,8 @@ namespace mdd {
         static json greater(const json &val1, const json &val2);
 
     public:
-        explicit ModuleMath(MathOperation operation = ADD);
-        bool update() override;
+        explicit ModuleMath(MathOperation operation = MathOperation::ADD);
+        state update() override;
         void setMathOperation(MathOperation operation);
         MathOperation getMathOperation();
     };

+ 1 - 1
lib/include/ModuleMerge.h

@@ -11,7 +11,7 @@ namespace mdd {
 		int addModuleInput();
 		int removeModuleInput();
 		std::string setInputType(const std::string& input_id, const std::string& new_type);
-		bool update() override;
+		state update() override;
 	};
 }
 

+ 1 - 1
lib/include/ModuleParameter.h

@@ -9,7 +9,7 @@ namespace mdd {
        
     public:
         ModuleParameter();
-        bool update() override;
+        state update() override;
     };
 }
 

+ 1 - 1
lib/include/ModuleSQL.h

@@ -20,7 +20,7 @@ namespace mdd {
 	public:
 		ModuleSQL(std::string dbname);
 		~ModuleSQL();
-		bool update() override;
+		state update() override;
 	};
 }
 

+ 1 - 1
lib/include/ModuleSwitch.h

@@ -7,7 +7,7 @@ namespace mdd{
     class ModuleSwitch : public ModuleBase{
     public:
         ModuleSwitch();
-        bool update() override;
+        state update() override;
     };
 }
 #endif //MDD_MODULESWITCH_H

+ 3 - 3
lib/include/Output.h

@@ -6,7 +6,7 @@
 namespace mdd {
     class Output : public IOutput{
     private:
-        bool _changed;
+        state _state;
         json _value;
         std::string _prefix;
         std::string _type;
@@ -16,8 +16,8 @@ namespace mdd {
         Output(const std::string& type, int appendix, const json& initial);
         const json& getValue() override;
         json& getValueInternal() override;
-        bool hasChanged() override;
-        void resetChange() override;
+        state getState() override;
+        void resetState() override;
         std::string setType(std::string type) override;
         std::string getType() override;
         std::string getID() override;

+ 1 - 0
lib/include/ProcessorBase.h

@@ -3,6 +3,7 @@
 
 #include <list>
 #include "Input.h"
+#include "Output.h"
 #include "IProcessor.h"
 #include "HandlerModule.h"
 

+ 1 - 1
lib/include/ProcessorManual.h

@@ -6,7 +6,7 @@ namespace mdd {
     class ProcessorManual : public ProcessorBase {
     public:
         ProcessorManual();
-        bool update() override;
+        state update() override;
         std::shared_ptr<IOutput> getIteration();
     };
 }

+ 11 - 0
lib/include/UpdateState.h

@@ -0,0 +1,11 @@
+#ifndef STATE_H
+#define STATE_H
+
+namespace mdd {
+    enum class state : char {
+        ERROR = -1,
+        CHANGED = 0,
+        UNCHANGED = 1,
+    };
+}
+#endif

+ 11 - 0
lib/include/state.h

@@ -0,0 +1,11 @@
+#ifndef STATE_H
+#define STATE_H
+
+namespace mdd {
+    enum class state : char {
+        STATE_ERROR = -1,
+        CHANGED = 0,
+        UNCHANGED = 1
+    };
+}
+#endif

+ 13 - 0
lib/src/Input.cpp

@@ -31,6 +31,19 @@ namespace mdd{
         return  getID();
     }
 
+    state Input::getState() {
+        if (_output == nullptr) {
+            return state::UNCHANGED;
+        }
+        else {
+            return _output->getState();
+        }
+    }
+
+    void Input::resetState() {
+
+    }
+
     const json& Input::getValue() {
         if(_output == nullptr){
             return _value;

+ 15 - 9
lib/src/ModuleHTTP.cpp

@@ -49,7 +49,7 @@ namespace mdd{
         return str;
     }
 
-    bool ModuleHTTP::updateInputs() {
+    state ModuleHTTP::updateInputs() {
         Client cli(_id, _port);
 
         std::string body;
@@ -75,10 +75,10 @@ namespace mdd{
             val["value"] = inputs[index]["value"];
             addInput(inputs[index]["type"].get<std::string>(),val);
         }
-        return true;
+        return state::UNCHANGED;
     }
 
-    bool ModuleHTTP::updateOutputs() {
+    state ModuleHTTP::updateOutputs() {
         Client cli(_id, _port);
 
         std::string body;
@@ -91,21 +91,27 @@ namespace mdd{
         assert(res->body.empty());
         body =  std::string(R"()") + body;
         json outputs = json::parse(body);
-
+        state output_state = state::UNCHANGED;
         for(int j = 0; j < (int)getOutputs().size()-(int)outputs.size(); ++j){
             pop_backOutput();
+            output_state = state::CHANGED;
         }
         for(size_t i=0; i < getOutputs().size(); i++){
-            getOutput(i)->setType(outputs[i]["type"].get<std::string>());
-            getOutput(i)->setAppendix(i);
-            getOutput(i)->getValueInternal() = outputs[i];
+            //getOutput(i)->setType(outputs[i]["type"].get<std::string>());
+            //getOutput(i)->setAppendix(i);
+            getOutput(i)->resetState();
+            if (outputs[i].dump() != getOutput(i)->getValue().dump()) {
+                getOutput(i)->getValueInternal() = outputs[i];
+                output_state = getOutput(i)->getState();
+            }
         }
         for(int index = getOutputs().size(); index < outputs.size(); ++index){
             json val;
             val["value"] = outputs[index]["value"];
             addOutput(outputs[index]["type"].get<std::string>(),val);
+            output_state = state::CHANGED;
         }
-        return true;
+        return output_state;
     }
 
     void ModuleHTTP::updateLayout(){
@@ -136,7 +142,7 @@ namespace mdd{
         
     }
 
-    bool ModuleHTTP::update() {
+    state ModuleHTTP::update() {
         Client cli(_id, _port);
         json new_inputs;
         for (int i = 0; i < getInputs().size(); ++i) {

+ 102 - 35
lib/src/ModuleMath.cpp

@@ -6,7 +6,7 @@ namespace mdd {
     ModuleMath::ModuleMath(MathOperation operation) {
         _operation = operation;
         json default_val;
-        default_val["value"] = 1;
+        default_val["value"] = { 1 };
         addInput("Value", default_val);
         addInput("Value", default_val);
         addOutput("Value", default_val);
@@ -14,12 +14,19 @@ namespace mdd {
     }
 
     json ModuleMath::add(const json &val1, const json &val2) {
-        json ret = json::array();
+        json ret; //= json::array();
         if (val1.is_array()) {
-            for (int i = 0; i < val1.size(); i++) {
+            size_t size = std::max(val1.size(), val2.size());
+            for (int i = 0; i < size; i++) {
                 if (val2.is_array()) {
                     if (val1.size() == val2.size()) {
-                        ret.push_back(add(val1[i],val2[i]));
+                        ret.push_back(add(val1[i], val2[i]));
+                    }
+                    else if (1 == val1.size()) {
+                        ret.push_back(add(val1[1], val2[i]));
+                    }
+                    else if (1 == val2.size()) {
+                        ret.push_back(add(val1[i], val2[1]));
                     }
                 } else {
                     ret.push_back(add(val1[i],val2));
@@ -59,11 +66,18 @@ namespace mdd {
     json ModuleMath::subtract(const json &val1, const json &val2){
         json ret = json::array();
         if (val1.is_array()) {
-            for (int i = 0; i < val1.size(); i++) {
+            size_t size = std::max(val1.size(), val2.size());
+            for (int i = 0; i < size; i++) {
                 if (val2.is_array()) {
                     if (val1.size() == val2.size()) {
                         ret.push_back(subtract(val1[i],val2[i]));
                     }
+                    else if (1 == val1.size()) {
+                        ret.push_back(subtract(val1[1], val2[i]));
+                    }
+                    else if (1 == val2.size()) {
+                        ret.push_back(subtract(val1[i], val2[1]));
+                    }
                 } else {
                     ret.push_back(subtract(val1[i],val2));
                 }
@@ -102,10 +116,17 @@ namespace mdd {
     json ModuleMath::multiply(const json &val1, const json &val2){
         json ret = json::array();
         if (val1.is_array()) {
-            for (int i = 0; i < val1.size(); i++) {
+            size_t size = std::max(val1.size(), val2.size());
+            for (int i = 0; i < size; i++) {
                 if (val2.is_array()) {
                     if (val1.size() == val2.size()) {
-                        ret.push_back(multiply(val1[i],val2[i]));
+                        ret.push_back(multiply(val1[i], val2[i]));
+                    }
+                    else if (1 == val1.size()) {
+                        ret.push_back(multiply(val1[1], val2[i]));
+                    }
+                    else if (1 == val2.size()) {
+                        ret.push_back(multiply(val1[i], val2[1]));
                     }
                 } else {
                     ret.push_back(multiply(val1[i],val2));
@@ -145,10 +166,17 @@ namespace mdd {
     json ModuleMath::divide(const json &val1, const json &val2){
         json ret = json::array();
         if (val1.is_array()) {
-            for (int i = 0; i < val1.size(); i++) {
+            size_t size = std::max(val1.size(), val2.size());
+            for (int i = 0; i < size; i++) {
                 if (val2.is_array()) {
                     if (val1.size() == val2.size()) {
-                        ret.push_back(divide(val1[i],val2[i]));
+                        ret.push_back(divide(val1[i], val2[i]));
+                    }
+                    else if (1 == val1.size()) {
+                        ret.push_back(divide(val1[1], val2[i]));
+                    }
+                    else if (1 == val2.size()) {
+                        ret.push_back(divide(val1[i], val2[1]));
                     }
                 } else {
                     ret.push_back(divide(val1[i],val2));
@@ -188,11 +216,18 @@ namespace mdd {
     json ModuleMath::power(const json &val1, const json &val2){
         json ret = json::array();
         if (val1.is_array()) {
-            for (int i = 0; i < val1.size(); i++) {
+            size_t size = std::max(val1.size(), val2.size());
+            for (int i = 0; i < size; i++) {
                 if (val2.is_array()) {
                     if (val1.size() == val2.size()) {
                         ret.push_back(power(val1[i], val2[i]));
                     }
+                    else if (1 == val1.size()) {
+                        ret.push_back(power(val1[1], val2[i]));
+                    }
+                    else if (1 == val2.size()) {
+                        ret.push_back(power(val1[i], val2[1]));
+                    }
                 }
                 else {
                     ret.push_back(power(val1[i], val2));
@@ -238,11 +273,18 @@ namespace mdd {
     json ModuleMath::logarithm(const json &val1, const json &val2){
         json ret = json::array();
         if (val1.is_array()) {
-            for (int i = 0; i < val1.size(); i++) {
+            size_t size = std::max(val1.size(), val2.size());
+            for (int i = 0; i < size; i++) {
                 if (val2.is_array()) {
                     if (val1.size() == val2.size()) {
                         ret.push_back(logarithm(val1[i], val2[i]));
                     }
+                    else if (1 == val1.size()) {
+                        ret.push_back(logarithm(val1[1], val2[i]));
+                    }
+                    else if (1 == val2.size()) {
+                        ret.push_back(logarithm(val1[i], val2[1]));
+                    }
                 }
                 else {
                     ret.push_back(logarithm(val1[i], val2));
@@ -288,10 +330,17 @@ namespace mdd {
     json ModuleMath::minimum(const json &val1, const json &val2){
         json ret = json::array();
         if (val1.is_array()) {
-            for (int i = 0; i < val1.size(); i++) {
+            size_t size = std::max(val1.size(), val2.size());
+            for (int i = 0; i < size; i++) {
                 if (val2.is_array()) {
                     if (val1.size() == val2.size()) {
-                        ret.push_back(minimum(val1[i],val2[i]));
+                        ret.push_back(minimum(val1[i], val2[i]));
+                    }
+                    else if (1 == val1.size()) {
+                        ret.push_back(minimum(val1[1], val2[i]));
+                    }
+                    else if (1 == val2.size()) {
+                        ret.push_back(minimum(val1[i], val2[1]));
                     }
                 } else {
                     ret.push_back(minimum(val1[i],val2));
@@ -347,20 +396,27 @@ namespace mdd {
     json ModuleMath::maximum(const json &val1, const json &val2){
         json ret = json::array();
         if (val1.is_array()) {
-            for (int i = 0; i < val1.size(); i++) {
+            size_t size = std::max(val1.size(), val2.size());
+            for (int i = 0; i < size; i++) {
                 if (val2.is_array()) {
                     if (val1.size() == val2.size()) {
-                        ret.push_back(minimum(val1[i],val2[i]));
+                        ret.push_back(maximum(val1[i], val2[i]));
+                    }
+                    else if (1 == val1.size()) {
+                        ret.push_back(maximum(val1[1], val2[i]));
+                    }
+                    else if (1 == val2.size()) {
+                        ret.push_back(maximum(val1[i], val2[1]));
                     }
                 } else {
-                    ret.push_back(minimum(val1[i],val2));
+                    ret.push_back(maximum(val1[i],val2));
                 }
             }
 
         } else {
             if (val2.is_array()) {
                 for (int i = 0; i < val2.size(); i++) {
-                    ret.push_back(minimum(val1,val2[i]));
+                    ret.push_back(maximum(val1,val2[i]));
                 }
             } else {
                 if (val1.is_number() && val2.is_number()) {
@@ -406,11 +462,18 @@ namespace mdd {
     json ModuleMath::less(const json &val1, const json &val2){
         json ret = json::array();
         if (val1.is_array()) {
-            for (int i = 0; i < val1.size(); i++) {
+            size_t size = std::max(val1.size(), val2.size());
+            for (int i = 0; i < size; i++) {
                 if (val2.is_array()) {
                     if (val1.size() == val2.size()) {
                         ret.push_back(less(val1[i], val2[i]));
                     }
+                    else if (1 == val1.size()) {
+                        ret.push_back(less(val1[1], val2[i]));
+                    }
+                    if (1 == val2.size()) {
+                        ret.push_back(less(val1[i], val2[1]));
+                    }
                 }
                 else {
                     ret.push_back(less(val1[i], val2));
@@ -476,11 +539,18 @@ namespace mdd {
     json ModuleMath::greater(const json &val1, const json &val2){
         json ret = json::array();
         if (val1.is_array()) {
-            for (int i = 0; i < val1.size(); i++) {
+            size_t size = std::max(val1.size(), val2.size());
+            for (int i = 0; i < size; i++) {
                 if (val2.is_array()) {
                     if (val1.size() == val2.size()) {
                         ret.push_back(greater(val1[i], val2[i]));
                     }
+                    else if (1 == val1.size()) {
+                        ret.push_back(greater(val1[1], val2[i]));
+                    }
+                    else if (1 == val2.size()) {
+                        ret.push_back(greater(val1[i], val2[1]));
+                    }
                 }
                 else {
                     ret.push_back(greater(val1[i], val2));
@@ -543,58 +613,55 @@ namespace mdd {
         return ret;
     }
 
-    bool ModuleMath::update() {
+    state ModuleMath::update() {
         json ret = getOutput(0)->getValue()["value"];
 
         switch (_operation) {
-            case ADD:
+        case MathOperation::ADD:
                 ret = add(getInput(0)->getValue()["value"], getInput(1)->getValue()["value"]);
                 break;
 
-            case SUBTRACT:
+            case MathOperation::SUBTRACT:
                 ret = subtract(getInput(0)->getValue()["value"], getInput(1)->getValue()["value"]);
                 break;
 
-            case MULTIPLY:
+            case MathOperation::MULTIPLY:
                 ret = multiply(getInput(0)->getValue()["value"], getInput(1)->getValue()["value"]);
                 break;
 
-            case DIVIDE:
+            case MathOperation::DIVIDE:
                 ret = divide(getInput(0)->getValue()["value"], getInput(1)->getValue()["value"]);
                 break;
 
-            case POWER:
+            case MathOperation::POWER:
                 ret = power(getInput(0)->getValue()["value"], getInput(1)->getValue()["value"]);
                 break;
 
-            case LOGARITHM:
+            case MathOperation::LOGARITHM:
                 ret = logarithm(getInput(0)->getValue()["value"], getInput(1)->getValue()["value"]);
                 break;
 
-            case MINIMUM:
+            case MathOperation::MINIMUM:
                 ret = minimum(getInput(0)->getValue()["value"], getInput(1)->getValue()["value"]);
                 break;
 
-            case MAXIMUM:
+            case MathOperation::MAXIMUM:
                 ret = maximum(getInput(0)->getValue()["value"], getInput(1)->getValue()["value"]);
                 break;
 
-            case LESS_THAN:
+            case MathOperation::LESS_THAN:
                 ret = less(getInput(0)->getValue()["value"], getInput(1)->getValue()["value"]);
                 break;
 
-            case GREATER_THAN:
+            case MathOperation::GREATER_THAN:
                 ret = greater(getInput(0)->getValue()["value"], getInput(1)->getValue()["value"]);
                 break;
         }
-
+        getOutput(0)->resetState();
         if (ret.dump() != getOutput(0)->getValue()["value"].dump()) {
             getOutput(0)->getValueInternal()["value"] = ret ;
-            return true;
-        }
-        else{
-            return false;
         }
+        return getOutput(0)->getState();
     }
 
 

+ 3 - 5
lib/src/ModuleMerge.cpp

@@ -30,7 +30,7 @@ namespace mdd {
 		}
 		return "";
 	}
-	bool ModuleMerge::update() {
+	state ModuleMerge::update() {
 		json ret;
 		for (size_t i = 0; i < getInputs().size(); i++)
 		{
@@ -38,12 +38,10 @@ namespace mdd {
 			boost::algorithm::to_lower(key);
 			ret.emplace(key, getInput(i)->getValue()["value"]);
 		}
+		getOutput(0)->resetState();
 		if (ret.dump() != getOutput(0)->getValue().dump()) {
 			getOutput(0)->getValueInternal() = ret;
-			return true;
-		}
-		else {
-			return false;
 		}
+		return getOutput(0)->getState();
 	}
 }

+ 3 - 6
lib/src/ModuleParameter.cpp

@@ -9,15 +9,12 @@ namespace mdd {
         setType("Parameter");
     }
 
-    bool ModuleParameter::update() {
+    state ModuleParameter::update() {
         json ret = getInput(0)->getValue()["value"];
-        
+        getOutput(0)->resetState();
         if (ret.dump() != getOutput(0)->getValue()["value"].dump()) {
             getOutput(0)->getValueInternal()["value"] = ret;
-            return true;
-        }
-        else {
-            return false;
         }
+        return getOutput(0)->getState();
     }
 }

+ 6 - 4
lib/src/ModuleSQL.cpp

@@ -117,7 +117,7 @@ namespace mdd {
 
 
 		json default_val;
-		default_val["value"] = 1;
+		default_val["value"] = { 1 };
 		addInput(_content[0].key, default_val);
 		for (auto& cont :_content)
 		{
@@ -126,7 +126,7 @@ namespace mdd {
 		setType("SQL");
 	}
 
-	bool ModuleSQL::update() {
+	state ModuleSQL::update() {
 		int rc;
 		std::string sql;
 		sqlite3_stmt* res;
@@ -150,7 +150,7 @@ namespace mdd {
 		}
 
 		step = sqlite3_step(res);
-		bool state = false;
+		state state = state::UNCHANGED;
 		json ret;
 		if (step == SQLITE_ROW) {
 			int nCol = sqlite3_column_count(res);
@@ -158,9 +158,11 @@ namespace mdd {
 			for (size_t i = 0; i < nCol; i++)
 			{
 				std::string val = (char*)sqlite3_column_text(res, i);
+				val = "[" + val + "]";
+				getOutput(i)->resetState();
 				if (getOutput(i)->getValue()["value"].dump() != val) {
 					getOutput(i)->getValueInternal()["value"] = val;
-					state = true;
+					state = getOutput(i)->getState();
 				}
 			}
 		}

+ 34 - 14
lib/src/ModuleSwitch.cpp

@@ -4,30 +4,50 @@
 namespace mdd{
     ModuleSwitch::ModuleSwitch(){
         json default_val;
-        default_val["value"] = 42;
+        default_val["value"] = { 42 };
         addInput("Switch", default_val);
         addInput("Value", default_val);
         addInput("Default", default_val);
         addOutput("Value", default_val);
         setType("Switch");
     }
-    bool ModuleSwitch::update(){
-        int index = getInput(0)->getValue()["value"].get<int>();
-        if(index == 0){
-            index = 1;
+    state ModuleSwitch::update(){
+        json ret;
+        size_t length = 1;
+        if (getInput(0)->getValue()["value"].is_array()) {
+            length = getInput(0)->getValue()["value"].size();
         }
+        for (size_t i = 0; i < length; i++)
+        {
+            int index;
+            if (getInput(0)->getValue()["value"].is_array()) {
+                index = getInput(0)->getValue()["value"][i];
+            }
+            else {
+                index = getInput(0)->getValue()["value"].get<int>();
+            }
+           
+            if (index == 0) {
+                index = 1;
+            }
 
-        if(index > getInputs().size() - 1){
-            index = getInputs().size() - 1;
-        }
+            if (index > getInputs().size() - 1) {
+                index = getInputs().size() - 1;
+            }
 
-        json ret = getInput(index)->getValue()["value"];
-        if (ret.dump() != getOutput(0)->getValue()["value"].dump()) {
-            getOutput(0)->getValueInternal()["value"] = ret ;
-            return true;
+            if (getInput(0)->getValue()["value"].is_array()) {
+                ret.push_back(getInput(index)->getValue()["value"]);
+            }
+            else {
+                ret = getInput(index)->getValue()["value"];
+            }
         }
-        else{
-            return false;
+        getOutput(0)->resetState();
+        if (ret.dump() != getOutput(0)->getValue()["value"].dump()) {
+            getOutput(0)->getValueInternal()["value"] = ret;
         }
+        
+        return getOutput(0)->getState();
+
     }
 }

+ 4 - 4
lib/src/Output.cpp

@@ -1,7 +1,7 @@
 #include "Output.h"
 namespace mdd {
     Output::Output( const std::string& type, int appendix, const json& initial) :
-            _changed(false)
+            _state(state::UNCHANGED)
     {
         _appendix = appendix;
         _prefix = "";
@@ -12,15 +12,15 @@ namespace mdd {
     const json& Output::getValue() { return _value; }
 
     json& Output::getValueInternal() {
-        _changed = true;
+        _state = state::CHANGED;
         return _value;
     }
 
     std::string Output::getType() { return _type; }
 
-    bool Output::hasChanged() { return _changed; }
+    state Output::getState() { return _state; } 
 
-    void Output::resetChange() { _changed = false; }
+    void Output::resetState() { _state = state::UNCHANGED; }
 
     std::string Output::setType(std::string type){
         _type = type;

+ 9 - 9
lib/src/ProcessorManual.cpp

@@ -7,17 +7,17 @@ namespace mdd {
         addProcessorOutput("Iterator", "{ \"value\": 0 }"_json);
     }
 
-    bool ProcessorManual::update() {
-        bool ret = false;
-        bool group_state = true;
-        while(group_state){
+    state ProcessorManual::update() {
+        state ret = state::UNCHANGED;
+        state group_state = state::CHANGED;
+        while(group_state == state::CHANGED){
             getProcessorOutput(0)->getValueInternal()["value"]= getProcessorOutput(0)->getValue()["value"].get<int>()+1;
-            group_state = false;
+            group_state = state::UNCHANGED;
             for (int i = 0; i < getModules().size(); ++i) {
-                bool module_state = getModule(i)->update();
-                if(module_state){
-                    group_state=true;
-                    ret = true;
+                state module_state = getModule(i)->update();
+                if(module_state == state::CHANGED){
+                    group_state = state::CHANGED;
+                    ret = state::CHANGED;
                 }
             }
         }

+ 2 - 1
lib/test/test_ModuleHTTP.cpp

@@ -149,9 +149,10 @@ TEST(ModuleHTTP, update_intern){
         EXPECT_EQ(inputs_types[i], "INPUT");
         EXPECT_EQ(module.getInput(inputs_ids[i])->getValue()["value"].get<int>(), 10-i);
     }
-
+    std::cout << "WORKED" << std::endl;
     auto outputs_types = module.getOutputs();
     auto outputs_ids = module.getOutputIDs();
+    std::cout << module.getOutput(outputs_ids[0])->getValue()["value"].dump() << std::endl;
     EXPECT_EQ(module.getOutput(outputs_ids[0])->getValue()["value"].get<int>(), 19);
     EXPECT_EQ(module.getOutput(outputs_ids[1])->getValue()["value"].get<int>(), 64);
     EXPECT_EQ(module.getOutput(outputs_ids[2])->getValue()["value"].get<int>(), 1);

+ 4 - 4
lib/test/test_ModuleMath.cpp

@@ -14,7 +14,7 @@ TEST(ModuleMath, INT_PLUS_INT){
     ModuleMath test = ModuleMath();
     test.update();
 
-    EXPECT_EQ(test.getOutput(test.getOutputIDs()[0])->getValue()["value"].get<int>(), 2);
+    EXPECT_EQ(test.getOutput(test.getOutputIDs()[0])->getValue()["value"][0].get<int>(), 2);
 }
 
 TEST(ModuleMath, FLOAT_PLUS_FLOAT){
@@ -63,7 +63,7 @@ TEST(ModuleMath, ARRAY_PLUS_INT){
 }
 
 TEST(ModuleMath, ARRAY_MINUS_ARRAY){
-    ModuleMath test = ModuleMath(SUBTRACT);
+    ModuleMath test = ModuleMath(MathOperation::SUBTRACT);
     test.getInput(test.getInputIDs()[0])->setDefaultValue()["value"] = {10,31,3,45};
     test.getInput(test.getInputIDs()[1])->setDefaultValue()["value"] = {1,2.5,23,23};
     test.update();
@@ -72,7 +72,7 @@ TEST(ModuleMath, ARRAY_MINUS_ARRAY){
 }
 
 TEST(ModuleMath, ARRAY_MAL_ARRAY){
-    ModuleMath test = ModuleMath(MULTIPLY);
+    ModuleMath test = ModuleMath(MathOperation::MULTIPLY);
     test.getInput(test.getInputIDs()[0])->setDefaultValue()["value"] = {10,30,-3.5,45};
     test.getInput(test.getInputIDs()[1])->setDefaultValue()["value"] = {1,2.5,2.25,20};
     test.update();
@@ -81,7 +81,7 @@ TEST(ModuleMath, ARRAY_MAL_ARRAY){
 }
 
 TEST(ModuleMath, ARRAY_DURCH_ARRAY){
-    ModuleMath test = ModuleMath(DIVIDE);
+    ModuleMath test = ModuleMath(MathOperation::DIVIDE);
     test.getInput(test.getInputIDs()[0])->setDefaultValue()["value"] = {10,30,-3.5,45};
     test.getInput(test.getInputIDs()[1])->setDefaultValue()["value"] = {4,2.5,2,20};
     test.update();

+ 3 - 3
lib/test/test_ModuleSwitch.cpp

@@ -38,17 +38,17 @@ TEST(ModuleSwitch, EasySwitch){
 
 TEST(ModuleSwitch, ConnectTest){
 
-    ModuleMath f0 = ModuleMath(MULTIPLY);
+    ModuleMath f0 = ModuleMath(MathOperation::MULTIPLY);
     auto inputs = f0.getInputIDs();
     f0.getInput(inputs[0])->setDefaultValue()["value"] = 1;
     f0.getInput(inputs[1])->setDefaultValue()["value"] = 1;
 
-    ModuleMath f1 = ModuleMath(MULTIPLY);
+    ModuleMath f1 = ModuleMath(MathOperation::MULTIPLY);
     inputs = f1.getInputIDs();
     f1.getInput(inputs[0])->setDefaultValue()["value"] = 2;
     f1.getInput(inputs[1])->setDefaultValue()["value"] = 3;
 
-    ModuleMath f2 = ModuleMath(MULTIPLY);
+    ModuleMath f2 = ModuleMath(MathOperation::MULTIPLY);
     inputs = f2.getInputIDs();
     f2.getInput(inputs[0])->setDefaultValue()["value"] = 5;
     f2.getInput(inputs[1])->setDefaultValue()["value"] = 7;

+ 9 - 9
lib/test/test_ProcessorManual.cpp

@@ -10,22 +10,22 @@ using namespace mdd;
 TEST(ProcessorManual, CalculateSimpleFormula){
     //f4:(f3:(f1:(5*3)-f2:(4+5))/2)==(15-9)/2==6/2==3
     std::vector<std::string> inputs;
-    std::shared_ptr<ModuleMath> f1 = std::make_shared<ModuleMath>(MULTIPLY);
+    std::shared_ptr<ModuleMath> f1 = std::make_shared<ModuleMath>(MathOperation::MULTIPLY);
     inputs = f1->getInputIDs();
     f1->getInput(inputs[0])->setDefaultValue()["value"] = 5;
     f1->getInput(inputs[1])->setDefaultValue()["value"] = 3;
 
-    std::shared_ptr<ModuleMath> f2 = std::make_shared<ModuleMath>(ADD);
+    std::shared_ptr<ModuleMath> f2 = std::make_shared<ModuleMath>(MathOperation::ADD);
     inputs = f2->getInputIDs();
     f2->getInput(inputs[0])->setDefaultValue()["value"] = 4;
     f2->getInput(inputs[1])->setDefaultValue()["value"] = 5;
 
-    std::shared_ptr<ModuleMath> f3 = std::make_shared<ModuleMath>(SUBTRACT);
+    std::shared_ptr<ModuleMath> f3 = std::make_shared<ModuleMath>(MathOperation::SUBTRACT);
     inputs = f3->getInputIDs();
     f3->getInput(inputs[0])->connect(f1->getOutput(f1->getOutputIDs()[0]));
     f3->getInput(inputs[1])->connect(f2->getOutput(f2->getOutputIDs()[0]));
 
-    std::shared_ptr<ModuleMath> f4 = std::make_shared<ModuleMath>(DIVIDE);
+    std::shared_ptr<ModuleMath> f4 = std::make_shared<ModuleMath>(MathOperation::DIVIDE);
     inputs = f4->getInputIDs();
     f4->getInput(inputs[0])->connect(f3->getOutput(f3->getOutputIDs()[0]));
     f4->getInput(inputs[1])->setDefaultValue()["value"] = 2;
@@ -52,22 +52,22 @@ TEST(ProcessorManual, CalculateSimpleFormula){
 TEST(ProcessorManual, CalculateAdvancedFormula){
     //f4:(f3:(f1:(5*3)-f2:(4+5))/2)==(15-9)/2==6/2==3
     std::vector<std::string> inputs;
-    std::shared_ptr<ModuleMath> f1 = std::make_shared<ModuleMath>(MULTIPLY);
+    std::shared_ptr<ModuleMath> f1 = std::make_shared<ModuleMath>(MathOperation::MULTIPLY);
     inputs = f1->getInputIDs();
     f1->getInput(inputs[0])->setDefaultValue()["value"] = 5;
     f1->getInput(inputs[1])->setDefaultValue()["value"] = 3;
 
-    std::shared_ptr<ModuleMath> f2 = std::make_shared<ModuleMath>(ADD);
+    std::shared_ptr<ModuleMath> f2 = std::make_shared<ModuleMath>(MathOperation::ADD);
     inputs = f2->getInputIDs();
     f2->getInput(inputs[0])->setDefaultValue()["value"] = 4;
     f2->getInput(inputs[1])->setDefaultValue()["value"] = 5;
 
-    std::shared_ptr<ModuleMath> f3 = std::make_shared<ModuleMath>(SUBTRACT);
+    std::shared_ptr<ModuleMath> f3 = std::make_shared<ModuleMath>(MathOperation::SUBTRACT);
     inputs = f3->getInputIDs();
     f3->getInput(inputs[0])->connect(f1->getOutput(f1->getOutputIDs()[0]));
     f3->getInput(inputs[1])->connect(f2->getOutput(f2->getOutputIDs()[0]));
 
-    std::shared_ptr<ModuleMath> f4 = std::make_shared<ModuleMath>(DIVIDE);
+    std::shared_ptr<ModuleMath> f4 = std::make_shared<ModuleMath>(MathOperation::DIVIDE);
     inputs = f4->getInputIDs();
     f4->getInput(inputs[0])->connect(f3->getOutput(f3->getOutputIDs()[0]));
     f4->getInput(inputs[1])->setDefaultValue()["value"] = 2;
@@ -86,7 +86,7 @@ TEST(ProcessorManual, CalculateAdvancedFormula){
 TEST(ProcessorManual, CalculateExtremeFormula){
     //x_0=8, x_i=x_{i-1}/2
     std::shared_ptr<ModuleSwitch> switchModule =  std::make_shared<ModuleSwitch>();
-    std::shared_ptr<ModuleMath> calcModule = std::make_shared<ModuleMath>(DIVIDE);
+    std::shared_ptr<ModuleMath> calcModule = std::make_shared<ModuleMath>(MathOperation::DIVIDE);
     std::shared_ptr<ProcessorManual> processor = std::make_shared<ProcessorManual>();
     processor->addModule(switchModule);
     processor->addModule(calcModule);