From 874194d055d0c90a7874a06be95ca2e087616a9d Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Tue, 14 Jan 2014 17:00:14 +0000 Subject: converting settings initiaiers to json --- NT/src/rotor.h | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'NT/src/rotor.h') diff --git a/NT/src/rotor.h b/NT/src/rotor.h index d261954..30b4ba1 100644 --- a/NT/src/rotor.h +++ b/NT/src/rotor.h @@ -30,7 +30,7 @@ struct TypeName { template <> struct TypeName { static const char* Get() { - return "double"; + return "number"; } }; @@ -71,23 +71,26 @@ namespace Rotor { class Variable { //pure virtual base type for variable pointers public: Variable(){connection=nullptr;}; - virtual void init(std::string s)=0; + virtual void init(std::string n,std::string s)=0; virtual ~Variable(){}; virtual bool connect(Node* target)=0; virtual std::string get_type()=0; Node* connection; bool connectable; + std::string name; }; template class Variable_type : public Variable { public: Variable_type(bool _c){connectable=_c;}; - void init(std::string s){ + void init(std::string n,std::string s){ std::istringstream cur(s); cur >> value; + name=n; } std::string get_type(){ //need this to output node templates return TypeName::Get(); } +//have to cast connect and get_output to use templated return types bool connect(Node* target){ if (connectable){ if (dynamic_cast*>(target)){ @@ -112,10 +115,11 @@ namespace Rotor { }; template class Variable_array_type: public Variable_array { public: - Variable_array_type(){}; - void init(std::string s){ + Variable_array_type(){connectable=true;}; + void init(std::string n,std::string s){ std::istringstream cur(s); cur >> value; + name=n; } std::string get_type(){ //need this to output node templates return TypeName::Get(); @@ -176,9 +180,9 @@ namespace Rotor { Json::Value list_json(); virtual Node* clone(std::map &_settings)=0; virtual std::string output_type()=0; - std::string node_type; - std::string node_id; + std::string type; std::string id; + std::string type_id; std::string description; std::string title; std::string ui_type; @@ -195,6 +199,14 @@ namespace Rotor { } } } + void init(Json::Value settings){ + for (auto s:settings["input"].Members) { + if (vars.find(s.first)!=vars.end()){ + vars[s.first]->init(s.second); + //printf("set %s to %s\n",s.first.c_str(),s.second.c_str()); + } + } + } std::string output_type(){return TypeName::Get();}; template Variable_type* create_inlet(std::string name){ vars[name]=new Variable_type(true); -- cgit v1.2.3