summaryrefslogtreecommitdiff
path: root/NT/src/rotor.h
blob: 6e82e80e80b0664a8351b032a6dfaa40ca5691e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <string>
#include <sstream>
#include <map>
#include <unordered_map>

#include "utils.h"

namespace Rotor {

	class Node;
	class Frame_parameters;

	class Variable { //base type for variable pointers
		public:
			virtual void init(std::string s){};
			virtual ~Variable(){};
			Node* connection;
			bool connectable;
	};
	template <class T> class Variable_type : public Variable {
		public:
			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
	//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?
	
	class Node { //base type for node pointers
		public:
			virtual ~Node(){
				for (auto v:vars){
					delete v.second;
				}
			}
		protected:
			std::unordered_map<std::string,Variable*> vars;
	};
	template <class NT> class Node_type : public Node {
		public:
			NT* get_output(Frame_parameters frame);
			void init(std::map<std::string,std::string> settings){
				for (auto s:settings) {
					if (vars.find(s.first)){
						vars[s.first]->init(s.second);
					}
				}
			}
			template <class IT> IT* create_inlet(std::string name){
				vars[name]=new Variable_type<IT>();
				return &((dynamic_cast<Variable_type<IT>*>(vars[name]))->value);
			}
	};

	class a_node: public Node_type<double> {
		public:
			a_node(){
				delay=create_inlet<int>("delay");
				//initialise the pointer to point at the instance variable
				//how to delete the vars ???
			};
		private:
			int *delay;
	};

}