Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: setValue(type) defined

File size: 2.0 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();
61  int getInt();
62  float getFloat();
63  char getChar();
64  const char* getString();
65
66
67 private:
68   MT_Type             type;
69   union Type
70   {
71     bool             Bool;
72     int              Int;
73     float            Float;
74     char             Char;
75     char*            String;
76   } value;
77
78   char* storedString;
79};
80
81#endif /* _MULTI_TYPE_H */
Note: See TracBrowser for help on using the repository browser.