From cbf26b93d097cd4304de2fa037675b3211629a62 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Thu, 26 Dec 2013 00:51:22 +0000 Subject: making string initialisers for variables --- NT/src/rotor.h | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/NT/src/rotor.h b/NT/src/rotor.h index 6835d01..6e82e80 100644 --- a/NT/src/rotor.h +++ b/NT/src/rotor.h @@ -1,7 +1,10 @@ #include +#include #include #include +#include "utils.h" + namespace Rotor { class Node; @@ -11,15 +14,26 @@ namespace Rotor { public: virtual void init(std::string s){}; virtual ~Variable(){}; + Node* connection; + bool connectable; }; template class Variable_type : public Variable { public: - Node* connection; T* get(Frame_parameters frame); - bool connectable; 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 @@ -33,16 +47,18 @@ namespace Rotor { //does the gui need a hint for the "basic" mode inlets so they stand out? class Node { //base type for node pointers - }; - template class Node_type : public Node { public: - std::unordered_map vars; - NT* get_output(Frame_parameters frame); - virtual ~Node_type(){ + virtual ~Node(){ for (auto v:vars){ delete v.second; } } + protected: + std::unordered_map vars; + }; + template class Node_type : public Node { + public: + NT* get_output(Frame_parameters frame); void init(std::map settings){ for (auto s:settings) { if (vars.find(s.first)){ @@ -57,12 +73,14 @@ namespace Rotor { }; class a_node: public Node_type { - a_node(){ - delay=create_inlet("delay"); - //initialise the pointer to point at the instance variable - //how to delete the vars ??? - }; - int *delay; + public: + a_node(){ + delay=create_inlet("delay"); + //initialise the pointer to point at the instance variable + //how to delete the vars ??? + }; + private: + int *delay; }; } -- cgit v1.2.3