summaryrefslogtreecommitdiff
path: root/NT/src/nodes.h
blob: 1632363f5b555580753b9c40a0c67404268d4949 (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
#ifndef ROTOR_NODES_H
#define ROTOR_NODES_H

#include "rotor.h"

using namespace std;

namespace Rotor{
	class Double_node: public Node_type<double> {
		public:
			Double_node(){};
	};
	class Time: public Double_node {
		public:
			Time(){type="time";};
			Time(Json::Value &settings):Time() {
				init(settings);
			};
			const double &get_output(const Frame_parameters &frame){
				value=frame.get_time();
				return value;
			}
			Time* clone(Json::Value &_settings) { return new Time(_settings);};
		private:
			double value;
	};
	class Multiply: public Double_node {
		public:
			Multiply(){
				factors=create_array<double>("factors");
				type="multiply";
				description="multiplies numbers";
				title="Multiply";
				type_id="11c67850-7ce4-11e3-abf6-930ef8613c46";
				ui_type="none";
			}
			Multiply(Json::Value &settings):Multiply() {
				init(settings);
			};
			const double &get_output(const Frame_parameters &frame){
				result=1.0f;
				for (auto var:factors->get_values()) result*=var.get(frame); 
				return result;
			}
			Multiply* clone(Json::Value &_settings) { return new Multiply(_settings);};
		private:
			Variable_array_type<double> *factors;
			double result;
	};
	class String_node: public Node_type<string> {
		public:
			String_node(){};
	};
	class Print: public String_node {
		public:
			Print(){
				inlet=create_inlet<double>("inlet");
				type="print";
			}
			Print(Json::Value &settings):Print() {
				init(settings);
			};
			const std::string &get_output(const Frame_parameters &frame){
				std::ostringstream out;
				out << inlet->get(frame);
				result=out.str();
				return result;
			}
			Print* clone(Json::Value &_settings) { return new Print(_settings);};
		private:
			Variable_type<double> *inlet;
			std::string result;
	};
}


#endif //ROTOR_NODES_H