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_FLOAT = 4, //!< A float Value. |
---|
18 | MT_CHAR = 8, //!< A single char. |
---|
19 | MT_STRING = 16, //!< An entire String. |
---|
20 | |
---|
21 | } MT_Type; |
---|
22 | |
---|
23 | |
---|
24 | |
---|
25 | //! A class that encapsulates multiple differen types. |
---|
26 | /** |
---|
27 | * Only one Value can be Stored inside this Class, but it can have any type: @see MT_Type. |
---|
28 | */ |
---|
29 | class MultiType { |
---|
30 | |
---|
31 | public: |
---|
32 | MultiType(); |
---|
33 | MultiType(bool value); |
---|
34 | MultiType(int value); |
---|
35 | MultiType(double value); |
---|
36 | MultiType(char value); |
---|
37 | MultiType(const char* value); |
---|
38 | virtual ~MultiType(); |
---|
39 | |
---|
40 | MultiType operator= (const MultiType& mt); |
---|
41 | |
---|
42 | void setType(MT_Type); |
---|
43 | |
---|
44 | void setBool(bool value); |
---|
45 | void setInt(int value); |
---|
46 | void setFloat(float value); |
---|
47 | void setChar(char value); |
---|
48 | void setString(const char* value); |
---|
49 | |
---|
50 | inline void setValue(bool value) { this->setBool(value); }; |
---|
51 | inline void setValue(int value) { this->setInt(value); }; |
---|
52 | inline void setValue(float value) { this->setFloat(value); }; |
---|
53 | inline void setValue(char value) { this->setChar(value); }; |
---|
54 | inline void setValue(const char* value) { this->setString(value); }; |
---|
55 | |
---|
56 | /** @returns the Type of the Value stored in this MultiType */ |
---|
57 | inline MT_Type getType() const { return this->type; }; |
---|
58 | |
---|
59 | bool getBool() const; |
---|
60 | int getInt() const; |
---|
61 | float getFloat() const; |
---|
62 | char getChar() const; |
---|
63 | const char* getString(); |
---|
64 | |
---|
65 | |
---|
66 | void debug(); |
---|
67 | |
---|
68 | static const char* MultiTypeToString(MT_Type type); |
---|
69 | static MT_Type StringToMultiType(const char* type); |
---|
70 | |
---|
71 | private: |
---|
72 | void init(); |
---|
73 | |
---|
74 | |
---|
75 | private: |
---|
76 | MT_Type type; |
---|
77 | union Type |
---|
78 | { |
---|
79 | bool Bool; |
---|
80 | int Int; |
---|
81 | float Float; |
---|
82 | char Char; |
---|
83 | char* String; |
---|
84 | |
---|
85 | } value; |
---|
86 | |
---|
87 | char* storedString; |
---|
88 | }; |
---|
89 | |
---|
90 | #endif /* _MULTI_TYPE_H */ |
---|