From 0632c3bf7808608d9e1b165c30f6791662ce009c Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Thu, 26 Dec 2013 10:20:35 +0000 Subject: template from_string --- NT/src/rotor.cpp | 6 ++++++ 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 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 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 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 : 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 { public: a_node(){ - delay=create_inlet("delay"); + p1=create_inlet("p1"); + p2=create_inlet("p2"); + p3=create_inlet("p3"); //initialise the pointer to point at the instance variable //how to delete the vars ??? }; private: - int *delay; + int *p1; + float *p2; + double *p3; }; } -- cgit v1.2.3