ModuleBase.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #ifndef MDD_BASEMODULE_H
  2. #define MDD_BASEMODULE_H
  3. #include <string>
  4. #include <functional>
  5. #include "IModule.h"
  6. #include "Output.h"
  7. #include <bits/shared_ptr.h>
  8. namespace mdd {
  9. struct Input {
  10. std::string type;
  11. json value;
  12. std::function<bool(const json&)> verification;
  13. std::shared_ptr<IOutput> output;
  14. Input(const std::string& type, const json& default_value,
  15. const std::function<bool(const json&)>& verification = [](
  16. const json&) { return true; });
  17. };
  18. class ModuleBase : public IModule{
  19. private:
  20. std::vector<Input> _inputs;
  21. std::vector<std::shared_ptr<Output>> _outputs;
  22. public:
  23. int addInput(const std::string& type, const json& value,
  24. const std::function<bool(const json&)>& verification = [](
  25. const json&) { return true; });
  26. json& setInputDefaultValue(int handle);
  27. const json& getInputValue(int handle);
  28. bool connectInput(int handle, std::shared_ptr<IOutput> output) override;
  29. std::vector<std::string> getInputs() override;
  30. std::vector<std::string> getOutputs() override;
  31. std::shared_ptr<IOutput> getOutput(int handle) override;
  32. int addOutput(const std::string& type, const json& initial);
  33. json &setOutputValue(int handle);
  34. };
  35. }
  36. #endif //MDD_BASEMODULE_H