Changeset 5545 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Nov 11, 2005, 4:32:28 PM (19 years ago)
- Location:
- trunk/src/lib/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/util/multi_type.cc
r5544 r5545 17 17 18 18 #include "multi_type.h" 19 #include <stddef.h> 20 #include <stdlib.h> 21 #include <string.h> 22 #include <stdio.h> 19 #include "stdincl.h" 20 // #include <stddef.h> 21 // #include <stdlib.h> 22 // #include <string.h> 23 // #include <stdio.h> 23 24 24 25 using namespace std; 25 26 27 /** 28 * creates a multiType without any stored value at all. 29 */ 26 30 MultiType::MultiType() 27 31 { … … 30 34 } 31 35 32 36 /** 37 * creates a multiType out of a boolean 38 * @param value the Value of this MulitType 39 */ 33 40 MultiType::MultiType(bool value) 34 41 { … … 37 44 } 38 45 46 /** 47 * creates a multiType out of an integer 48 * @param value the Value of this MulitType 49 */ 39 50 MultiType::MultiType(int value) 40 51 { … … 43 54 } 44 55 45 56 /** 57 * creates a multiType out of a float (double) 58 * @param value the Value of this MulitType 59 */ 46 60 MultiType::MultiType(double value) 47 61 { … … 50 64 } 51 65 52 66 /** 67 * creates a multiType out of a char 68 * @param value the Value of this MulitType 69 */ 53 70 MultiType::MultiType(char value) 54 71 { … … 57 74 } 58 75 59 76 /** 77 * creates a multiType out of a String 78 * @param value the Value of this MulitType 79 */ 60 80 MultiType::MultiType(const char* value) 61 81 { … … 91 111 } 92 112 113 /** 114 * initializes the MultiType 115 */ 93 116 void MultiType::init() 94 117 { … … 104 127 } 105 128 129 /** 130 * sets a new Value to the MultiType 131 * @param value the new Value as a bool 132 */ 106 133 void MultiType::setBool(bool value) 107 134 { … … 110 137 } 111 138 112 139 /** 140 * sets a new Value to the MultiType 141 * @param value the new Value as an int 142 */ 113 143 void MultiType::setInt(int value) 114 144 { … … 117 147 } 118 148 119 149 /** 150 * sets a new Value to the MultiType 151 * @param value the new Value as a float 152 */ 120 153 void MultiType::setFloat(float value) 121 154 { … … 125 158 } 126 159 127 160 /** 161 * sets a new Value to the MultiType 162 * @param value the new Value as a char 163 */ 128 164 void MultiType::setChar(char value) 129 165 { … … 132 168 } 133 169 134 170 /** 171 * sets a new Value to the MultiType 172 * @param value the new Value as a String 173 */ 135 174 void MultiType::setString(const char* value) 136 175 { 137 176 this->type = MT_STRING; 138 this->value.String = new char[strlen(value)+1]; 139 strcpy(this->value.String, value); 140 141 this->storedString = this->value.String; 142 } 143 144 145 146 147 148 177 178 if (this->storedString != NULL) 179 delete[] this->storedString; 180 this->storedString = new char[strlen(value)+1]; 181 strcpy(storedString, value); 182 183 this->value.String = this->storedString; 184 } 185 186 187 188 189 190 /** 191 * @returns the Value of this MultiType as a int 192 */ 149 193 bool MultiType::getBool() const 150 194 { … … 161 205 } 162 206 163 207 /** 208 * @returns the Value of this MultiType as a int 209 */ 164 210 int MultiType::getInt() const 165 211 { … … 182 228 } 183 229 184 230 /** 231 * @returns the Value of this MultiType as a float 232 */ 185 233 float MultiType::getFloat() const 186 234 { … … 204 252 205 253 254 /** 255 * @returns the Value of this MultiType as a char 256 */ 206 257 char MultiType::getChar() const 207 258 { … … 217 268 } 218 269 270 /** 271 * @returns the Value of this MultiType as a String 272 */ 219 273 const char* MultiType::getString() 220 274 { … … 253 307 } 254 308 255 309 /** 310 * prints out some nice debug output 311 */ 256 312 void MultiType::debug() 257 313 { … … 268 324 } 269 325 326 /** 327 * converts a MT_Type into a String 328 * @param type: the MT_Type 329 * @returns: the Type as a constant String (do not delete) 330 */ 270 331 const char* MultiType::MultiTypeToString(MT_Type type) 271 332 { … … 287 348 } 288 349 350 /** 351 * converts a String into a MT_Type 352 * @param type: the Type as a String 353 * @returns: the Type as MT_Type 354 */ 289 355 MT_Type MultiType::StringToMultiType(const char* type) 290 356 { -
trunk/src/lib/util/multi_type.h
r5544 r5545 2 2 * @file multi_type.h 3 3 * @brief Definition of ... 4 */4 */ 5 5 6 6 #ifndef _MULTI_TYPE_H … … 29 29 class MultiType { 30 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(); 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(); 40 39 41 MultiType operator= (const MultiType& mt);40 MultiType operator= (const MultiType& mt); 42 41 43 void setType(MT_Type);42 void setType(MT_Type); 44 43 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);44 void setBool(bool value); 45 void setInt(int value); 46 void setFloat(float value); 47 void setChar(char value); 48 void setString(const char* value); 50 49 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); };50 inline void setValue(bool value) { this->setBool(value); }; 51 inline void setValue(int value) { this->setInt(value); }; 52 inline void setValue(float value) { this->setFloat(value); }; 53 inline void setValue(char value) { this->setChar(value); }; 54 inline void setValue(const char* value) { this->setString(value); }; 56 55 57 /** @returns the Type of the Value stored in this MultiType */58 inline MT_Type getType() const { return this->type; };56 /** @returns the Type of the Value stored in this MultiType */ 57 inline MT_Type getType() const { return this->type; }; 59 58 60 bool getBool() const;61 int getInt() const;62 float getFloat() const;63 char getChar() const;64 const char* getString();59 bool getBool() const; 60 int getInt() const; 61 float getFloat() const; 62 char getChar() const; 63 const char* getString(); 65 64 66 65 67 void debug();66 void debug(); 68 67 69 static const char* MultiTypeToString(MT_Type type);70 static MT_Type StringToMultiType(const char* type);68 static const char* MultiTypeToString(MT_Type type); 69 static MT_Type StringToMultiType(const char* type); 71 70 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; 71 private: 72 void init(); 81 73 82 } value;83 74 84 char* storedString; 75 private: 76 MT_Type type; 77 union Type 78 { 79 bool Bool; 80 int Int; 81 float Float; 82 char Char; 83 char* String; 84 85 } value; 86 87 char* storedString; 85 88 }; 86 89
Note: See TracChangeset
for help on using the changeset viewer.