-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalcTree.h
56 lines (54 loc) · 1.33 KB
/
CalcTree.h
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
#pragma once
//virtual class Node and it's attribute/operation, in C, operation implement in .c file so,
// not put in the structure,but keep the unit together for good reading
/*
* virtual interface-only virtual operation
*
*/
typedef struct _NodeVTable NodeVTable;
typedef struct _Node{
const NodeVTable * vtable;
}Node;
typedef Node* pNodeType;
extern double node_calc(Node *pThis);
extern void node_cleanup(Node *pThis);
/*
* Reality NumNode class
* "_"means private attribute
*/
typedef struct _NumNode{
Node isa;
double _num;
}NumNode;
typedef NumNode* pNumNodeType;
extern NumNode * newNumNode(double num);
//AddNode class
typedef struct _AddNode{
Node isa;
Node *_pLeft;
Node *_pRight;
}AddNode;
typedef AddNode* pAddNodeType;
extern AddNode * newAddNode(Node *pLeft, Node *pRight);
/*
* Reality MultNode class
*/
typedef struct _MultNode{
Node isa;
Node *_pLeft;
Node *_pRight;
}MultNode;
typedef MultNode* pMultNodeType;
extern MultNode * newMultNode(Node *pLeft, Node *pRight);
/*
* Virtual BinNode Class
* virtual operation and virtual attributes
*/
typedef struct _BinNode{
Node isa;
Node *_pLeft;
Node *_pRight;
}BinNode;
typedef BinNode* pBinNodeType;
//virtual class no external operation required.
//new BinNode and Node is not available since virtual