ModuleSwitch.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "ModuleSwitch.h"
  2. #include <iostream>
  3. namespace mdd{
  4. ModuleSwitch::ModuleSwitch(){
  5. json default_val;
  6. default_val["value"] = 42;
  7. auto veri = [](const json& val){
  8. if(val.find("value")==val.end())
  9. return false;
  10. return true;
  11. };
  12. addInput("Switch", default_val, veri);
  13. addInput("Value", default_val, veri);
  14. addInput("Default", default_val, veri);
  15. addOutput("Value", default_val);
  16. setType("Switch");
  17. }
  18. bool ModuleSwitch::update(){
  19. int index = getInput(0)->getValue()["value"].get<int>();
  20. if(index == 0){
  21. index = 1;
  22. }
  23. if(index > getInputs().size() - 1){
  24. index = getInputs().size() - 1;
  25. }
  26. json ret = getInput(index)->getValue()["value"];
  27. if (ret.dump() != getOutput(0)->getValue()["value"].dump()) {
  28. getOutput(0)->getValueInternal()["value"] = ret ;
  29. return true;
  30. }
  31. else{
  32. return false;
  33. }
  34. }
  35. }