From 1e01ca3e89beca6870a3112c4513df66dd07dbb1 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Sun, 19 Jan 2014 09:33:14 +0000 Subject: json spreadiing --- NT/src/rotor.h | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'NT/src/rotor.h') diff --git a/NT/src/rotor.h b/NT/src/rotor.h index 6fed8df..0138191 100644 --- a/NT/src/rotor.h +++ b/NT/src/rotor.h @@ -33,6 +33,13 @@ struct TypeName { return "number"; } }; +template <> +struct TypeName { + static const char* Get() { + return "string"; + } +}; + namespace Rotor { @@ -71,7 +78,7 @@ namespace Rotor { class Variable { //pure virtual base type for variable pointers public: Variable(){connection=nullptr;}; - virtual void init(std::string n,std::string s)=0; + virtual void init(std::string s)=0; virtual void init(Json::Value s)=0; virtual ~Variable(){}; virtual bool connect(Node* target)=0; @@ -82,11 +89,10 @@ namespace Rotor { }; template class Variable_type : public Variable { public: - Variable_type(bool _c){connectable=_c;}; - void init(std::string n,std::string s){ + Variable_type(std::string n,bool _c){name=n;connectable=_c;}; + void init(std::string s){ std::istringstream cur(s); cur >> value; - name=n; } void init(Json::Value s){ std::istringstream cur(s["value"].asString()); @@ -121,11 +127,10 @@ namespace Rotor { }; template class Variable_array_type: public Variable_array { public: - Variable_array_type(){connectable=true;}; - void init(std::string n,std::string s){ + Variable_array_type(std::string n){name=n;connectable=true;}; + void init(std::string s){ std::istringstream cur(s); cur >> value; - name=n; } void init(Json::Value s){ std::istringstream cur(s["value"].asString()); @@ -231,15 +236,15 @@ namespace Rotor { } std::string output_type(){return TypeName::Get();}; template Variable_type* create_inlet(std::string name){ - vars[name]=new Variable_type(true); + vars[name]=new Variable_type(name,true); return (dynamic_cast*>(vars[name])); } template Variable_type* create_attribute(std::string name){ - vars[name]=new Variable_type(false); + vars[name]=new Variable_type(name,false); return (dynamic_cast*>(vars[name])); } template Variable_array_type* create_array(std::string name){ - vars[name]=new Variable_array_type(); + vars[name]=new Variable_array_type(name); return (dynamic_cast*>(vars[name])); } }; -- cgit v1.2.3