[4838] | 1 | /*! |
---|
[5536] | 2 | * @file multi_type.h |
---|
[4838] | 3 | * @brief Definition of ... |
---|
[5545] | 4 | */ |
---|
[1853] | 5 | |
---|
[5536] | 6 | #ifndef _MULTI_TYPE_H |
---|
| 7 | #define _MULTI_TYPE_H |
---|
[1853] | 8 | |
---|
[4838] | 9 | // FORWARD DECLARATION |
---|
[3543] | 10 | |
---|
[5537] | 11 | //! An enumerator defining Types, that can be stored inside a MultiType. |
---|
[5536] | 12 | typedef enum |
---|
| 13 | { |
---|
[5537] | 14 | MT_NULL = 0, //!< No Value at all. |
---|
| 15 | MT_BOOL = 1, //!< A bool Value. |
---|
| 16 | MT_INT = 2, //!< An int Value. |
---|
[5633] | 17 | MT_UINT = 2, |
---|
| 18 | MT_LONG = 2, |
---|
[5537] | 19 | MT_FLOAT = 4, //!< A float Value. |
---|
| 20 | MT_CHAR = 8, //!< A single char. |
---|
| 21 | MT_STRING = 16, //!< An entire String. |
---|
[5633] | 22 | MT_EXT1 = 32, //!< An external Type. |
---|
| 23 | MT_EXT2 = 64, //!< An external Type. |
---|
[5537] | 24 | } MT_Type; |
---|
[5536] | 25 | |
---|
| 26 | |
---|
| 27 | |
---|
[5537] | 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 | */ |
---|
[5536] | 32 | class MultiType { |
---|
[1853] | 33 | |
---|
[5545] | 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); |
---|
[5659] | 41 | MultiType(const MultiType& multiType); |
---|
[5545] | 42 | virtual ~MultiType(); |
---|
[1853] | 43 | |
---|
[5659] | 44 | MultiType& operator= (const MultiType& mt); |
---|
[3245] | 45 | |
---|
[5633] | 46 | void setType(int type); |
---|
[5540] | 47 | |
---|
[5545] | 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); |
---|
[5540] | 53 | |
---|
[5545] | 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); }; |
---|
[5541] | 59 | |
---|
[5545] | 60 | /** @returns the Type of the Value stored in this MultiType */ |
---|
| 61 | inline MT_Type getType() const { return this->type; }; |
---|
[5536] | 62 | |
---|
[5552] | 63 | |
---|
| 64 | /* RETRIEVING FUNCTIONS */ |
---|
[5545] | 65 | bool getBool() const; |
---|
| 66 | int getInt() const; |
---|
| 67 | float getFloat() const; |
---|
| 68 | char getChar() const; |
---|
| 69 | const char* getString(); |
---|
[5537] | 70 | |
---|
[5643] | 71 | void reset(); |
---|
[5537] | 72 | |
---|
[5545] | 73 | void debug(); |
---|
[5544] | 74 | |
---|
[5545] | 75 | static const char* MultiTypeToString(MT_Type type); |
---|
| 76 | static MT_Type StringToMultiType(const char* type); |
---|
[5544] | 77 | |
---|
[5545] | 78 | private: |
---|
| 79 | void init(); |
---|
[5536] | 80 | |
---|
[5544] | 81 | |
---|
[5545] | 82 | private: |
---|
[5659] | 83 | |
---|
[5551] | 84 | union MultiTypeValue |
---|
[5545] | 85 | { |
---|
| 86 | bool Bool; |
---|
| 87 | int Int; |
---|
| 88 | float Float; |
---|
| 89 | char Char; |
---|
| 90 | char* String; |
---|
| 91 | |
---|
| 92 | } value; |
---|
| 93 | |
---|
[5659] | 94 | MT_Type type; |
---|
| 95 | |
---|
[5545] | 96 | char* storedString; |
---|
[1853] | 97 | }; |
---|
| 98 | |
---|
[5536] | 99 | #endif /* _MULTI_TYPE_H */ |
---|