Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trunk: MultiType equalities

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