/
TPTSTypes.h
123 lines (111 loc) · 2.12 KB
/
TPTSTypes.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
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
#ifndef TPTSTYPES_H_
#define TPTSTYPES_H_
#include <string>
#include <typeinfo>
#include "gui/interface/Point.h"
enum ValueType { TypeNumber, TypeFloat, TypePoint, TypeString, TypeNull, TypeFunction };
typedef union { int num; float numf; std::string* str; ui::Point* pt; } ValueValue;
class GeneralException
{
protected:
std::string exception;
public:
GeneralException(std::string message){
exception = message;
}
std::string GetExceptionMessage() {
return exception;
}
};
class NumberType;
class FloatType;
class StringType;
class PointType;
class AnyType
{
protected:
ValueType type;
ValueValue value;
public:
AnyType(ValueType type_, ValueValue value_);
AnyType(const AnyType & v);
operator NumberType();
operator FloatType();
operator StringType();
operator PointType();
ValueType GetType();
std::string TypeName()
{
switch(type)
{
case TypeNumber:
return "Number";
case TypeFloat:
return "Float";
case TypePoint:
return "Point";
case TypeString:
return "String";
case TypeNull:
return "Null";
case TypeFunction:
return "Function";
default:
return "Unknown";
}
}
static std::string TypeName(ValueType type)
{
switch(type)
{
case TypeNumber:
return "Number";
case TypeFloat:
return "Float";
case TypePoint:
return "Point";
case TypeString:
return "String";
case TypeNull:
return "Null";
case TypeFunction:
return "Function";
default:
return "Unknown";
}
}
~AnyType();
};
class InvalidConversionException: public GeneralException
{
public:
InvalidConversionException(ValueType from_, ValueType to_):
GeneralException("Invalid conversion from " + AnyType::TypeName(from_) + " to " + AnyType::TypeName(to_)) {
}
};
class NumberType: public AnyType
{
public:
NumberType(int number);
int Value();
};
class FloatType: public AnyType
{
public:
FloatType(float number);
float Value();
};
class StringType: public AnyType
{
public:
StringType(std::string string);
std::string Value();
};
class PointType: public AnyType
{
public:
PointType(ui::Point point);
PointType(int pointX, int pointY);
ui::Point Value();
};
#endif /* TPTSTYPES_H_ */