forked from FantasqueX/Computing_Graph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.h
More file actions
102 lines (101 loc) · 1.89 KB
/
node.h
File metadata and controls
102 lines (101 loc) · 1.89 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#pragma once
#include <iostream>
#include <string>
#include <cmath>
const float NaN=0.0/0.0;
class Node
{
public:
std::string name;
virtual float geteval();
virtual void setvalue(float a);
float tempeval;
bool calculated=0;
bool printable=0;
virtual void reset();
};
class ZeroParentsNode:public Node
{
public:
float geteval();
int getParentsNum();
};
class OneParentsNode:public Node
{
public:
Node *p1;//parents
OneParentsNode(std::string a,Node* parent1);
virtual float func(float x);
float geteval();
int getParentsNum();
};
template<float func(float f)>
class Opn:public Node
{
public:
Node *p1;//parents
Opn(std::string a,Node* parent1)
{
name=a;
p1=parent1;
}
float geteval()
{
if(calculated)return tempeval;
else
{
calculated=1;
tempeval=func(p1->geteval());
return tempeval;
}
}
int getParentsNum()
{
return 1;
}
};
template<float func(float f1,float f2)>
class Tpn:public Node
{
public:
Node *p1,*p2;//parents
Tpn(std::string a,Node* parent1,Node* parent2)
{
name=a;
p1=parent1;
p2=parent2;
}
float geteval()
{
if(calculated)return tempeval;
else
{
calculated=1;
tempeval=func(p1->geteval(),p2->geteval());
return tempeval;
}
}
int getParentsNum()
{
return 2;
}
TwoParentsNode(std::string a,Node* parent1,Node* parent2);
};
class TwoParentsNode:public Node
{
public:
Node *p1,*p2;//parents
virtual float func(float x,float y);
float geteval();
int getParentsNum();
TwoParentsNode(std::string a,Node* parent1,Node* parent2);
};
class ThreeParentsNode:public Node
{
public:
Node *p1,*p2,*p3;//parents
virtual float func(float x,float y,float z);
float geteval();
int getParentsNum();
ThreeParentsNode(std::string a,Node* parent1,Node* parent2,Node* parent3);
};