diff options
| author | Tim Redfern <tim@eclectronics.org> | 2013-12-29 12:19:38 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2013-12-29 12:19:38 +0000 |
| commit | f7813a5324be39d13ab536c245d15dfc602a7849 (patch) | |
| tree | fad99148b88823d34a5df2f0a25881a002eb291b /NT/src/rotor.h | |
| parent | b7a5a477b8ff4d4e3028b9dfb9a9df0a41463f92 (diff) | |
basic type mechanism working
Diffstat (limited to 'NT/src/rotor.h')
| -rw-r--r-- | NT/src/rotor.h | 76 |
1 files changed, 39 insertions, 37 deletions
diff --git a/NT/src/rotor.h b/NT/src/rotor.h index 1451a1b..2d8c7d7 100644 --- a/NT/src/rotor.h +++ b/NT/src/rotor.h @@ -4,7 +4,6 @@ #include <map> #include <unordered_map> -#include "utils.h" namespace Rotor { @@ -41,6 +40,7 @@ namespace Rotor { }; class Variable { //pure virtual base type for variable pointers public: + Variable(){connection=nullptr;}; virtual void init(std::string s)=0; virtual ~Variable(){}; virtual bool connect(Node* target)=0; @@ -50,33 +50,19 @@ namespace Rotor { template <class T> class Variable_type : public Variable { public: Variable_type(bool _c){connectable=_c;}; - 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; - } - T* get(Frame_parameters frame); + void init(std::string s); + bool connect(Node* target); + const T& get(const Frame_parameters &frame); T value; }; + class enum{ + public: + vector<std::string> options; + + }; - //what happens if we want to link an unlinked attribute at runtime - //should attributes and paramaters just be the same thing - //it would be really nice if there could be arithmetic - //type objects that could act on multiple types - - //either we call them attributes and inlets or just vars - //for the author, is it better to have seperate static members? - //for the GUI, yes. but is that another issue? - //does the gui need a hint for the "basic" mode inlets so they stand out? +//rotor variable types class Node { //base type for node pointers public: @@ -91,11 +77,12 @@ namespace Rotor { }; template <class NT> class Node_type : public Node { public: - virtual NT* get_output(const Frame_parameters &frame)=0; + virtual const NT& get_output(const Frame_parameters &frame)=0; 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()); } }; } @@ -108,20 +95,20 @@ namespace Rotor { } return false; } - template <class IT> IT* create_inlet(std::string name){ + 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]))->value); + return (dynamic_cast<Variable_type<IT>*>(vars[name])); } - template <class IT> IT* create_attribute(std::string name){ + template <class IT> Variable_type<IT>* create_attribute(std::string name){ vars[name]=new Variable_type<IT>(false); - return &((dynamic_cast<Variable_type<IT>*>(vars[name]))->value); + return (dynamic_cast<Variable_type<IT>*>(vars[name])); } }; class time: public Node_type<double> { public: - double* get_output(const Frame_parameters &frame){ + const double &get_output(const Frame_parameters &frame){ value=frame.time; - return &value; + return value; } private: double value; @@ -132,19 +119,34 @@ namespace Rotor { inlet=create_inlet<double>("inlet"); value=create_inlet<double>("value"); } - double* get_output(const Frame_parameters &frame){ - result=(*inlet)*(*value); - return &result; + const double &get_output(const Frame_parameters &frame){ + result=inlet->get(frame)*value->get(frame); + return result; } private: - double *inlet; - double *value; + Variable_type<double> *inlet; + Variable_type<double> *value; double result; }; +class print: public Node_type<std::string> { + public: + print(){ + inlet=create_inlet<double>("inlet"); + } + const std::string &get_output(const Frame_parameters &frame){ +std::ostringstream out; + out << inlet->get(frame); + result=out.str(); + return result; + } + private: + Variable_type<double> *inlet; + std::string result; + }; } //next:: make a couple of nodes that do something //test them //make loading and saving functions -//xml or json?
\ No newline at end of file +//xml or json? |
