From dc2c81dd14933b21e0f4bdad8cdd662c8596a6c2 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Tue, 21 Jan 2014 12:54:34 +0000 Subject: connections working --- NT/src/rotor.h | 47 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) (limited to 'NT/src/rotor.h') diff --git a/NT/src/rotor.h b/NT/src/rotor.h index 4d73050..0a016a2 100644 --- a/NT/src/rotor.h +++ b/NT/src/rotor.h @@ -94,24 +94,37 @@ namespace Rotor { virtual Json::Value to_json()=0; virtual void init(Json::Value s)=0; virtual bool connect(Node* target)=0; - virtual std::string get_type()=0; + virtual std::string get_type()=0; + virtual void create_connection(std::unordered_map &nodes)=0; bool is_connected(){ if (connection) return true; return false; } std::string get_connection_id(); + std::string name; protected: Node* connection; bool connectable; - std::string name; + std::string input; }; template class Variable_type : public Variable { public: - Variable_type(std::string _name,bool _connectable){name=_name;connectable=_connectable;}; + Variable_type(std::string _name="",std::string _input="",bool _connectable=true){name=_name;input=_input;connectable=_connectable;}; void init(Json::Value s){ std::istringstream cur(s["value"].asString()); cur >> value; name=s["name"].asString(); + input=s["input"].asString(); + } + void create_connection(std::unordered_map &nodes){ + for (auto node:nodes){ + if (node.first==input){ + if (connect(node.second)) { + std::cerr<<"connecting '"<::Get()<<"' input to '"<::Get()<<"'' input to '"< values; }; template class Variable_array_type: public Variable_array { public: Variable_array_type(std::string n){name=n;connectable=true;}; void init(Json::Value s){ - std::istringstream cur(s["value"].asString()); - cur >> value; name=s["name"].asString(); + if (!s["input"].empty()){ + for (uint32_t i=0;i &nodes){ + for (auto v:values){ + v.create_connection(nodes); + } } Json::Value to_json(); std::string get_type(){ @@ -162,8 +184,11 @@ namespace Rotor { } return false; } + void add(std::string _name,std::string _input,bool _connectable=true){ + values.push_back(Variable_type(_name,_input,_connectable)); + } void add(std::string _name="",bool _connectable=true,int num=1){ - for (int i=0;i(_name,_connectable)); + for (int i=0;i(_name,"",_connectable)); } bool connect(uint32_t which,Node* target){ if (values.size()>which){ @@ -213,8 +238,11 @@ namespace Rotor { Json::Value to_json(); virtual Node* clone(Json::Value &_settings)=0; virtual std::string get_output_type()=0; - std::unordered_map vars; + void create_connections(std::unordered_map &nodes){ + for (auto var:vars) var.second->create_connection(nodes); + } protected: + std::unordered_map vars; std::string type; std::string id; std::string type_id; @@ -235,11 +263,11 @@ namespace Rotor { } std::string get_output_type(){return TypeName::Get();}; template Variable_type* create_inlet(std::string name){ - vars[name]=new Variable_type(name,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(name,false); + vars[name]=new Variable_type(name,"",false); return (dynamic_cast*>(vars[name])); } template Variable_array_type* create_array(std::string name){ @@ -247,7 +275,6 @@ namespace Rotor { return (dynamic_cast*>(vars[name])); } }; - } #endif //ROTOR_H -- cgit v1.2.3