From a940710de90c5bc2b9a3e74f19d60c769ab76643 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Mon, 6 Jan 2014 17:39:21 +0000 Subject: thinking out multi inlets --- NT/src/rotor.h | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 6 deletions(-) (limited to 'NT/src/rotor.h') diff --git a/NT/src/rotor.h b/NT/src/rotor.h index 49e978f..c83fe63 100644 --- a/NT/src/rotor.h +++ b/NT/src/rotor.h @@ -56,11 +56,37 @@ namespace Rotor { template class Variable_type : public Variable { public: Variable_type(bool _c){connectable=_c;}; - void init(std::string s); - bool connect(Node* target); - const T& get(const Frame_parameters &frame); + void init(std::string s){ + std::istringstream cur(s); + cur >> value; + } + bool connect(Node* target){ + if (connectable){ + if (dynamic_cast*>(target)){ + connection=target; + return true; + } + } + return false; + } + const T& get(const Frame_parameters &frame){ + if (connection){ + return (dynamic_cast*>(connection))->get_output(frame); + } + return value; + } T value; }; + //don't forget the dupliicate inlets + //it needs to be a property of a var + //vars need to be: + //std::unordered_map>> + //?? + //or could it be that a var has properties + //var needs to be a class? + //or multi var could be a subclass of var? + //with an extra accessor const T& get(int which,const Frame_parameters &frame) + //in Node we could have create_multi_inlet() and add_multi_inlet() class Node { //base type for node pointers public: virtual ~Node(){ @@ -68,16 +94,34 @@ namespace Rotor { delete v.second; } } - bool connect(std::string v,Node *t); + bool connect(std::string v,Node *t){ + auto var=vars.find(v); + if (var!=vars.end()){ + if ((*var).second->connect(t)){ + return true; + } + } + return false; + } virtual Node* clone(std::map &_settings)=0; std::string type; + std::string type; + std::string type; + std::string type; protected: std::unordered_map vars; }; template class Node_type : public Node { public: virtual const NT& get_output(const Frame_parameters &frame)=0; - void init(std::map settings); + void init(std::map settings){ + for (auto s:settings) { + 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()); + } + } + } template Variable_type* create_inlet(std::string name){ vars[name]=new Variable_type(true); return (dynamic_cast*>(vars[name])); @@ -87,6 +131,7 @@ namespace Rotor { return (dynamic_cast*>(vars[name])); } }; + } -#endif //ROTOR_H \ No newline at end of file +#endif //ROTOR_H -- cgit v1.2.3