diff options
| author | Tim Redfern <tim@eclectronics.org> | 2013-12-30 08:55:15 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2013-12-30 08:55:15 +0000 |
| commit | d9abdcbce9f0c3c7dbfebc00827e05536cb196e4 (patch) | |
| tree | 342cb8fe4e6c176fb07aee11ede41bb5263deee7 /NT/src/rotor.cpp | |
| parent | f7813a5324be39d13ab536c245d15dfc602a7849 (diff) | |
adding node factory
Diffstat (limited to 'NT/src/rotor.cpp')
| -rw-r--r-- | NT/src/rotor.cpp | 69 |
1 files changed, 52 insertions, 17 deletions
diff --git a/NT/src/rotor.cpp b/NT/src/rotor.cpp index ca15423..c10520a 100644 --- a/NT/src/rotor.cpp +++ b/NT/src/rotor.cpp @@ -1,6 +1,7 @@ #include <stdio.h> #include "rotor.h" +#include "nodes.h" using namespace std; using namespace Rotor; @@ -8,28 +9,62 @@ using namespace Rotor; template <class T> void Rotor::Variable_type<T>::init(std::string s){ std::istringstream cur(s); -cur >> value; - //std::cout<<s<<" "<<value<<std::endl; - } + cur >> value; +} template <class T> bool Rotor::Variable_type<T>::connect(Node* target){ - if (connectable){ - if (dynamic_cast<Node_type<T>*>(target)){ - connection=target; - return true; - } - } - return false; - } + if (connectable){ + if (dynamic_cast<Node_type<T>*>(target)){ + connection=target; + return true; + } + } + return false; +} template <class T> const T& Rotor::Variable_type<T>::get(const Frame_parameters &frame){ - if (connection){ - return (dynamic_cast<Node_type<T>*>(connection))->get_output(frame); - } - return value; + if (connection){ + return (dynamic_cast<Node_type<T>*>(connection))->get_output(frame); + } + return value; +} + +template <class NT> +void Node_type<NT>::init(map<string,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 NT> +bool Node_type<NT>::connect(string v,Node *t){ + auto var=vars.find(v); + if (var!=vars.end()){ + if ((*var).second->connect(t)){ + return true; } + } + return false; +} + +template <class NT> +template <class IT> +Variable_type<IT>* Node_type<NT>::create_inlet(std::string name){ + vars[name]=new Variable_type<IT>(true); + return (dynamic_cast<Variable_type<IT>*>(vars[name])); +} + +template <class NT> +template <class IT> +Variable_type<IT>* Node_type<NT>::create_attribute(std::string name){ + vars[name]=new Variable_type<IT>(false); + return (dynamic_cast<Variable_type<IT>*>(vars[name])); +} int main(){ Rotor::time t; @@ -37,8 +72,8 @@ int main(){ map<string,string> settings={{"value","2"}}; m.init(settings); if (!m.connect("inlet",&t)) printf("not connected...\n"); -Rotor::print p; -if (!p.connect("inlet",&m)) printf("not connected...\n"); + Rotor::print p; + if (!p.connect("inlet",&m)) printf("not connected...\n"); for (double t=0;t<10.0;t+=0.765){ Frame_parameters f=Frame_parameters(t,25.0,10.0,640,360); printf("%04f %s\n",t,p.get_output(f).c_str()); |
