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/nodes.h | 1 - NT/src/rotor.cpp | 47 ++-------------------------------------------- NT/src/rotor.h | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 53 insertions(+), 52 deletions(-) (limited to 'NT') diff --git a/NT/src/nodes.h b/NT/src/nodes.h index 8ce7cdd..a32408e 100644 --- a/NT/src/nodes.h +++ b/NT/src/nodes.h @@ -3,7 +3,6 @@ #include "rotor.h" - using namespace std; namespace Rotor{ diff --git a/NT/src/rotor.cpp b/NT/src/rotor.cpp index 597ded6..677fae0 100644 --- a/NT/src/rotor.cpp +++ b/NT/src/rotor.cpp @@ -5,53 +5,10 @@ #include "factory.h" using namespace std; - -namespace Rotor{ - template - void Rotor::Variable_type::init(std::string s){ - std::istringstream cur(s); - cur >> value; - } - - template - bool Rotor::Variable_type::connect(Node* target){ - if (connectable){ - if (dynamic_cast*>(target)){ - connection=target; - return true; - } - } - return false; - } - template - const T& Rotor::Variable_type::get(const Frame_parameters &frame){ - if (connection){ - return (dynamic_cast*>(connection))->get_output(frame); - } - return value; - } - bool Node::connect(string v,Node *t){ - auto var=vars.find(v); - if (var!=vars.end()){ - if ((*var).second->connect(t)){ - return true; - } - } - return false; - } - template - void Node_type::init(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()); - } - }; - } -} - using namespace Rotor; +//factory generates linker errors if rotor.h implementation is seperated: why? + int main(){ Node_factory f; map settings={{"type","time"}}; 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