Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: merged the std-branche back, it runs on windows and Linux

svn merge https://svn.orxonox.net/orxonox/branches/std . -r7202:HEAD

File size: 3.9 KB
RevLine 
[4838]1/*!
[5536]2 * @file multi_type.h
[7199]3 * @brief Definition of a MultiType, that is able to hold one Value of many types.
[5545]4 */
[1853]5
[5536]6#ifndef _MULTI_TYPE_H
7#define _MULTI_TYPE_H
[1853]8
[7199]9#include <string>
10
[4838]11// FORWARD DECLARATION
[3543]12
[5537]13//! An enumerator defining Types, that can be stored inside a MultiType.
[5536]14typedef enum
15{
[5537]16  MT_NULL            = 0,                  //!< No Value at all.
17  MT_BOOL            = 1,                  //!< A bool Value.
18  MT_INT             = 2,                  //!< An int Value.
[5633]19  MT_UINT            = 2,
20  MT_LONG            = 2,
[5537]21  MT_FLOAT           = 4,                  //!< A float Value.
22  MT_CHAR            = 8,                  //!< A single char.
23  MT_STRING          = 16,                 //!< An entire String.
[5633]24  MT_EXT1            = 32,                 //!< An external Type.
25  MT_EXT2            = 64,                 //!< An external Type.
[5537]26} MT_Type;
[5536]27
28
29
[5537]30//! A class that encapsulates multiple differen types.
31/**
32 * Only one Value can be Stored inside this Class, but it can have any type: @see MT_Type.
33 */
[5536]34class MultiType {
[5545]35  public:
[7197]36    MultiType(MT_Type type = MT_NULL);
[5545]37    MultiType(bool value);
38    MultiType(int value);
39    MultiType(double value);
40    MultiType(char value);
[7199]41    MultiType(const std::string& value);
[5659]42    MultiType(const MultiType& multiType);
[5545]43    virtual ~MultiType();
[1853]44
[6643]45    MultiType& operator=(const MultiType& mt);
[6644]46    MultiType& operator=(bool value) { this->setBool(value); return *this; };
47    MultiType& operator=(int value) { this->setInt(value); return *this; };
48    MultiType& operator=(float value) { this->setFloat(value); return *this; };
49    MultiType& operator=(char value) { this->setChar(value); return *this; };
50    MultiType& operator=(const char* value) { this->setString(value); return *this; };
[7199]51    MultiType& operator=(const std::string& value) { this->setString(value); return *this; };
[6644]52
[6643]53    bool operator==(const MultiType& mt) const;
[6644]54    bool operator==(bool value) const { return (this->getBool() == value); };
55    bool operator==(int value) const { return (this->getInt() == value); };
56    bool operator==(float value) const { return (this->getFloat() ==  value); };
57    bool operator==(char value) const { return (this->getChar() == value); };
[7199]58    bool operator==(const std::string& value) const { return (this->getString() == value); };
[6645]59    bool operator==(MT_Type type) const { return (this->type == type); }
60    bool operator!=(MT_Type type) const { return (this->type != type); }
[3245]61
[6645]62    void setType(MT_Type type);
[5540]63
[5545]64    void setBool(bool value);
65    void setInt(int value);
66    void setFloat(float value);
67    void setChar(char value);
[7199]68    void setString(const std::string& value);
[5540]69
[6644]70    // for your convenience.
[5545]71    inline void setValue(bool value) { this->setBool(value); };
72    inline void setValue(int value) { this->setInt(value); };
73    inline void setValue(float value) { this->setFloat(value); };
74    inline void setValue(char value) { this->setChar(value); };
75    inline void setValue(const char* value) { this->setString(value); };
[7199]76    inline void setValue(const std::string& value) { this->setString(value); };
77    void setValueOf(const MultiType& mt);
[5541]78
[5545]79    /** @returns the Type of the Value stored in this MultiType */
80    inline MT_Type getType() const { return this->type; };
[5536]81
[5552]82
83    /* RETRIEVING FUNCTIONS */
[5545]84    bool getBool() const;
85    int getInt() const;
86    float getFloat() const;
87    char getChar() const;
[7199]88    const char* getCString();
89    std::string getString() const;
[5537]90
[5643]91    void reset();
[5537]92
[7199]93    void debug() const;
[5544]94
[5545]95    static const char* MultiTypeToString(MT_Type type);
[7221]96    static MT_Type StringToMultiType(const std::string& type);
[5544]97
[5545]98  private:
[5551]99    union MultiTypeValue
[5545]100    {
101      bool              Bool;
102      int               Int;
103      float             Float;
104      char              Char;
[7199]105//      std::string*      String;
[5545]106    }                   value;
[7221]107    std::string         storedString;
[5659]108    MT_Type             type;
[1853]109};
110
[5536]111#endif /* _MULTI_TYPE_H */
Note: See TracBrowser for help on using the repository browser.