summaryrefslogtreecommitdiff
path: root/src/cat/TPTSTypes.h
blob: b9fa92b61b0925ba1e3e6f0cfa9648d63dbe0869 (plain)
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
#ifndef TPTSTYPES_H_
#define TPTSTYPES_H_

#include <string>
#include <typeinfo>
#include "gui/interface/Point.h"

enum ValueType { TypeNumber, TypePoint, TypeString, TypeNull, TypeFunction };

class GeneralException
{
protected:
	std::string exception;
public:
	GeneralException(std::string message){
		exception = message;
	}
	std::string GetExceptionMessage() {
		return exception;
	}
};


class NumberType;
class StringType;
class PointType;

class AnyType
{
protected:
	ValueType type;
	void * value;
public:
	AnyType(ValueType type_, void * value_);
	AnyType(const AnyType & v);
	operator NumberType();
	operator StringType();
	operator PointType();
	ValueType GetType();
	std::string TypeName()
	{
		switch(type)
		{
		case TypeNumber:
			return "Number";
		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 TypePoint:
			return "Point";
		case TypeString:
			return "String";
		case TypeNull:
			return "Null";
		case TypeFunction:
			return "Function";
		default:
			return "Unknown";
		}
	}
	~AnyType();
};

class InvalidConversionException: public GeneralException
{
private:
	ValueType from;
	ValueType to;
public:
	InvalidConversionException(ValueType from_, ValueType to_):
	GeneralException("Invalid conversion from " + AnyType::TypeName(from_) + " to " + AnyType::TypeName(to_)), from(from_), to(to_) {
	}
};

class NumberType: public AnyType
{
public:
	NumberType(int number);
	int 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_ */