Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trunk: MultiType comparisons

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