1 | /*! |
---|
2 | * @file multi_type.h |
---|
3 | * @brief Definition of ... |
---|
4 | */ |
---|
5 | |
---|
6 | #ifndef _MULTI_TYPE_H |
---|
7 | #define _MULTI_TYPE_H |
---|
8 | |
---|
9 | // FORWARD DECLARATION |
---|
10 | |
---|
11 | //! An enumerator defining Types, that can be stored inside a MultiType. |
---|
12 | typedef enum |
---|
13 | { |
---|
14 | MT_NULL = 0, //!< No Value at all. |
---|
15 | MT_BOOL = 1, //!< A bool Value. |
---|
16 | MT_INT = 2, //!< An int Value. |
---|
17 | MT_UINT = 2, |
---|
18 | MT_LONG = 2, |
---|
19 | MT_FLOAT = 4, //!< A float Value. |
---|
20 | MT_CHAR = 8, //!< A single char. |
---|
21 | MT_STRING = 16, //!< An entire String. |
---|
22 | MT_EXT1 = 32, //!< An external Type. |
---|
23 | MT_EXT2 = 64, //!< An external Type. |
---|
24 | } MT_Type; |
---|
25 | |
---|
26 | |
---|
27 | |
---|
28 | //! A class that encapsulates multiple differen types. |
---|
29 | /** |
---|
30 | * Only one Value can be Stored inside this Class, but it can have any type: @see MT_Type. |
---|
31 | */ |
---|
32 | class MultiType { |
---|
33 | |
---|
34 | public: |
---|
35 | MultiType(); |
---|
36 | MultiType(bool value); |
---|
37 | MultiType(int value); |
---|
38 | MultiType(double value); |
---|
39 | MultiType(char value); |
---|
40 | MultiType(const char* value); |
---|
41 | MultiType(const MultiType& multiType); |
---|
42 | virtual ~MultiType(); |
---|
43 | |
---|
44 | MultiType& operator= (const MultiType& mt); |
---|
45 | |
---|
46 | void setType(int type); |
---|
47 | |
---|
48 | void setBool(bool value); |
---|
49 | void setInt(int value); |
---|
50 | void setFloat(float value); |
---|
51 | void setChar(char value); |
---|
52 | void setString(const char* value); |
---|
53 | |
---|
54 | inline void setValue(bool value) { this->setBool(value); }; |
---|
55 | inline void setValue(int value) { this->setInt(value); }; |
---|
56 | inline void setValue(float value) { this->setFloat(value); }; |
---|
57 | inline void setValue(char value) { this->setChar(value); }; |
---|
58 | inline void setValue(const char* value) { this->setString(value); }; |
---|
59 | |
---|
60 | /** @returns the Type of the Value stored in this MultiType */ |
---|
61 | inline MT_Type getType() const { return this->type; }; |
---|
62 | |
---|
63 | |
---|
64 | /* RETRIEVING FUNCTIONS */ |
---|
65 | bool getBool() const; |
---|
66 | int getInt() const; |
---|
67 | float getFloat() const; |
---|
68 | char getChar() const; |
---|
69 | const char* getString(); |
---|
70 | |
---|
71 | void reset(); |
---|
72 | |
---|
73 | void debug(); |
---|
74 | |
---|
75 | static const char* MultiTypeToString(MT_Type type); |
---|
76 | static MT_Type StringToMultiType(const char* type); |
---|
77 | |
---|
78 | private: |
---|
79 | void init(); |
---|
80 | |
---|
81 | |
---|
82 | private: |
---|
83 | |
---|
84 | union MultiTypeValue |
---|
85 | { |
---|
86 | bool Bool; |
---|
87 | int Int; |
---|
88 | float Float; |
---|
89 | char Char; |
---|
90 | char* String; |
---|
91 | |
---|
92 | } value; |
---|
93 | |
---|
94 | MT_Type type; |
---|
95 | |
---|
96 | char* storedString; |
---|
97 | }; |
---|
98 | |
---|
99 | #endif /* _MULTI_TYPE_H */ |
---|