1234567891011121314151617181920212223242526272829303132333435363738 |
- #include "ModuleSwitch.h"
- #include <iostream>
- namespace mdd{
- ModuleSwitch::ModuleSwitch(){
- json default_val;
- default_val["value"] = 42;
- auto veri = [](const json& val){
- if(val.find("value")==val.end())
- return false;
- return true;
- };
- addInput("Switch", default_val, veri);
- addInput("Value", default_val, veri);
- addInput("Default", default_val, veri);
- addOutput("Value", default_val);
- setType("Switch");
- }
- bool ModuleSwitch::update(){
- int index = getInput(0)->getValue()["value"].get<int>();
- if(index == 0){
- index = 1;
- }
- if(index > getInputs().size() - 1){
- index = getInputs().size() - 1;
- }
- json ret = getInput(index)->getValue()["value"];
- if (ret.dump() != getOutput(0)->getValue()["value"].dump()) {
- getOutput(0)->getValueInternal()["value"] = ret ;
- return true;
- }
- else{
- return false;
- }
- }
- }
|