-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunction.h
62 lines (42 loc) · 1.45 KB
/
Function.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
57
58
59
60
61
62
#ifndef FUNCTION_H_
#define FUNCTION_H_
#include "Record.h"
#include "ParseTree.h"
#define MAX_DEPTH 100
enum ArithOp {PushInt, PushDouble, ToDouble, ToDouble2Down,
IntUnaryMinus, IntMinus, IntPlus, IntDivide, IntMultiply,
DblUnaryMinus, DblMinus, DblPlus, DblDivide, DblMultiply};
struct Arithmatic {
ArithOp myOp;
int recInput;
void *litInput;
};
class Function {
private:
Arithmatic *opList;
int numOps;
int returnsInt;
public:
Function ();
// this grows the specified function from a parse tree and converts
// it into an accumulator-based computation over the attributes in
// a record with the given schema; the record "literal" is produced
// by the GrowFromParseTree method
void GrowFromParseTree (struct FuncOperator *parseTree, Schema &mySchema);
// helper function
Type RecursivelyBuild (struct FuncOperator *parseTree, Schema &mySchema);
// prints out the function to the screen
void Print ();
// applies the function to the given record and returns the result
Type Apply (Record &toMe, int &intResult, double &doubleResult);
template <class T>
T Apply (Record& toMe) {
int intResult; double doubleResult;
Apply (toMe, intResult, doubleResult);
return returnsInt ? intResult : doubleResult;
}
Type resultType() const { return returnsInt ? Int : Double; }
// prints out the function to the screen
void PrintToStream (std::ostream &os, Schema *schema);
};
#endif