Willi Zschiebsch 4 years ago
parent
commit
38e0095e63

+ 0 - 2
CMakeLists.txt

@@ -1,5 +1,3 @@
-
-
 cmake_minimum_required(VERSION 3.8.0)
 project(mdd)
 option(TESTS_ENABLED "enable unit tests" ON)

+ 12 - 3
lib/CMakeLists.txt

@@ -1,10 +1,12 @@
 cmake_minimum_required(VERSION 3.8.0)
 project(mdd_lib)
 
-add_library(${PROJECT_NAME}
+add_library(${PROJECT_NAME} SHARED
 	include/Connector.h
+	include/Generator.h
         include/HandlerModule
 	include/IConnection.h
+	include/IGenerator.h
         include/IInput.h
         include/IModule.h
         include/Input.h
@@ -12,11 +14,10 @@ add_library(${PROJECT_NAME}
 	include/IOptimizer.h
         include/IOutput.h
         include/IProcessor.h
+	include/IProperty.h
 	include/IState.h
         include/IUnique.h
         include/ModuleBase.h
-        include/ModuleHTTP.h
-        include/ModuleMath.h
 	include/ModuleMerge.h
 	include/ModuleParameter.h
 	include/ModuleSplitt.h
@@ -28,9 +29,11 @@ add_library(${PROJECT_NAME}
         include/ProcessorBase.h
         include/ProcessorEvolution.h
 	include/ProcessorStandard.h
+	include/Property.h
 	include/state.h
 
 	src/Connector.cpp
+	src/Generator.cpp
         src/Input.cpp
         src/ModuleBase.cpp
         src/ModuleHTTP.cpp
@@ -54,6 +57,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC
 
 target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES} sqlite3)
 
+set_target_properties( ${PROJECT_NAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )
 if(WIN32)
 	target_compile_options(${PROJECT_NAME} PRIVATE /bigobj)
 endif(WIN32)
@@ -63,6 +67,11 @@ install(DIRECTORY include DESTINATION .)
 install(TARGETS ${PROJECT_NAME} DESTINATION lib/$<CONFIG> EXPORT targets)
 install(EXPORT targets DESTINATION cmake)
 
+add_custom_command(TARGET mdd_lib POST_BUILD
+    COMMAND ${CMAKE_COMMAND} -E copy
+	"$<TARGET_FILE:mdd_lib>"
+	"${CMAKE_BINARY_DIR}/lib/test/$<CONFIGURATION>")
+
 
 if(${TESTS_ENABLED})
     add_subdirectory(test)

+ 0 - 2
lib/include/Connector.h

@@ -6,8 +6,6 @@
 #include "Input.h"
 #include "Output.h"
 
-#include "ModuleHTTP.h"
-#include "ModuleMath.h"
 #include "ModuleMerge.h"
 #include "ModuleSplitt.h"
 #include "ModuleSQL.h"

+ 38 - 0
lib/include/Generator.h

@@ -0,0 +1,38 @@
+
+
+#pragma once
+
+#include <map>
+#include <string>
+#include "IGenerator.h"
+
+namespace mdd
+{
+	template <class MODULE_CLASS>
+	class Generator
+		: public IGenerator
+	{
+
+		virtual std::shared_ptr<IModule> Generate()
+		{
+			return std::make_shared<MODULE_CLASS>();
+		}
+	};
+
+	std::map<std::string, std::shared_ptr<IGenerator>>&
+		GetGenerators(
+			const std::string& name = "", 
+			const std::shared_ptr<IGenerator>& generator = nullptr);
+
+	template<class MODULE_CLASS>
+	class GeneratorRegistration
+	{
+	public:
+		GeneratorRegistration(const std::string& name)
+		{
+			GetGenerators(name.substr(6), std::make_shared<Generator<MODULE_CLASS>>());
+		}
+	};
+}
+
+#define ADD_GENERATOR(CLASS) namespace{mdd::GeneratorRegistration<CLASS> reg_sdewfdsf(typeid(CLASS).name());}

+ 16 - 0
lib/include/IGenerator.h

@@ -0,0 +1,16 @@
+
+#pragma once
+
+#include <memory>
+#include "IModule.h"
+
+namespace mdd
+{
+	class IGenerator
+	{
+	public:
+		virtual ~IGenerator() {}
+
+		virtual std::shared_ptr<IModule> Generate() = 0;
+	};
+}

+ 8 - 3
lib/include/IModule.h

@@ -3,6 +3,7 @@
 
 #include "IOutput.h"
 #include "IInput.h"
+#include "IProperty.h"
 #include "state.h"
 #include <string>
 #include <vector>
@@ -11,8 +12,10 @@
 namespace mdd {
     class IOutput;
 
-    class IModule : public IUnique{
+    class IModule : public IUnique, public IProperty{
     public:
+        typedef std::shared_ptr<IModule> Ptr;
+
         virtual void updateID() = 0;
         virtual std::vector<std::string> getInputs() = 0;
         virtual std::vector<std::string> getOutputs() = 0;
@@ -20,14 +23,16 @@ namespace mdd {
         virtual std::vector<std::string> getOutputIDs() = 0;
         virtual std::vector<state> getInputStates() = 0;
         virtual std::vector<state> getOutputStates() = 0;
-        virtual std::shared_ptr<IOutput> getOutput(std::string output_id) = 0;
-        virtual std::shared_ptr<IInput> getInput(std::string input_id) = 0;
+        virtual std::shared_ptr<IOutput> getOutput(const std::string& output_id) = 0;
+        virtual std::shared_ptr<IInput> getInput(const std::string& input_id) = 0;
         virtual std::vector <std::shared_ptr<IOutput>> getInputConnections() = 0;
         virtual std::vector <std::vector <std::shared_ptr<IInput>>> getOutputConnections() = 0;
         virtual std::vector <std::shared_ptr<IInput>> getOptimizableInputs() = 0;
         virtual std::vector <std::shared_ptr<IOutput>> getOptimizableOutputs() = 0;
         virtual state update() = 0;
         virtual ~IModule() = default;
+
+        virtual void configure() = 0;
     };
 }
 #endif //MDD_IMODULE_H

+ 55 - 0
lib/include/IProperty.h

@@ -0,0 +1,55 @@
+
+
+#pragma once
+
+#include <memory>
+#include <string>
+
+namespace mdd
+{
+	class IPropertyValue
+	{
+	public:
+		virtual ~IPropertyValue(){}
+		virtual std::string GetPropertyType() = 0;
+	};
+
+	template<typename TYPE>
+	class PropertyValue : public IPropertyValue
+	{
+	public:
+		std::string GetPropertyType()
+		{
+			return typeid(TYPE).name();
+		}
+
+		std::shared_ptr<TYPE> value = std::make_shared<TYPE>();
+	};
+
+	class IProperty
+	{
+	protected:
+		virtual IPropertyValue* GetPropertyValue() = 0;
+
+	public:
+
+		virtual ~IProperty(){}
+
+		virtual std::shared_ptr<IProperty> GetSubProp(const std::string& name) = 0;
+
+
+		template<typename EXPECTED_TYPE>
+		std::shared_ptr<EXPECTED_TYPE> Value()
+		{
+			if (GetPropertyValue()->GetPropertyType() != typeid(EXPECTED_TYPE).name())
+			{
+				return std::make_shared<EXPECTED_TYPE>();
+			}
+			else
+			{
+				return dynamic_cast<PropertyValue<EXPECTED_TYPE>>(GetPropertyValue())->value;
+			}
+		}
+	};
+
+}

+ 2 - 2
lib/include/IUnique.h

@@ -5,10 +5,10 @@
 namespace mdd{
     class IUnique{
     public:
-        virtual std::string setType(std::string type) = 0;
+        virtual std::string setType(const std::string& type) = 0;
         virtual std::string getType() = 0;
         virtual std::string getID() = 0;
-        virtual std::string setPrefix(std::string prefix) = 0;
+        virtual std::string setPrefix(const std::string& prefix) = 0;
         virtual std::string setAppendix(int appendix) = 0;
     };
 }

+ 2 - 2
lib/include/Input.h

@@ -26,10 +26,10 @@ namespace mdd {
     public:
         Input(const std::string &type, int appendix, const std::vector<double>& default_value);
         //const std::function<bool(const json &)> &verification = [](const json&) { return true; }
-        std::string setType(std::string type) override;
+        std::string setType(const std::string& type) override;
         std::string getType() override;
         std::string getID() override;
-        std::string setPrefix(std::string prefix) override;
+        std::string setPrefix(const std::string& prefix) override;
         std::string setAppendix(int appendix) override;
 
         state getState() override;

+ 10 - 5
lib/include/ModuleBase.h

@@ -4,10 +4,12 @@
 #include "Input.h"
 #include "Output.h"
 #include "IModule.h"
+#include "Property.h"
+#include "Generator.h"
 
 namespace mdd {
 
-class ModuleBase : public  IModule{
+class ModuleBase : public  IModule, protected Property<bool>{
     private:
         std::string _prefix = "";
         std::string _type = "";
@@ -16,6 +18,7 @@ class ModuleBase : public  IModule{
         std::vector<std::shared_ptr<Output>> _outputs;
 
     protected:
+        virtual void configure() {};
         std::shared_ptr<IOutput> getOutput(int handle);
         std::shared_ptr<IInput> getInput(int handle);
         int addInput(const std::string& type, const std::vector<double>& value);
@@ -30,6 +33,8 @@ class ModuleBase : public  IModule{
         int eraseInput(int index);
         int eraseOutput(int index);
 
+        IPropertyValue* GetPropertyValue();
+        std::shared_ptr<IProperty> GetSubProp(const std::string& name);
     public:
         std::vector<std::string> getInputs() override;
         std::vector<std::string> getInputIDs() override;
@@ -41,12 +46,12 @@ class ModuleBase : public  IModule{
         std::vector <std::vector <std::shared_ptr<IInput>>> getOutputConnections() override;
         std::vector <std::shared_ptr<IInput>> getOptimizableInputs() override;
         std::vector <std::shared_ptr<IOutput>> getOptimizableOutputs() override;
-        std::shared_ptr<IOutput> getOutput(std::string output_id) override;
-        std::shared_ptr<IInput> getInput(std::string input_id) override;
-        std::string setType(std::string type) override;
+        std::shared_ptr<IOutput> getOutput(const std::string& output_id) override;
+        std::shared_ptr<IInput> getInput(const std::string& input_id) override;
+        std::string setType(const std::string& type) override;
         std::string getType() override;
         std::string getID() override;
-        std::string setPrefix(std::string prefix) override;
+        std::string setPrefix(const std::string& prefix) override;
         std::string setAppendix(int appendix) override;
         void updateID() override ;
     };

+ 0 - 40
lib/include/ModuleHTTP.h

@@ -1,40 +0,0 @@
-#ifndef MDD_MODULEHTTP_H
-#define MDD_MODULEHTTP_H
-
-#include "ModuleBase.h"
-#include <httplib.h>
-#include <memory>
-
-namespace boost {
-    namespace process{
-        class child;
-    }
-};
-using namespace boost::process;
-
-
-using namespace httplib;
-
-namespace mdd{
-    class ModuleHTTP : public ModuleBase{
-    private:
-        std::string _fname;
-        std::string _id;
-        int _port;
-        std::unique_ptr<child> _child;
-
-    protected:
-        bool connect();
-        std::string str_to_json(const std::string& input);
-        state updateInputs();
-        state updateOutputs();
-        void updateLayout();
-
-    public:
-        ModuleHTTP(std::string fname, std::string id, int port);
-        ~ModuleHTTP();
-        state update() override;
-    };
-}
-
-#endif //MDD_MODULEHTTP_H

+ 0 - 41
lib/include/ModuleMath.h

@@ -1,41 +0,0 @@
-#ifndef MDD_MODULEMATH_H
-#define MDD_MODULEMATH_H
-#include "ModuleBase.h"
-
-namespace mdd {
-    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
-    };
-
-    class ModuleMath : public ModuleBase {
-    private:
-        MathOperation _operation;
-
-        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(MathOperation operation = MathOperation::ADD);
-        state update() override;
-        void setMathOperation(MathOperation operation);
-        MathOperation getMathOperation();
-    };
-}
-#endif

+ 2 - 2
lib/include/Output.h

@@ -26,10 +26,10 @@ namespace mdd {
         void setOptimizability(bool state);
         state getState() override;
         void resetState() override;
-        std::string setType(std::string type) override;
+        std::string setType(const std::string& type) override;
         std::string getType() override;
         std::string getID() override;
-        std::string setPrefix(std::string prefix) override;
+        std::string setPrefix(const std::string& prefix) override;
         std::string setAppendix(int appendix) override;
         int addConnection(std::shared_ptr<IInput> input) override;
         int removeConnection(std::shared_ptr<IInput> input) override;

+ 4 - 4
lib/include/ProcessorBase.h

@@ -41,9 +41,9 @@ namespace mdd {
 
     public:
         std::string getID() override ;
-        std::string setType(std:: string type) override;
+        std::string setType(const std::string& type) override;
         std::string getType() override;
-        std::string setPrefix(std::string prefix) override;
+        std::string setPrefix(const std::string& prefix) override;
         std::string setAppendix(int appendix) override;
         void updateID() override ;
 
@@ -71,8 +71,8 @@ namespace mdd {
         std::vector <std::shared_ptr<IInput>> getOptimizableInputs() override;
         std::vector <std::shared_ptr<IOutput>> getOptimizableOutputs() override;
 
-        std::shared_ptr<IOutput> getOutput(std::string output_id) override;
-        std::shared_ptr<IInput> getInput(std::string input_id) override;
+        std::shared_ptr<IOutput> getOutput(const std::string& output_id) override;
+        std::shared_ptr<IInput> getInput(const std::string& input_id) override;
         std::shared_ptr<IModule> getModule(std::string module_id) override;
     };
 }

+ 61 - 0
lib/include/Property.h

@@ -0,0 +1,61 @@
+
+
+#pragma once
+
+#include <map>
+#include "IProperty.h"
+
+namespace mdd
+{
+
+	template<typename TYPE>
+	class Property : public IProperty
+	{
+		PropertyValue<TYPE> val;
+		std::map<std::string, std::shared_ptr<IProperty>> _subprops;
+	protected:
+		virtual IPropertyValue* GetPropertyValue()
+		{
+			return &val;
+		}
+
+	public:
+		typedef std::shared_ptr<Property<TYPE>> Ptr;
+
+		virtual std::shared_ptr<IProperty> GetSubProp(const std::string& name)
+		{
+			auto sub = _subprops.find(name);
+			if (sub == _subprops.end())
+			{
+				return std::make_shared<Property<bool>>();
+			}
+			else
+			{
+				return sub->second;
+			}
+		}
+
+		template<typename T>
+		std::shared_ptr<Property<T>> addSubProperty(const std::string& name)
+		{
+			auto newprop = std::make_shared<Property<T>>();
+			_subprops[name] = newprop;
+			return newprop;
+		}
+
+		template<typename T>
+		std::shared_ptr<Property<T>> addSubProperty(const std::string& name, const T& default)
+		{
+			auto newprop = std::make_shared<Property<T>>();
+			newprop->Value() = default;
+			_subprops[name] = newprop;
+			return newprop;
+		}
+
+		TYPE& Value()
+		{
+			return *val.value;
+		}
+	};
+
+}

+ 24 - 0
lib/src/Generator.cpp

@@ -0,0 +1,24 @@
+
+
+#include <Generator.h>
+#include <mutex>
+namespace mdd
+{
+
+	std::map<std::string, std::shared_ptr<IGenerator>>&
+		GetGenerators(
+			const std::string& name,
+			const std::shared_ptr<IGenerator>& generator)
+	{
+		static std::map<std::string, std::shared_ptr<IGenerator>> gens;
+		static std::mutex mutex;
+
+		if (generator != nullptr)
+		{
+			mutex.lock();
+			gens[name] = generator;
+			mutex.unlock();
+		}
+		return gens;
+	}
+}

+ 2 - 2
lib/src/Input.cpp

@@ -20,7 +20,7 @@ namespace mdd{
 
     }
 
-    std::string Input::setType(std::string type){
+    std::string Input::setType(const std::string& type){
         _type = type;
         return getID();
     }
@@ -31,7 +31,7 @@ namespace mdd{
         return _prefix + "/" + _type + std::to_string(_appendix);
     }
 
-    std::string Input::setPrefix(std::string prefix){
+    std::string Input::setPrefix(const std::string& prefix){
         _prefix = prefix;
         return getID();
     }

+ 14 - 4
lib/src/ModuleBase.cpp

@@ -3,7 +3,7 @@
 
 namespace mdd {
 
-    std::string ModuleBase::setType(std:: string type){
+    std::string ModuleBase::setType(const std::string& type){
         _type=type;
         updateID();
         return getID();
@@ -111,7 +111,7 @@ namespace mdd {
         return ret;
     }
 
-    std::shared_ptr<IOutput> ModuleBase::getOutput(std::string output_id) {
+    std::shared_ptr<IOutput> ModuleBase::getOutput(const std::string& output_id) {
         for(auto& output : _outputs){
                 if (output->getID() == output_id) {
                     return output;
@@ -120,7 +120,7 @@ namespace mdd {
         return nullptr;
     }
 
-    std::shared_ptr<IInput> ModuleBase::getInput(std::string input_id){
+    std::shared_ptr<IInput> ModuleBase::getInput(const std::string& input_id){
         for(auto& input : _inputs){
             if (input->getID() == input_id) {
                 return input;
@@ -174,7 +174,17 @@ namespace mdd {
         return _prefix + "/" + _type + std::to_string(_appendix);
     }
 
-    std::string ModuleBase::setPrefix(std::string prefix){
+    IPropertyValue* ModuleBase::GetPropertyValue()
+    {
+        return Property<bool>::GetPropertyValue();
+    }
+
+    std::shared_ptr<IProperty> ModuleBase::GetSubProp(const std::string& name)
+    {
+        return Property<bool>::GetSubProp(name);
+    }
+
+    std::string ModuleBase::setPrefix(const std::string& prefix){
         _prefix = prefix;
         updateID();
         return getID();

+ 35 - 8
lib/src/ModuleHTTP.cpp

@@ -1,17 +1,41 @@
-#include "ModuleHTTP.h"
 #include <httplib.h>
 #include <iostream>
 #include <thread>
+#include <Generator.h>
 #include <boost/process.hpp>
 #include <filesystem>
 
 //#include <wait.h>
 
+#include "ModuleBase.h"
+#include <httplib.h>
+#include <memory>
 #include <chrono>
 
 using namespace httplib;
 namespace mdd{
 
+    using namespace boost::process;
+    class ModuleHTTP : public ModuleBase {
+    private:
+        std::string _fname;
+        std::string _id;
+        int _port;
+        std::unique_ptr<child> _child;
+
+    protected:
+        bool connect();
+        std::string str_to_json(const std::string& input);
+        state updateInputs();
+        state updateOutputs();
+        void updateLayout();
+
+    public:
+        ModuleHTTP();// std::string fname, std::string id, int port);
+        ~ModuleHTTP();
+        state update() override;
+    };
+
     bool ModuleHTTP::connect(){
         Client cli(_id, _port);
         std::string body;
@@ -127,12 +151,12 @@ namespace mdd{
         updateOutputs();
     }
 
-    ModuleHTTP::ModuleHTTP(std::string fname, std::string id, int port):
-        _fname(fname),
-        _id(id),
-        _port(port)
+    ModuleHTTP::ModuleHTTP()// std::string fname, std::string id, int port):
+      //  _fname(fname),
+       // _id(id),
+       // _port(port)
     {
-        setType("HTTP");
+       /* setType("HTTP");
 
         if(!fname.empty()){
             if (std::filesystem::exists(fname))
@@ -146,7 +170,7 @@ namespace mdd{
         while(!connect()){
             std::this_thread::sleep_for(std::chrono::microseconds(500));
         }
-        updateLayout();
+        updateLayout();*/
     }
 
     ModuleHTTP::~ModuleHTTP()
@@ -182,4 +206,7 @@ namespace mdd{
         }
         return updateOutputs();
     }
-}
+
+}
+
+ADD_GENERATOR(mdd::ModuleHTTP);

+ 62 - 4
lib/src/ModuleMath.cpp

@@ -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

+ 2 - 2
lib/src/Output.cpp

@@ -55,7 +55,7 @@ namespace mdd {
 
     void Output::resetState() { _state = state::UNCHANGED; }
 
-    std::string Output::setType(std::string type){
+    std::string Output::setType(const std::string& type){
         _type = type;
         return getID();
     }
@@ -64,7 +64,7 @@ namespace mdd {
         return _prefix + "/" + _type + std::to_string(_appendix);
     }
 
-    std::string Output::setPrefix(std::string prefix){
+    std::string Output::setPrefix(const std::string& prefix){
         _prefix = prefix;
         return getID();
     }

+ 4 - 4
lib/src/ProcessorBase.cpp

@@ -47,7 +47,7 @@ namespace mdd{
         return _prefix + "/" + _type + std::to_string(_appendix);
     }
 
-    std::string ProcessorBase::setType(std:: string type){
+    std::string ProcessorBase::setType(const std::string& type){
         _type=type;
         updateID();
         return getID();
@@ -56,7 +56,7 @@ namespace mdd{
         return _type;
     }
 
-    std::string ProcessorBase::setPrefix(std::string prefix){
+    std::string ProcessorBase::setPrefix(const std::string& prefix){
         _prefix = prefix;
         updateID();
         return getID();
@@ -274,7 +274,7 @@ namespace mdd{
         return ret;
     }
 
-    std::shared_ptr<IOutput> ProcessorBase::getOutput(std::string output_id){
+    std::shared_ptr<IOutput> ProcessorBase::getOutput(const std::string& output_id){
         for (auto& output : _processor_outputs) {
             if(output->getID() == output_id){
                 return output;
@@ -288,7 +288,7 @@ namespace mdd{
         return nullptr;
     }
 
-    std::shared_ptr<IInput> ProcessorBase::getInput(std::string input_id){
+    std::shared_ptr<IInput> ProcessorBase::getInput(const std::string& input_id){
         for (auto& input : _processor_inputs) {
             if(input->getID() == input_id){
                 return input;

+ 6 - 4
lib/test/CMakeLists.txt

@@ -1,4 +1,4 @@
-add_executable(auslegung_test
+add_executable(mdd_lib_test
 	test_Ansys.cpp
 	test_Connector
         test_ModuleHTTP.cpp
@@ -8,8 +8,10 @@ add_executable(auslegung_test
 	test_OptimizerEvolutionary.cpp
         test_ProcessorStandard.cpp
         )
-target_link_libraries(auslegung_test gtest gtest_main ${PROJECT_NAME})
+target_link_libraries(mdd_lib_test gtest gtest_main ${PROJECT_NAME})
+
 if(WIN32)
-	target_compile_options(auslegung_test PRIVATE /bigobj)
+	target_compile_options(mdd_lib_test PRIVATE /bigobj)
 endif(WIN32)
-add_test(auslegung_test auslegung_test)
+
+add_test(mdd_lib_test mdd_lib_test)

+ 2 - 3
lib/test/test_Ansys.cpp

@@ -4,13 +4,11 @@
 //#define private public
 #include "OptimizerEvolutionary.h"
 #include <ProcessorStandard.h>
-#include <ModuleHTTP.h>
 #include <ModuleSQL.h>
-#include <ModuleMath.h>
 #include <ModuleSwitch.h>
 #include <math.h>
 #include <thread>
-
+/*
 using namespace mdd;
 TEST(ModuleHTTP, test_ansys_sql_server) {
     std::shared_ptr<ModuleSQL> sql = std::make_shared<ModuleSQL>("../../../lib/test/db/materials.db");
@@ -139,3 +137,4 @@ TEST(ModuleHTTP, test_ansys_server) {
     std::cout << optimizer.evaluateFitness(optimizer.getBest()) << std::endl;
     EXPECT_TRUE(optimizer.getBest().fitness <= 100.0);
 }
+//*/

+ 6 - 4
lib/test/test_Connector.cpp

@@ -3,16 +3,18 @@
 #include "Connector.h"
 
 using namespace mdd;
-
+/*
 TEST(Connector, encode) {
     //decode (3+4)*2
     std::vector<std::string> inputs;
-    std::shared_ptr<ModuleMath> f1 = std::make_shared<ModuleMath>(MathOperation::MULTIPLY);
+    std::shared_ptr<IModule> f1 = GetGenerators()["mdd::ModuleMath"]->Generate();
     inputs = f1->getInputIDs();
     f1->getInput(inputs[0])->setValue() = { 3 };
     f1->getInput(inputs[1])->setValue() = { 4 };
 
-    std::shared_ptr<ModuleMath> f2 = std::make_shared<ModuleMath>(MathOperation::ADD);
+    std::shared_ptr<IModule> f2 = GetGenerators()["mdd::ModuleMath"]->Generate();
+    f2->GetSubProp("operation")->Set("multiply");
+    //= std::make_shared<ModuleMath>(MathOperation::ADD);
     inputs = f2->getInputIDs();
     f2->getInput(inputs[0])->connect(f1->getOutput(f1->getOutputIDs()[0]));
     f2->getInput(inputs[1])->setValue() = { 2 };
@@ -64,4 +66,4 @@ TEST(Connector, decode) {
     auto module = Connector::decode(p);
     //auto ids_out = module->getOutputIDs();
     //EXPECT_EQ((int)module->getOutput(ids_out[0])->getValue()[0], 14);
-}
+}*/

+ 3 - 4
lib/test/test_ModuleHTTP.cpp

@@ -3,15 +3,14 @@
 #include <httplib.h>
 //#define private public
 #include <ProcessorStandard.h>
-#include <ModuleHTTP.h>
-#include <ModuleMath.h>
 #include <ModuleSwitch.h>
+#include <Generator.h>
 #include <math.h>
 #include <thread>
 
 using namespace mdd;
 using namespace httplib;
-
+/*
 void serverThread()
 {
     Server svr;
@@ -87,7 +86,7 @@ void serverThread()
 
 TEST(ModuleHTTP, updateLayout_intern){
     std::thread server (serverThread);
-    ModuleHTTP module("", "localhost", 8888);
+    auto module = GetGenerators()["mdd::ModuleHTTP"]->Generate();// ("", "localhost", 8888);
 
     Client cli("localhost",8888);
     cli.Get("/stop");

+ 19 - 12
lib/test/test_ModuleMath.cpp

@@ -1,7 +1,7 @@
 #include <gtest/gtest.h>
 #include <json.hpp>
+#include <Generator.h>
 //#define private public
-#include <ModuleMath.h>
 
 //cd cmake-build-debug/lib/test
 //gtb auslegung_test
@@ -11,21 +11,28 @@
 
 using namespace mdd;
 TEST(ModuleMath, INT_PLUS_INT){
-    ModuleMath test = ModuleMath();
-    test.update();
-
-    EXPECT_FLOAT_EQ(test.getOutput(test.getOutputIDs()[0])->getValue()[0], 2.0);
+    
+    auto generators = GetGenerators();
+    IModule::Ptr mod = generators["mdd::ModuleMath"]->Generate();
+    //mod->configure();
+    mod->update();
+    auto ids = mod->getOutputIDs();
+    auto id = ids[0];
+    auto output = mod->getOutput(id);
+    auto res = output->getValue();
+    EXPECT_FLOAT_EQ(res[0], 2.0);
 }
 
+/*
 TEST(ModuleMath, FLOAT_PLUS_FLOAT){
-    ModuleMath test = ModuleMath();
-    test.getInput(test.getInputIDs()[0])->setValue() = { 1.25 };
-    test.getInput(test.getInputIDs()[1])->setValue() = { 3.125 };
-    test.update();
+    IModule::Ptr test = GetGenerators()["class mdd::ModuleMath"]->Generate();
+    test->configure();
+    test->getInput(test->getInputIDs()[0])->setValue() = { 1.25 };
+    test->getInput(test->getInputIDs()[1])->setValue() = { 3.125 };
+    test->update();
 
-    EXPECT_FLOAT_EQ(test.getOutput(test.getOutputIDs()[0])->getValue()[0], 4.375);
+    EXPECT_FLOAT_EQ(test->getOutput(test->getOutputIDs()[0])->getValue()[0], 4.375);
 }
-
 TEST(ModuleMath, FLOAT_PLUS_FLOAT_HARDER){
     ModuleMath test = ModuleMath();
     test.getInput(test.getInputIDs()[0])->setValue() = { 2.2 };
@@ -92,4 +99,4 @@ TEST(ModuleMath, ARRAY_DURCH_ARRAY){
     test.update();
 
     EXPECT_EQ(test.getOutput(test.getOutputIDs()[0])->getValue(), expect);
-}
+}*/

+ 1 - 1
lib/test/test_ModuleSQL.cpp

@@ -9,7 +9,7 @@
 
 
 using namespace mdd;
-
+/*
 static int callback(void* data, int argc, char** argv, char** azColName) {
     int i;
     fprintf(stderr, "%s: ", (const char*)data);

+ 2 - 2
lib/test/test_ModuleSwitch.cpp

@@ -2,11 +2,11 @@
 #include <json.hpp>
 //#define private public
 #include <ProcessorStandard.h>
-#include <ModuleMath.h>
 #include <ModuleSwitch.h>
 
 
 using namespace mdd;
+/*
 TEST(ModuleSwitch, EasySwitch){
     ModuleSwitch sModule = ModuleSwitch();
     auto inputs = sModule.getInputIDs();
@@ -66,4 +66,4 @@ TEST(ModuleSwitch, ConnectTest){
 
     //std::cout << sModule.getOutput(sModule.getOutputIDs()[0])->getValue()["value"].dump() << std::endl;
     EXPECT_EQ(sModule.getOutput(sModule.getOutputIDs()[0])->getValue()[0], 6);
-}
+}*/

+ 2 - 3
lib/test/test_OptimizerEvolutionary.cpp

@@ -2,10 +2,9 @@
 #include <json.hpp>
 //#define private public
 #include "OptimizerEvolutionary.h"
-#include <ModuleMath.h>
 #include <ModuleSwitch.h>
 
-
+/*
 using namespace mdd;
 TEST(OptimizerEvolutionary, OptimizeSimpleFormula) {
     //optimize f(x)=a*b
@@ -78,4 +77,4 @@ TEST(OptimizerEvolutionary, exprtk) {
     EXPECT_EQ(_func_expr.value(), 1);
     parser.compile("in0[1]!=in0[1]", _func_expr);
     EXPECT_EQ(_func_expr.value(), 0);
-}
+}*/

+ 1 - 2
lib/test/test_ProcessorStandard.cpp

@@ -2,9 +2,8 @@
 #include <json.hpp>
 //#define private public
 #include "ProcessorStandard.h"
-#include <ModuleMath.h>
 #include <ModuleSwitch.h>
-
+/*
 
 using namespace mdd;
 TEST(ProcessorStandard, CalculateSimpleFormula){