123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #include "Input.h"
- namespace mdd{
- Input::Input(const std::string& type, int appendix, const json& default_value,
- const std::function<bool(const json&)>& verification) {
- _type = type;
- _value = default_value;
- _verification = std::move(verification);
- _prefix = "";
- _appendix = appendix;
- }
- std::string Input::setType(std::string type){
- _type = type;
- return getID();
- }
- std::string Input::getType(){
- return _type;
- }
- std::string Input::getID(){
- return _prefix + "/" + _type + std::to_string(_appendix);
- }
- std::string Input::setPrefix(std::string prefix){
- _prefix = prefix;
- return getID();
- }
- std::string Input::setAppendix(int appendix){
- _appendix = appendix;
- return getID();
- }
- state Input::getState() {
- if (_output == nullptr) {
- return state::UNCHANGED;
- }
- else {
- return _output->getState();
- }
- }
- void Input::resetState() {
- }
- const json& Input::getValue() {
- if(_output == nullptr){
- return _value;
- } else{
- return _output->getValue();
- }
- }
- json& Input::setDefaultValue(){
- return _value;
- }
- bool Input::verify(const json & data){
- return _verification(data);
- }
- bool Input::connect(std::shared_ptr<IOutput> output){
- if (verify(output->getValue())) {
- _output = output;
- return true;
- }
- }
- }
|