Input.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "Input.h"
  2. namespace mdd{
  3. Input::Input(const std::string& type, int appendix, const json& default_value,
  4. const std::function<bool(const json&)>& verification) {
  5. _type = type;
  6. _value = default_value;
  7. _verification = std::move(verification);
  8. _prefix = "";
  9. _appendix = appendix;
  10. }
  11. std::string Input::setType(std::string type){
  12. _type = type;
  13. return getID();
  14. }
  15. std::string Input::getType(){
  16. return _type;
  17. }
  18. std::string Input::getID(){
  19. return _prefix + "/" + _type + std::to_string(_appendix);
  20. }
  21. std::string Input::setPrefix(std::string prefix){
  22. _prefix = prefix;
  23. return getID();
  24. }
  25. std::string Input::setAppendix(int appendix){
  26. _appendix = appendix;
  27. return getID();
  28. }
  29. const json& Input::getValue() {
  30. return _value;
  31. }
  32. json& Input::setDefaultValue(){
  33. return _value;
  34. }
  35. bool Input::verify(const json & data){
  36. return _verification(data);
  37. }
  38. bool Input::connect(std::shared_ptr<IOutput> output){
  39. if (verify(output->getValue())) {
  40. _output = output;
  41. return true;
  42. }
  43. }
  44. }