Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5544 was 5544, checked in by bensch, 19 years ago

orxonox/trunk: more elaborate MultiType

File size: 2.2 KB
RevLine 
[4838]1/*!
[5536]2 * @file multi_type.h
[4838]3 * @brief Definition of ...
[3245]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]12typedef 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.
17  MT_FLOAT           = 4,                  //!< A float Value.
18  MT_CHAR            = 8,                  //!< A single char.
19  MT_STRING          = 16,                 //!< An entire String.
[2036]20
[5537]21} MT_Type;
[5536]22
23
24
[5537]25//! A class that encapsulates multiple differen types.
26/**
27 * Only one Value can be Stored inside this Class, but it can have any type: @see MT_Type.
28 */
[5536]29class MultiType {
[1853]30
[1904]31 public:
[5540]32   MultiType();
[5537]33   MultiType(bool value);
[5536]34   MultiType(int value);
[5539]35   MultiType(double value);
[5536]36   MultiType(char value);
37   MultiType(const char* value);
[5537]38   virtual ~MultiType();
39   void init();
[1853]40
[5540]41   MultiType operator= (const MultiType& mt);
[3245]42
[5540]43   void setType(MT_Type);
44
45   void setBool(bool value);
46   void setInt(int value);
47   void setFloat(float value);
48   void setChar(char value);
49   void setString(const char* value);
50
[5541]51   inline void setValue(bool value) { this->setBool(value); };
52   inline void setValue(int value) { this->setInt(value); };
53   inline void setValue(float value) { this->setFloat(value); };
54   inline void setValue(char value) { this->setChar(value); };
55   inline void setValue(const char* value) { this->setString(value); };
56
[5537]57  /** @returns the Type of the Value stored in this MultiType */
58  inline MT_Type getType() const { return this->type; };
[5536]59
[5544]60  bool getBool() const;
61  int getInt() const;
62  float getFloat() const;
63  char getChar() const;
[5537]64  const char* getString();
65
66
[5544]67  void debug();
68
69  static const char* MultiTypeToString(MT_Type type);
70  static MT_Type StringToMultiType(const char* type);
71
[3245]72 private:
[5537]73   MT_Type             type;
[5536]74   union Type
75   {
[5544]76     bool              Bool;
77     int               Int;
78     float             Float;
79     char              Char;
80     char*             String;
[5536]81
[5544]82   }                   value;
83
84   char*               storedString;
[1853]85};
86
[5536]87#endif /* _MULTI_TYPE_H */
Note: See TracBrowser for help on using the repository browser.