ProcessorBase.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #ifndef MDD_PROCESSORBASE_H
  2. #define MDD_PROCESSORBASE_H
  3. #include <list>
  4. #include "Input.h"
  5. #include "Output.h"
  6. #include "IProcessor.h"
  7. namespace mdd {
  8. class ProcessorBase : public IProcessor{
  9. private:
  10. template<class T>
  11. class HandlerModule {
  12. public:
  13. std::shared_ptr<IModule> moduleHandler;
  14. std::shared_ptr<T> accessHandler;
  15. HandlerModule(std::shared_ptr<IModule> module, std::shared_ptr<T> access) {
  16. moduleHandler = module;
  17. accessHandler = access;
  18. }
  19. };
  20. std::string _prefix;
  21. std::string _type;
  22. int _appendix;
  23. std::vector<std::shared_ptr<Input>> _processor_inputs;
  24. std::vector<std::shared_ptr<Output>> _processor_outputs;
  25. std::vector<HandlerModule<IInput>> _module_inputs;
  26. std::vector<HandlerModule<IOutput>> _module_outputs;
  27. std::vector<std::shared_ptr<IModule>> _modules;
  28. protected:
  29. int addProcesorInput(const std::string& type, const json& value,
  30. const std::function<bool(const json&)>& verification = [](
  31. const json&) { return true; });
  32. int addProcessorOutput(const std::string& type, const json& initial);
  33. std::shared_ptr<IOutput> getProcessorOutput(int handle);
  34. std::shared_ptr<IInput> getProcessorInput(int handle);
  35. std::shared_ptr<IModule> getModule(int handle);
  36. public:
  37. std::string getID() override ;
  38. std::string setType(std:: string type) override;
  39. std::string getType() override;
  40. std::string setPrefix(std::string prefix) override;
  41. std::string setAppendix(int appendix) override;
  42. void updateID() override ;
  43. std::string addModule(std::shared_ptr<IModule> module) override ;
  44. void removeModule(std::shared_ptr<IModule> module) override;
  45. std::string addModuleInput(std::string module_ID, std::string input_ID);
  46. std::string addModuleInput(std::shared_ptr<IModule> module, std::shared_ptr<IInput> input);
  47. std::string addModuleOutput(std::string module_ID, std::string output_ID);
  48. std::string addModuleOutput(std::shared_ptr<IModule> module, std::shared_ptr<IOutput> output);
  49. std::vector<std::string> getInputs() override;
  50. std::vector<std::string> getOutputs() override;
  51. std::vector<std::string> getModules() override;
  52. std::vector<std::string> getInputIDs() override;
  53. std::vector<std::string> getOutputIDs() override;
  54. std::vector<std::string> getModuleIDs() override;
  55. std::vector<state> getInputStates() override;
  56. std::vector<state> getOutputStates() override;
  57. std::vector<std::shared_ptr<IOutput>> getConnections() override;
  58. std::shared_ptr<IOutput> getOutput(std::string output_id) override;
  59. std::shared_ptr<IInput> getInput(std::string input_id) override;
  60. std::shared_ptr<IModule> getModule(std::string module_id) override;
  61. };
  62. }
  63. #endif