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, 18 years ago

orxonox/trunk: more elaborate MultiType

File size: 2.2 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_FLOAT           = 4,                  //!< A float Value.
18  MT_CHAR            = 8,                  //!< A single char.
19  MT_STRING          = 16,                 //!< An entire String.
20
21} MT_Type;
22
23
24
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 */
29class MultiType {
30
31 public:
32   MultiType();
33   MultiType(bool value);
34   MultiType(int value);
35   MultiType(double value);
36   MultiType(char value);
37   MultiType(const char* value);
38   virtual ~MultiType();
39   void init();
40
41   MultiType operator= (const MultiType& mt);
42
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
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
57  /** @returns the Type of the Value stored in this MultiType */
58  inline MT_Type getType() const { return this->type; };
59
60  bool getBool() const;
61  int getInt() const;
62  float getFloat() const;
63  char getChar() const;
64  const char* getString();
65
66
67  void debug();
68
69  static const char* MultiTypeToString(MT_Type type);
70  static MT_Type StringToMultiType(const char* type);
71
72 private:
73   MT_Type             type;
74   union Type
75   {
76     bool              Bool;
77     int               Int;
78     float             Float;
79     char              Char;
80     char*             String;
81
82   }                   value;
83
84   char*               storedString;
85};
86
87#endif /* _MULTI_TYPE_H */
Note: See TracBrowser for help on using the repository browser.