Input.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. state Input::getState() {
  30. if (_output == nullptr) {
  31. return state::UNCHANGED;
  32. }
  33. else {
  34. return _output->getState();
  35. }
  36. }
  37. void Input::resetState() {
  38. }
  39. const json& Input::getValue() {
  40. if(_output == nullptr){
  41. return _value;
  42. } else{
  43. return _output->getValue();
  44. }
  45. }
  46. json& Input::setDefaultValue(){
  47. return _value;
  48. }
  49. bool Input::verify(const json & data){
  50. return _verification(data);
  51. }
  52. bool Input::connect(std::shared_ptr<IOutput> output){
  53. if (verify(output->getValue())) {
  54. _output = output;
  55. return true;
  56. }
  57. }
  58. }