diff options
| author | Tim Redfern <tim@eclectronics.org> | 2014-01-06 17:39:21 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2014-01-06 17:39:21 +0000 |
| commit | a940710de90c5bc2b9a3e74f19d60c769ab76643 (patch) | |
| tree | ce3740f465effe29ef2ee15ef13901f019273cd8 /NT/src/rotor.h | |
| parent | 815d1149f9fb6be2c1bc05fb04f574eb928e050e (diff) | |
thinking out multi inlets
Diffstat (limited to 'NT/src/rotor.h')
| -rw-r--r-- | NT/src/rotor.h | 57 |
1 files changed, 51 insertions, 6 deletions
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 T> 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<Node_type<T>*>(target)){ + connection=target; + return true; + } + } + return false; + } + const T& get(const Frame_parameters &frame){ + if (connection){ + return (dynamic_cast<Node_type<T>*>(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<std::string,std::pair<bool,std::vector<Variable*>>> + //?? + //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<std::string,std::string> &_settings)=0; std::string type; + std::string type; + std::string type; + std::string type; protected: std::unordered_map<std::string,Variable*> vars; }; template <class NT> class Node_type : public Node { public: virtual const NT& get_output(const Frame_parameters &frame)=0; - void init(std::map<std::string,std::string> settings); + void init(std::map<std::string,std::string> 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 <class IT> Variable_type<IT>* create_inlet(std::string name){ vars[name]=new Variable_type<IT>(true); return (dynamic_cast<Variable_type<IT>*>(vars[name])); @@ -87,6 +131,7 @@ namespace Rotor { return (dynamic_cast<Variable_type<IT>*>(vars[name])); } }; + } -#endif //ROTOR_H
\ No newline at end of file +#endif //ROTOR_H |
