diff options
| author | Tim Redfern <tim@eclectronics.org> | 2013-12-26 10:20:35 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2013-12-26 10:20:35 +0000 |
| commit | 0632c3bf7808608d9e1b165c30f6791662ce009c (patch) | |
| tree | ada0494cace166afc7a4fa04b9c6465fca6457b3 /NT | |
| parent | cbf26b93d097cd4304de2fa037675b3211629a62 (diff) | |
template from_string
Diffstat (limited to 'NT')
| -rw-r--r-- | NT/src/rotor.cpp | 6 | ||||
| -rw-r--r-- | NT/src/rotor.h | 28 |
2 files changed, 20 insertions, 14 deletions
diff --git a/NT/src/rotor.cpp b/NT/src/rotor.cpp index 2678dd5..f13f700 100644 --- a/NT/src/rotor.cpp +++ b/NT/src/rotor.cpp @@ -2,6 +2,12 @@ #include "rotor.h" +using namespace std; +using namespace Rotor; + int main(){ + a_node a; + map<string,string> settings={{"p1","1"}, {"p2","2"}, {"p3","3"}}; + a.init(settings); printf("hello, world\n"); }
\ No newline at end of file diff --git a/NT/src/rotor.h b/NT/src/rotor.h index 6e82e80..19e5d18 100644 --- a/NT/src/rotor.h +++ b/NT/src/rotor.h @@ -7,6 +7,11 @@ namespace Rotor { + template <class T> void from_string(T t,std::string s) { + std::istringstream cur(s); + cur >> t; + }; + class Node; class Frame_parameters; @@ -19,21 +24,12 @@ namespace Rotor { }; template <class T> class Variable_type : public Variable { public: + void init(std::string s){ + from_string(value,s); + }; T* get(Frame_parameters frame); T value; }; - //type specialisations deal with string conversion - template <> class Variable_type <double> : public Variable { - public: - void init(std::string s){ - double x = 0; - std::istringstream cur(s); - cur >> x; - (*value)= x; - }; - double* get(Frame_parameters frame); - double *value; - }; //what happens if we want to link an unlinked attribute at runtime @@ -75,12 +71,16 @@ namespace Rotor { class a_node: public Node_type<double> { public: a_node(){ - delay=create_inlet<int>("delay"); + p1=create_inlet<int>("p1"); + p2=create_inlet<float>("p2"); + p3=create_inlet<double>("p3"); //initialise the pointer to point at the instance variable //how to delete the vars ??? }; private: - int *delay; + int *p1; + float *p2; + double *p3; }; } |
