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

orxonox/trunk: setValue(type) defined

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