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
|
#include <stdio.h>
#include "rotor.h"
#include "nodes.h"
#include "factory.h"
using namespace std;
namespace Rotor{
template <class T>
void Rotor::Variable_type<T>::init(std::string s){
std::istringstream cur(s);
cur >> value;
}
template <class T>
bool Rotor::Variable_type<T>::connect(Node* target){
if (connectable){
if (dynamic_cast<Node_type<T>*>(target)){
connection=target;
return true;
}
}
return false;
}
template <class T>
const T& Rotor::Variable_type<T>::get(const Frame_parameters &frame){
if (connection){
return (dynamic_cast<Node_type<T>*>(connection))->get_output(frame);
}
return value;
}
bool Node::connect(string v,Node *t){
auto var=vars.find(v);
if (var!=vars.end()){
if ((*var).second->connect(t)){
return true;
}
}
return false;
}
template <class NT>
void Node_type<NT>::init(map<string,string> settings){
for (auto s:settings) {
if (vars.find(s.first)!=vars.end()){
vars[s.first]->init(s.second);
//printf("set %s to %s\n",s.first.c_str(),s.second.c_str());
}
};
}
}
using namespace Rotor;
int main(){
Node_factory f;
map<string,string> settings={{"type","time"}};
Node *t=f.create(settings);
settings={{"value","2"},{"type","multiply"}};
Node *m=f.create(settings);
if (!m->connect("inlet",t)) printf("not connected...\n");
settings={{"type","print"}};
Node *p=f.create(settings);
if (!p->connect("inlet",m)) printf("not connected...\n");
for (double t=0;t<10.0;t+=0.765){
Frame_parameters f=Frame_parameters(t,25.0,10.0,640,360);
printf("%04f %s\n",t,(dynamic_cast<Node_type<string>*>(p))->get_output(f).c_str());
}
delete t;
delete m;
delete p;
}
|