-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperand.h
More file actions
executable file
·132 lines (115 loc) · 2.44 KB
/
Operand.h
File metadata and controls
executable file
·132 lines (115 loc) · 2.44 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#ifndef OPERAND_H_
#define OPERAND_H_
#include "Attribute.h"
#include "Tuple.h"
#include "globals.h"
enum Type { VARIABLE, CONSTANT };
template<typename T>
class IOperand
{
public:
virtual T value() = 0;
virtual int compareTo(IOperand<T> & other) = 0;
virtual Type type() = 0;
};
template<typename T>
class Operand : public IOperand<T>
{
protected:
Type m_type;
field_type_t m_fieldType;
public:
Operand(Type type, field_type_t fldType);
virtual T value() = 0;
virtual int compareTo(IOperand<T> & other);
virtual Type type() { return m_type; }
};
template<typename T>
class ConstantOperand : public Operand<T>
{
private:
T m_value;
public:
ConstantOperand(T value, field_type_t type);
virtual T value();
};
class IVariableOperand
{
public:
//virtual const std::string & name() const;
virtual void data(const Tuple * t) = 0;
};
template<typename T>
class VariableOperand : public IVariableOperand, public Operand<T>
{
private:
std::string m_name;
size_t m_size;
byte * m_buffer; // value buffer
const Tuple * m_tuple; // data buffer
public:
VariableOperand(const std::string & name, field_type_t type, size_t size);
~VariableOperand();
virtual T value();
virtual void data(const Tuple * t);
};
template<typename T>
Operand<T>::Operand(Type opType, field_type_t fieldType)
: m_type(opType), m_fieldType(fieldType)
{
}
template<typename T>
int Operand<T>::compareTo(IOperand<T> & other)
{
switch (m_fieldType)
{
case INTEGER:
case BIT:
case CHAR:
return value() - other.value();
case STRING:
{
char * v1 = (char *)value();
char * v2 = (char *)other.value();
return strcmp((char *)value(), (char *)other.value());
}
case REAL:
return 0;
}
}
template<typename T>
ConstantOperand<T>::ConstantOperand(T value, field_type_t type)
: Operand<T>(CONSTANT, type), m_value(value)
{
}
template<typename T>
T ConstantOperand<T>::value()
{
return m_value;
}
template<typename T>
VariableOperand<T>::VariableOperand(const std::string & name, field_type_t type,
size_t size) :
Operand<T>(VARIABLE, type), m_size(size), m_name(name), m_tuple(NULL)
{
m_buffer = new byte[size];
memset(m_buffer, 0, size);
}
template<typename T>
VariableOperand<T>::~VariableOperand()
{
delete [] m_buffer;
}
/*
template<typename T>
T VariableOperand<T>::value()
{
return 0;
}
*/
template<typename T>
void VariableOperand<T>::data(const Tuple * t)
{
m_tuple = t;
}
#endif