Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/util/multi_type.h @ 7197

Last change on this file since 7197 was 7197, checked in by bensch, 18 years ago

orxonox/trunk: Executor now uses MultiType instead of va_arg

File size: 3.5 KB
Line 
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.
12typedef 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 */
32class MultiType {
33  public:
34    MultiType(MT_Type type = MT_NULL);
35    MultiType(bool value);
36    MultiType(int value);
37    MultiType(double value);
38    MultiType(char value);
39    MultiType(const char* value);
40    MultiType(const MultiType& multiType);
41    virtual ~MultiType();
42
43    MultiType& operator=(const MultiType& mt);
44    MultiType& operator=(bool value) { this->setBool(value); return *this; };
45    MultiType& operator=(int value) { this->setInt(value); return *this; };
46    MultiType& operator=(float value) { this->setFloat(value); return *this; };
47    MultiType& operator=(char value) { this->setChar(value); return *this; };
48    MultiType& operator=(const char* value) { this->setString(value); return *this; };
49
50    bool operator==(const MultiType& mt) const;
51    bool operator==(bool value) const { return (this->getBool() == value); };
52    bool operator==(int value) const { return (this->getInt() == value); };
53    bool operator==(float value) const { return (this->getFloat() ==  value); };
54    bool operator==(char value) const { return (this->getChar() == value); };
55    bool operator==(const char* value) const;
56    bool operator==(MT_Type type) const { return (this->type == type); }
57    bool operator!=(MT_Type type) const { return (this->type != type); }
58
59    void setType(MT_Type type);
60
61    void setBool(bool value);
62    void setInt(int value);
63    void setFloat(float value);
64    void setChar(char value);
65    void setString(const char* value);
66
67    // for your convenience.
68    inline void setValue(bool value) { this->setBool(value); };
69    inline void setValue(int value) { this->setInt(value); };
70    inline void setValue(float value) { this->setFloat(value); };
71    inline void setValue(char value) { this->setChar(value); };
72    inline void setValue(const char* value) { this->setString(value); };
73
74    /** @returns the Type of the Value stored in this MultiType */
75    inline MT_Type getType() const { return this->type; };
76
77
78    /* RETRIEVING FUNCTIONS */
79    bool getBool() const;
80    int getInt() const;
81    float getFloat() const;
82    char getChar() const;
83    const char* getString();
84
85    void reset();
86
87    void debug();
88
89    static const char* MultiTypeToString(MT_Type type);
90    static MT_Type StringToMultiType(const char* type);
91
92  private:
93    void init();
94
95
96  private:
97    union MultiTypeValue
98    {
99      bool              Bool;
100      int               Int;
101      float             Float;
102      char              Char;
103      char*             String;
104
105    }                   value;
106
107    MT_Type             type;
108
109    char*               storedString;
110};
111
112#endif /* _MULTI_TYPE_H */
Note: See TracBrowser for help on using the repository browser.