Changeset 7401 for code/trunk/src/libraries/util
- Timestamp:
- Sep 11, 2010, 12:34:00 AM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 40 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/doc (added) merged: 7290-7292,7296-7300,7302-7304,7306-7312,7315-7318,7323,7325,7327,7331-7332,7334-7335,7345-7347,7352-7353,7356-7357,7361,7363-7367,7371-7375,7388
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/util/Clipboard.cc
r6417 r7401 54 54 55 55 /** 56 @brief Puts text into the windows-clipboard 57 @param text The text 56 @brief Puts text into the Windows-clipboard 58 57 @return True if the action was successful 59 58 */ … … 119 118 namespace orxonox 120 119 { 121 static std::string clipboard; // !< Keeps the text of our internal clipboard120 static std::string clipboard; ///< Keeps the text of our internal clipboard 122 121 123 122 /** 124 123 @brief Default implementation if there is no OS-specific implementation or no clipboard. Copies the text into an internal clipboard. 125 @param text The text 126 @return True 124 @see fromClipboard() 127 125 */ 128 126 bool toClipboard(const std::string& text) … … 134 132 /** 135 133 @brief Default implementation if there is no OS-specific implementation or no clipboard. Gets the text from the internal clipboard. 136 @ return The text134 @see toClipboard() 137 135 */ 138 136 std::string fromClipboard() -
code/trunk/src/libraries/util/Clipboard.h
r5781 r7401 29 29 /** 30 30 @file 31 @brief Some functions to exchange text between the OS clipboard and Orxonox. 31 @ingroup Util Command 32 @brief Some functions to exchange text between the OS clipboard and the Shell in Orxonox. 32 33 33 34 Use fromClipboard() to get text from the clipboard (if there is any text) and 34 toClipboard( text) to put text into the clipboard.35 toClipboard() to put text into the clipboard. 35 36 36 Th ose functions can only work properly if there's an OS-specific implementation.37 If an OS isn't supported, the clipboard only works within Orxonox, but exchange38 with other programs isn't possible.37 These functions can only work properly if there's an OS-specific implementation 38 in Clipboard.cc. If a specific OS is not supported, the clipboard only works 39 within Orxonox, but the exchange with other programs is not possible. 39 40 */ 40 41 -
code/trunk/src/libraries/util/Clock.cc
r6417 r7401 45 45 } 46 46 47 /**48 @remarks49 Mind the types! Ogre::Timer::getMicroseconds() will return an unsigned50 long, which will eventually overflow. But if you use the subtraction of51 the current time minus the last time the timer gave us and sum these up to52 a 64 bit integer, we get the desired result.53 Also mind that we don't have to store the last timer's time as unsigned long54 as well because (unsigned long)tickTime_ will do exactly that.55 */56 47 void Clock::capture() 57 48 { -
code/trunk/src/libraries/util/Clock.h
r6417 r7401 27 27 */ 28 28 29 /** 30 @file 31 @ingroup Util 32 */ 33 29 34 #ifndef _Clock_H__ 30 35 #define _Clock_H__ … … 35 40 namespace orxonox 36 41 { 42 /** Simple real time clock based on Ogre::Timer 43 @details 44 The class can be used to both capture the current real time or to 45 incrementally capture the time and then distribute that time information 46 via Clock& references (for instance for the game tick). <br> 47 Precision: <br> 48 @par Precision 49 The maximum precision is given by the Ogre::Timer and that is somewhere 50 in the microsecond range for both Windows and UNIX. 51 @par Remarks for Usage on Windows 52 For proper functionality this class MUST be used in the same thread! <br> 53 Furthermore it might be possible that the Ogre::Timer has a performance 54 caveat because it will only capture the time on the same CPU core. 55 Confining the main thread to one process could speed up the game. 56 See \ref cmdargspage "Ccommandline Argument" 'limitToCPU' (only on Windows) 57 */ 37 58 class _UtilExport Clock 38 59 { 39 60 public: 61 /// Starts the time at 0 40 62 Clock(); 41 63 ~Clock(); 42 64 65 /** Internally captures the time and stays at that particular time 66 @remarks 67 Mind the types! Ogre::Timer::getMicroseconds() will return an unsigned 68 long, which will eventually overflow. But if you use the subtraction of 69 the current time minus the last time the timer gave us and sum these up to 70 a 64 bit integer, we get the desired result. <br> 71 Also mind that we don't have to store the last timer's time as unsigned long 72 as well because (unsigned long)tickTime_ will do exactly that. 73 */ 43 74 void capture(); 44 75 45 unsigned long long getMicroseconds() const { return tickTime_; } 46 unsigned long long getMilliseconds() const { return tickTime_ / 1000; } 47 unsigned long getSeconds() const { return static_cast<long> (tickTime_ / 1000000); } 48 float getSecondsPrecise() const { return static_cast<float>(tickTime_ / 1000000.0f); } 76 /// Returns the last captured absolute time in microseconds 77 unsigned long long getMicroseconds() const 78 { return tickTime_; } 79 /// Returns the last captured absolute time in milliseconds 80 unsigned long long getMilliseconds() const 81 { return tickTime_ / 1000; } 82 /// Returns the last captured absolute time in seconds 83 unsigned long getSeconds() const 84 { return static_cast<long> (tickTime_ / 1000000); } 85 /// Returns the last captured absolute time in seconds as float 86 float getSecondsPrecise() const 87 { return static_cast<float>(tickTime_ / 1000000.0f); } 49 88 50 float getDeltaTime() const { return tickDtFloat_; } 51 long getDeltaTimeMicroseconds() const { return tickDt_; } 89 /// Returns the timespan in seconds between the last two calls to capture() 90 float getDeltaTime() const 91 { return tickDtFloat_; } 92 /// Returns the timespan in microseconds between the last two calls to capture() 93 long getDeltaTimeMicroseconds() const 94 { return tickDt_; } 52 95 96 /** Returns the current real time in microseconds 97 @note 98 This is especially useful to measure execution times because of the 99 high precision. 100 */ 53 101 unsigned long long getRealMicroseconds() const; 54 102 55 103 private: 104 /// Undefined 56 105 Clock(const Clock& instance); 57 106 58 Ogre::Timer* timer_; 59 unsigned long long tickTime_; 60 long tickDt_; 61 float tickDtFloat_; 107 Ogre::Timer* timer_; ///< Ogre timer object 108 unsigned long long tickTime_; ///< Currently captured time 109 long tickDt_; ///< Delta time in microseconds (cache value) 110 float tickDtFloat_; ///< Delta time in seconds (cache value) 62 111 }; 63 112 } -
code/trunk/src/libraries/util/Convert.cc
r7163 r7401 32 32 namespace orxonox 33 33 { 34 //template <class FromType, class ToType>35 34 bool ConverterExplicit<std::string, bool>::convert(bool* output, const std::string& input) 36 35 { -
code/trunk/src/libraries/util/Convert.h
r7305 r7401 28 28 */ 29 29 30 /*! 31 @file 32 @brief Definition and Implementation of the Convert class. 30 /** 31 @defgroup Convert Conversion functions 32 @ingroup Util 33 */ 34 35 /** Functions that convert values between different types. 36 @file 37 @ingroup Convert 38 @par Usage 39 There are three ways to use the conversions depending on what you need. <br> 40 - For simply converting values without having to know whether the conversion 41 was successful (for instance float --> string), use orxonox::multi_cast 42 which effectively works exactly like static_cast, etc. 43 @code 44 float input = 42.0; 45 std::string output = multi_cast<std::string>(input); 46 @endcode 47 - If you care about whether the conversion was successful, 48 use orxonox::convertValue. 49 @code 50 std::string input("3.4"); 51 float output; 52 bool success = convertValue(&output, input); 53 @endcode 54 - If you care about success and if you can also feed a fallback value, 55 use orxonox::convertValue. 56 @code 57 std::string input("3.4"); 58 float output; 59 bool success = convertValue(&output, input, 0.0); 60 @endcode 61 - If success doesn't matter but you can feed a fallback value, 62 use orxonox::getConvertedValue. 63 @code 64 std::string input("3.4"); 65 float output = getConvertedValue(input, 0.0); 66 @endcode 67 @details 68 The back end of these functions are the actual implementations for the 69 specific conversions, for instance from Ogre::Vector3 to std::string and 70 vice versa. Some of them also use the iostream operators. <br> 71 The real deal is evaluating which function is needed for a conversion based 72 on the input and output type. But there are lots of catches in conjunction 73 with templates which explains why there are so many functions in this file. 74 <br> <br> 75 @par Search Order 76 Finding the right function is governed by priority rules: <br> 77 -# (Partial) template specialisation of orxonox::ConverterExplicit::convert() 78 -# An implicit conversion. This includes 'FooBar' to 'int' if FooBar 79 defines operator int() or float(). 80 -# Global or member operators for iostream when converting from or 81 to std::string (and FROM const char*) 82 -# (Partial) template specialisation of orxonox::ConverterFallback::convert() 83 -# Fallback function that displays "Could not convert value" with type 84 information obtained from typeid(). 85 @par Implementing conversion functions 86 To do that you probably need to know a thing or two about the types 87 involved. So, get ready with that. <br> 88 Usually the best way to do it is specialising of the orxonox::ConverterFallback 89 template, like this: 90 @code 91 template <> 92 struct _UtilExport ConverterFallback<std::string, MyType> 93 { 94 static bool convert(MyType* output, const std::string& input) 95 { 96 ... 97 return success; 98 } 99 }; 100 @endcode 101 This piece of code converts an std::string to MyType and returns whether the 102 conversion was successful. You can also use partial specialisation.<br> 103 The advantage with orxonox::ConverterFallback is that it has a low priority 104 meaning that when there is an implicit conversion or an iostream method, that 105 comes first and you don't have to deal with it (and the accompanying 106 function call ambiguity). <br> 107 However sometimes you would like to explicitely replace such a conversion. 108 That's where orxonox::ConverterExplicit comes in handy (for instance we 109 replaced the operator << conversions for Ogre::VectorX with our own functions). 110 @note 111 There has to be an exact type match when using template specialisations. <br> 112 Template specialisations can be defined after including this file. 113 But any implicit cast function or iostream operator has to be included 114 in this file! 115 @par Understanding the Code 116 In order to understand how the templates work, it is probably best to study 117 the functions in order of calling. There are lots of comments explaining 118 what happens, but you'll need to understand a deal about partial template 119 specialisation and function headers are matched in C++. 33 120 */ 34 121 … … 46 133 #include "ImplicitConversion.h" 47 134 48 ////////////////////////////////////49 //// ACTUAL CONVERSION SEQUENCE ////50 ////////////////////////////////////51 /*52 There is a distinct priority when choosing the right conversion function:53 Overwrite:54 1. (Partial) template specialisation of ConverterExplicit::convert()55 Fallbacks:56 2. Any possible implicit conversion. This includes 'FooBar' --> 'int' if FooBar defines operator float().57 3. Global or member operators for stringstream when converting from or to std::string (or FROM const char*)58 4. (Partial) template specialisation of ConverterFallback::convert()59 5. Function that simply displays "Could not convert value" with type information obtained from typeid().60 61 Notes:62 There has to be an exact type match when using template specialisations.63 Template specialisations can be defined after including this file. Any implicit cast function or iostream64 operator has to be declared BEFORE this file gets parsed.65 66 Defining your own functions:67 There are obviously 4 ways to specify a user defined conversion. What should you use?68 69 Usually, ConverterFallback fits quite well. You won't have to deal with the conversion from70 'MyClass' to 'MyClass' by using another explicit template specialisation to avoid ambiguities.71 72 However if you want to overwrite an implicit conversion or an iostream operator, you really need to73 make use of ConverterExplicit. We have to do this for the Ogre classes for instance because they74 define stream operators we don't particulary like.75 */76 77 135 namespace orxonox 78 136 { … … 81 139 /////////////////// 82 140 83 // Default template. No conversion available at all.141 /// Default template. No conversion available at all. 84 142 template <class FromType, class ToType> 85 143 struct ConverterFallback … … 93 151 }; 94 152 95 // If all else fails, try a dynamic_cast for pointer types.153 /// If all else fails, try a dynamic_cast for pointer types. 96 154 template <class FromType, class ToType> 97 155 struct ConverterFallback<FromType*, ToType*> … … 109 167 } 110 168 }; 111 112 ////////////113 // upcast //114 ////////////115 namespace detail116 {117 // perform a static cast if ToType is a base of FromType118 template<class ToType, class FromType>119 FORCEINLINE ToType upcast(FromType input, Loki::Int2Type<true>)120 {121 return static_cast<ToType>(input);122 }123 124 // return zero if ToType is not a base of FromType125 template<class ToType, class FromType>126 FORCEINLINE ToType upcast(FromType input, Loki::Int2Type<false>)127 {128 return 0;129 }130 }131 132 // performs an upcast if ToType is a base of FromType, returns zero otherwise133 template <class ToType, class FromType>134 FORCEINLINE ToType upcast(FromType input)135 {136 enum { probe = ImplicitConversion<FromType, ToType>::exists };137 return detail::upcast<ToType, FromType>(input, Loki::Int2Type<probe>());138 }139 169 } 140 170 … … 144 174 /////////////////////// 145 175 146 // Default template for stringstream 176 /** Fallback template for stringstream 177 @details 178 Neither FromType nor ToType was std::string, therefore 179 delegate to orxonox::ConverterFallback 180 */ 147 181 template <class FromType, class ToType> 148 182 struct ConverterStringStream … … 159 193 ///////////// 160 194 195 /// Extra namespace to avoid exposing the iostream operators in it 161 196 namespace fallbackTemplates 162 197 { 198 /// Fallback operator <<() (delegates to orxonox::ConverterFallback) 163 199 template <class FromType> 164 200 FORCEINLINE bool operator <<(std::ostream& outstream, const FromType& input) … … 175 211 } 176 212 177 // template that evaluates whether we can convert to std::string via ostringstream213 /// Template that evaluates whether we can convert to std::string via ostringstream 178 214 template <class FromType> 179 215 struct ConverterStringStream<FromType, std::string> … … 182 218 { 183 219 using namespace fallbackTemplates; 184 // this operator call only chooses fallbackTemplates::operator<< if there's no other fitting function 220 // this operator call only chooses fallbackTemplates::operator<<() 221 // if there's no other fitting function 185 222 std::ostringstream oss; 223 // Note: std::ostream has operator!() to tell whether any error flag was set 186 224 if (oss << input) 187 225 { … … 201 239 namespace fallbackTemplates 202 240 { 241 /// Fallback operator >>() (delegates to orxonox::ConverterFallback) 203 242 template <class ToType> 204 243 FORCEINLINE bool operator >>(std::istream& instream, ToType& output) 205 244 { 206 return orxonox::ConverterFallback<std::string, ToType>207 ::convert(&output, static_cast<std::istringstream&>(instream).str());245 std::string input(static_cast<std::istringstream&>(instream).str()); 246 return orxonox::ConverterFallback<std::string, ToType>::convert(&output, input); 208 247 } 209 248 } 210 249 211 // template that evaluates whether we can convert from std::string via ostringstream250 /// Template that evaluates whether we can convert from std::string via istringstream 212 251 template <class ToType> 213 252 struct ConverterStringStream<std::string, ToType> … … 216 255 { 217 256 using namespace fallbackTemplates; 257 // this operator call chooses fallbackTemplates::operator>>() 258 // only if there's no other fitting function 218 259 std::istringstream iss(input); 219 // this operator call only chooses fallbackTemplates::operator>> if there's no other fitting function260 // Note: std::istream has operator!() to tell whether any error flag was set 220 261 if (iss >> (*output)) 221 262 { … … 229 270 namespace orxonox 230 271 { 231 232 272 /////////////////// 233 273 // Implicit Cast // 234 274 /////////////////// 235 275 236 // implicit cast not possible, try stringstream conversion next276 /// %Template delegates to ::ConverterStringStream 237 277 template <class FromType, class ToType> 238 278 FORCEINLINE bool convertImplicitely(ToType* output, const FromType& input, Loki::Int2Type<false>) … … 241 281 } 242 282 243 // We can cast implicitely283 /// Makes an implicit cast from \a FromType to \a ToType 244 284 template <class FromType, class ToType> 245 285 FORCEINLINE bool convertImplicitely(ToType* output, const FromType& input, Loki::Int2Type<true>) … … 254 294 //////////////////////////////// 255 295 256 // Default template if no specialisation is available 296 /** Default template if no orxonox::ConverterExplicit is available 297 @details 298 Evaluates whether \a FromType can be implicitly converted to \a ToType 299 by the use the ImplicitConversion magic. 300 */ 257 301 template <class FromType, class ToType> 258 302 struct ConverterExplicit … … 261 305 FORCEINLINE static bool convert(ToType* output, const FromType& input) 262 306 { 263 // Try implict cast and probe first. If a simple cast is not possible, it will not compile 264 // We therefore have to out source it into another template function 307 // Use the probe's value to delegate to the right function 265 308 return convertImplicitely(output, input, Loki::Int2Type<probe>()); 266 309 } … … 275 318 @brief 276 319 Converts any value to any other as long as there exists a conversion. 320 @details 277 321 Otherwise, the conversion will generate a runtime warning and return false. 278 For information about the different conversion methods (user defined too), see the section 279 'Actual conversion sequence' in this file above. 322 @see Convert.h 323 @param output 324 A pointer to the variable where the converted value will be stored 325 @param input 326 The original value 280 327 */ 281 328 template <class FromType, class ToType> … … 291 338 Converts any value to any other as long as there exists a conversion. 292 339 Otherwise, the conversion will generate a runtime warning and return false. 293 For information about the different conversion methods (user defined too), see the section 294 'Actual conversion sequence' in this file above. 295 If the conversion doesn't succeed, 'fallback' is written to '*output'. 340 If the conversion doesn't succeed, \a fallback is written to \a output. 341 @see Convert.h 342 @param output 343 A pointer to the variable where the converted value will be stored 344 @param input 345 The original value 296 346 @param fallback 297 347 A default value that gets written to '*output' if there is no conversion. … … 309 359 } 310 360 311 // Directly returns the converted value, even if the conversion was not successful.361 /// Directly returns the converted value, but uses the fallback on failure. @see convertValue 312 362 template<class FromType, class ToType> 313 FORCEINLINE ToType getConvertedValue(const FromType& input) 363 FORCEINLINE ToType getConvertedValue(const FromType& input, const ToType& fallback) 364 { 365 ToType output; 366 convertValue(&output, input, fallback); 367 return output; 368 } 369 370 /** 371 @brief 372 Converts any value to any other as long as there exists a conversion. 373 @details 374 Use exactly the way you use static_cast, etc. <br> 375 A failed conversion will return a default instance of \a ToType 376 (possibly uninitialised) 377 @see Convert.h 378 @param input 379 The original value 380 */ 381 template<class ToType, class FromType> 382 FORCEINLINE ToType multi_cast(const FromType& input) 314 383 { 315 384 ToType output; … … 318 387 } 319 388 320 // Directly returns the converted value, but uses the fallback on failure.321 template<class FromType, class ToType>322 FORCEINLINE ToType getConvertedValue(const FromType& input, const ToType& fallback)323 {324 ToType output;325 convertValue(&output, input, fallback);326 return output;327 }328 329 // Like getConvertedValue, but the template argument order is in reverse.330 // That means you can call it exactly like static_cast<ToType>(fromTypeValue).331 template<class ToType, class FromType>332 FORCEINLINE ToType multi_cast(const FromType& input)333 {334 ToType output;335 convertValue(&output, input);336 return output;337 }338 339 389 //////////////////////////////// 340 390 // Special string conversions // 341 391 //////////////////////////////// 342 392 343 // Delegateconversion from const char* to std::string393 /// Delegates conversion from const char* to std::string 344 394 template <class ToType> 345 395 struct ConverterExplicit<const char*, ToType> … … 351 401 }; 352 402 353 // These conversions would exhibit ambiguous << or >> operators when using stringstream403 /// Conversion would exhibit ambiguous << or >> operators when using iostream 354 404 template <> 355 405 struct ConverterExplicit<char, std::string> … … 361 411 } 362 412 }; 413 /// Conversion would exhibit ambiguous << or >> operators when using iostream 363 414 template <> 364 415 struct ConverterExplicit<unsigned char, std::string> … … 370 421 } 371 422 }; 423 /// Conversion would exhibit ambiguous << or >> operators when using iostream 372 424 template <> 373 425 struct ConverterExplicit<std::string, char> … … 382 434 } 383 435 }; 436 /// Conversion would exhibit ambiguous << or >> operators when using iostream 384 437 template <> 385 438 struct ConverterExplicit<std::string, unsigned char> … … 396 449 397 450 398 // bool to std::string451 /// Conversion from bool to std::string 399 452 template <> 400 453 struct ConverterExplicit<bool, std::string> … … 410 463 }; 411 464 412 // std::string to bool465 /// Conversion from std::string to bool 413 466 template <> 414 467 struct _UtilExport ConverterExplicit<std::string, bool> -
code/trunk/src/libraries/util/Debug.h
r6443 r7401 29 29 30 30 /** 31 @defgroup COUT COUT(x) output macro 32 @ingroup Util 33 */ 34 35 /** 31 36 @file 37 @ingroup COUT 32 38 @brief 33 Handles different output-levels of errors, warnings, infos and debug information.39 Handles different output-levels of errors, warnings, infos, and debug information. 34 40 35 The COUT(level) macro acts like std::cout, but the output is only performed if the given41 The COUT(level) macro acts like @c std::cout, but the output is only performed if the given 36 42 level is <= the soft debug level. 37 43 … … 39 45 - The hard debug level is used during compile time. It describes the highest allowed output level. 40 46 - The soft debug level is used during runtime and is the maximum of the three configurable 41 output-levels for console, log file and in game shell.47 output-levels for console, log file, and in game shell. 42 48 43 49 The separation between the three devices is done by the OutputHandler. 44 50 51 @anchor COUTlevels 45 52 Possible levels are: 46 0: Very important output47 1: Errors48 2: Warnings49 3: Information50 4: Debug information51 5: More debug information52 6: Crazy debug information53 - 0: Very important output 54 - 1: Errors 55 - 2: Warnings 56 - 3: Information 57 - 4: Debug information 58 - 5: More debug information 59 - 6: Crazy debug information 53 60 54 @example 61 Example: 62 @code 55 63 COUT(0) << "Very important output" << std::endl; 56 64 COUT(1) << "Error: Something went wrong!" << std::endl; … … 58 66 COUT(3) << "Info: It's Monday" << std::endl; 59 67 COUT(4) << "Debug: x is 1.23456" << std::endl; 68 @endcode 60 69 */ 61 70 … … 90 99 /** 91 100 @brief 92 Logs text output: use exactly like std::cout, but specify an output 93 level as argument. 94 @details 95 (a > b ? 0 : c << "text") is equivalent to (a > b ? 0 : (c << "text")) 96 where (a > b ? 0 : ) stands for COUT(x). This should explain how 101 Logs text output: You can use COUT(level) exactly like @c std::cout, but you have to specify an output level as argument. 102 @param level 103 The level of the following output (passed with <tt><< "text"</tt>). Lower levels are more important. See @ref COUTlevels "the description above" for a list of possible output levels. 104 105 Example: 106 @code 107 COUT(3) << "Some info" << std::endl; // Output with level 3 108 @endcode 109 @note 110 <tt>(a > b ? 0 : c << "text")</tt> is equivalent to <tt>(a > b ? 0 : (c << "text")</tt> 111 where <tt>(a > b ? 0 : )</tt> stands for COUT(x). This should explain how 97 112 this macro magic can possibly even work ;) 98 @example 99 COUT(3) << "Some info" << std::endl; 100 @note 101 The ? : operator requires both possible results to have the type of 113 @remarks 114 The <tt>? :</tt> operator requires both possible results to have the type of 102 115 the first. This is achieved by the int conversion operator dummy 103 in the OutputHandler.116 in the @ref orxonox::OutputHandler. 104 117 */ 105 118 #define COUT(level) \ -
code/trunk/src/libraries/util/Exception.cc
r7174 r7401 53 53 { } 54 54 55 /**56 @remarks57 The composed full description gets stored to fullDescription_. But for compliance58 with std::exception, this method has to be const. Hence fullDescription_ is declared59 as mutable.60 */61 55 const std::string& Exception::getFullDescription() const 62 56 { … … 89 83 } 90 84 91 //! Returns the error description92 85 const char* Exception::what() const throw() 93 86 { -
code/trunk/src/libraries/util/Exception.h
r6417 r7401 28 28 29 29 /** 30 @defgroup ExceptionAssertion Exceptions and assertions 31 @ingroup Util 32 */ 33 34 /** 30 35 @file 36 @ingroup ExceptionAssertion 31 37 @brief 32 38 Declaration of facilities to handle exceptions. 39 @details 40 Any exception thrown should inherit from orxonox::Exception. There is a macro 41 \ref CREATE_ORXONOX_EXCEPTION to create a new exception (you can find a list of 42 available exceptions in the docs of this file). <br> 43 Throwing exception is also very simple: 44 @code 45 ThrowException(General, "Something went wrong"); 46 @endcode 47 (\c General is a type of exception, see docs of this file) <br> 48 The exception will automatically contain information about file, line number 49 and function name it occurred in. <br><br> 50 There is also some magic you can do for numbers, etc.: 51 @code 52 ThrowException(General, "Error code: " << myInt << ". more info..."); 53 @endcode 54 It works with an std::ostringstream, so you can feed it all sorts of values. 33 55 */ 34 56 … … 45 67 namespace orxonox 46 68 { 47 /** 48 @brief 49 Base class for all exceptions (derived from std::exception). 69 /** Base class for all exceptions (derived from std::exception). 50 70 @details 51 71 This class provides support for information about the file, the line 52 and the function the error occured. 72 and the function the error occurred. 73 @see Exception.h 53 74 */ 54 75 class _UtilExport Exception : public std::exception … … 60 81 @param description 61 82 Exception description as string. This message is supposed to help developers! 83 @param lineNumber 84 The number of the code-line in which the exception occurred 85 @param filename 86 The file in which the exception occurred 87 @param functionName 88 The function in which the exception occurred 62 89 */ 63 90 Exception(const std::string& description, unsigned int lineNumber, … … 68 95 //! Needed for compatibility with std::exception 69 96 virtual ~Exception() throw() { } 97 //! Returns the error description 70 98 const char* what() const throw(); 71 99 72 //! Returns a full description with type, line, file and function 100 /** Returns a full description with type, line, file and function 101 @remarks 102 The composed full description gets stored to fullDescription_. But for compliance 103 with std::exception, this method has to be const. Hence fullDescription_ is declared 104 as mutable. 105 */ 73 106 virtual const std::string& getFullDescription() const; 74 107 //! Returns the string name of the exception type … … 101 134 }; 102 135 103 //! Creates a new type of exception that inherits from tracker::Exception136 //! Creates a new type of exception that inherits from orxonox::Exception 104 137 #define CREATE_ORXONOX_EXCEPTION(ExceptionName) \ 105 138 class ExceptionName##Exception : public Exception \ … … 123 156 // Creates all possible exception types. 124 157 // If you want to add a new type, simply copy and adjust a new line here. 125 #ifndef DOXYGEN_SHOULD_SKIP_THIS126 158 CREATE_ORXONOX_EXCEPTION(General); 127 159 CREATE_ORXONOX_EXCEPTION(FileNotFound); … … 136 168 CREATE_ORXONOX_EXCEPTION(NoGraphics); 137 169 CREATE_ORXONOX_EXCEPTION(AbortLoading); 138 #endif139 170 140 /** 141 @brief 142 Helper function that forwards an exception and displays the message. 171 /** Helper function that forwards an exception and displays the message. 143 172 @details 144 173 This is necessary because only when using 'throw' the objects storage is managed. … … 152 181 } 153 182 154 /** 155 @brief 156 Throws an exception and logs a message beforehand. 183 /** Throws an exception and logs a message beforehand. 157 184 @param type 158 185 Type of the exception as literal (General, Initialisation, etc.) 159 186 @param description 160 187 Exception description as string 188 @see Exception.h 161 189 */ 162 190 #define ThrowException(type, description) \ -
code/trunk/src/libraries/util/ExprParser.h
r6417 r7401 28 28 29 29 /** 30 @file 31 @brief Declaration of FloatParser 30 @file 31 @ingroup Util 32 @brief Declaration of FloatParser 32 33 */ 33 34 … … 42 43 namespace orxonox 43 44 { 45 /** Parser for expressions like \c "3 * cos(5 + 4) / a" where \a a is a predeclared 46 variable. 47 @par Usage 48 Using it is rather simple: 49 @code 50 std::string str("3 + 4"); 51 ExprParser expr; 52 expr.parse(str); 53 if (expr.getSuccess()) 54 { 55 if (!expr.getRemains().empty()) 56 { 57 COUT(2) << "Warning: Expression could not be parsed to the end! Remains: '" << expr.getRemains() << '\'' << std::endl; 58 } 59 double result = expr.getResult(); 60 } 61 else 62 COUT(1) << "Error: Cannot calculate expression: Parse error." << std::endl; 63 @endcode 64 getRemains() returns the expression after what could be parsed. For instance 65 \c "2*3 text" will return \c "text" as remains. 66 @details 67 The implementation of this class is really old and sort of a trial for 68 a first C++ class by Reto. That explains why it looks more like C than 69 C++... Also some of the variable names are in German. <br> 70 Explaining how it works exactly is probably not possible anymore, but it 71 is based on recursively parsing the expression character by character. 72 That much I can remember. 73 @par Functions, operators and variables supported 74 - Variables: 75 - e 76 - pi 77 - Functions: 78 - sin, asin, sinh, asinh 79 - cos, acos, cosh, acosh 80 - tan, atan, tanh, atanh 81 - int, floor, ceil, abs, sign 82 - pow, sqrt, exp, ln, log 83 - mod, div 84 - min, max 85 - radians, degrees 86 - Operators: 87 - +, -, ! (unary) 88 - +, -, *, /, %, ^, |, &, !, <, >, !=, <=, >=, = 89 @note 90 Operators may not be very consistent with C++ rules, but using the class 91 for plus and minus should be perfectly ok. 92 */ 44 93 class _UtilExport ExprParser 45 94 { -
code/trunk/src/libraries/util/ImplicitConversion.h
r7305 r7401 29 29 /** 30 30 @file 31 @ingroup Util 31 32 @brief Declaration of various helper templates. 32 33 */ -
code/trunk/src/libraries/util/Math.cc
r7284 r7401 91 91 @param mydirection My viewing direction 92 92 @param otherposition The position of the other object 93 @return The angle 94 95 @example96 If the other object is exactly in front of me, the function returns 0.97 If the other object is exactly behind me, the function returns pi.98 If the other object is exactly right/left to me (or above/below), the function returns pi/2.93 @return The angle in radian 94 95 Examples: 96 - If the other object is exactly in front of me, the function returns 0. 97 - If the other object is exactly behind me, the function returns pi. 98 - If the other object is exactly right/left to me (or above/below), the function returns pi/2. 99 99 */ 100 100 float getAngle(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& otherposition) … … 116 116 @return The viewing direction 117 117 118 @example119 If the other object is exactly in front of me, the function returns Vector2(0, 0).120 If the other object is exactly at my left, the function returns Vector2(-1, 0).121 If the other object is exactly at my right, the function returns Vector2(1, 0).122 If the other object is only a bit at my right, the function still returns Vector2(1, 0).123 If the other object is exactly above me, the function returns Vector2(0, 1).118 Examples: 119 - If the other object is exactly in front of me, the function returns <tt>Vector2(0, 0)</tt>. 120 - If the other object is exactly at my left, the function returns <tt>Vector2(-1, 0)</tt>. 121 - If the other object is exactly at my right, the function returns <tt>Vector2(1, 0)</tt>. 122 - If the other object is only a bit at my right, the function still returns <tt>Vector2(1, 0)</tt>. 123 - If the other object is exactly above me, the function returns <tt>Vector2(0, 1)</tt>. 124 124 */ 125 125 orxonox::Vector2 get2DViewdirection(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition) … … 156 156 @return The viewing direction 157 157 158 @example159 If the other object is exactly in front of me, the function returns Vector2(0, 0).160 If the other object is exactly at my left, the function returns Vector2(-0.5, 0).161 If the other object is exactly at my right, the function returns Vector2(0.5, 0).162 If the other object is only a bit at my right, the function still returns Vector2(0.01, 0).163 If the other object is exactly above me, the function returns Vector2(0, 0.5).158 Examples: 159 - If the other object is exactly in front of me, the function returns <tt>Vector2(0, 0)</tt>. 160 - If the other object is exactly at my left, the function returns <tt>Vector2(-0.5, 0)</tt>. 161 - If the other object is exactly at my right, the function returns <tt>Vector2(0.5, 0)</tt>. 162 - If the other object is only a bit at my right, the function still returns <tt>Vector2(0.01, 0)</tt>. 163 - If the other object is exactly above me, the function returns <tt>Vector2(0, 0.5)</tt>. 164 164 */ 165 165 orxonox::Vector2 get2DViewcoordinates(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition) … … 220 220 } 221 221 222 /** 223 @brief Returns a unique number. This function will never return the same value twice. 224 */ 222 225 unsigned long getUniqueNumber() 223 226 { -
code/trunk/src/libraries/util/Math.h
r7184 r7401 28 28 29 29 /** 30 @defgroup Math Mathematical functions 31 @ingroup Util 32 */ 33 34 /** 30 35 @file 36 @ingroup Math 31 37 @brief Declaration and implementation of several math-functions, typedefs of some Ogre::Math classes to the orxonox namespace. 32 38 */ … … 62 68 namespace math 63 69 { 64 const float pi = 3.14159265f; 65 const float pi_2 = 1.57079633f; 66 const float pi_4 = 7.85398163e-1f; 67 const float e = 2.71828183f; 68 const float sqrt2 = 1.41421356f; 69 const float sqrt2_2 = 7.07106781e-1f; 70 71 const double pi_d = 3.14159265358979324; 72 const double pi_2_d = 1.57079632679489662; 73 const double pi_4_d = 7.85398163397448310e-1; 74 const double e_d = 2.71828182845904524; 75 const double sqrt2_d = 1.41421356237309505; 76 const double sqrt2_2_d = 7.07106781186547524e-1; 70 const float pi = 3.14159265f; ///< PI 71 const float pi_2 = 1.57079633f; ///< PI / 2 72 const float pi_4 = 7.85398163e-1f; ///< PI / 4 73 const float e = 2.71828183f; ///< e 74 const float sqrt2 = 1.41421356f; ///< sqrt(2) 75 const float sqrt2_2 = 7.07106781e-1f; ///< sqrt(2) / 2 76 77 const double pi_d = 3.14159265358979324; ///< PI (double) 78 const double pi_2_d = 1.57079632679489662; ///< PI / 2 (double) 79 const double pi_4_d = 7.85398163397448310e-1; ///< PI / 4 (double) 80 const double e_d = 2.71828182845904524; ///< e (double) 81 const double sqrt2_d = 1.41421356237309505; ///< sqrt(2) (double) 82 const double sqrt2_2_d = 7.07106781186547524e-1; ///< sqrt(2) / 2 (double) 77 83 } 78 84 … … 101 107 102 108 /** 103 @brief Keeps a value between a lower and an upper limit. 109 @brief Keeps a value between a lower and an upper limit. Values beyond these limits are limited to either @a min or @a max. 104 110 @param x The value 105 111 @param min The lower limit … … 119 125 120 126 /** 121 @brief Returns the square value (x^2).127 @brief Returns the squared value (x^2). 122 128 */ 123 129 template <typename T> … … 128 134 129 135 /** 130 @brief Returns the cube value (x^3).136 @brief Returns the cubed value (x^3). 131 137 */ 132 138 template <typename T> … … 137 143 138 144 /** 139 @brief Rounds the value .145 @brief Rounds the value to the nearest integer. 140 146 */ 141 147 template <typename T> … … 149 155 @param x The value 150 156 @param max The operand 157 158 The built in modulo operator % yields a strange behavior with negative values. 159 This function corrects this - the result is guaranteed to lie always between 160 zero and (max-1). 161 162 Example: 163 @code 164 int var = 11 % 10; // 1 165 int var = -1 % 10; // -1 166 167 int var = mod(11, 10); // 1 168 int var = mod(-1, 10); // 9 169 @endcode 151 170 */ 152 171 template <typename T> … … 159 178 } 160 179 180 /** 181 @brief Returns a "zero" value for the given type. 182 @note This is the default template of the zeroise() function. The template is spezialized for each supported type. 183 184 The exact return value of the function depends on the type. For @c int this is 0, 185 for @c float it's 0.0f. For a @c std::string the function returns "" and for 186 @c Vector3 you get <tt>Vector3(0, 0, 0)</tt>. 187 */ 161 188 template <typename T> 162 189 inline T zeroise() … … 192 219 template <> inline orxonox::Quaternion zeroise<orxonox::Quaternion>() { return orxonox::Quaternion (0, 0, 0, 0); } 193 220 194 //! Provides zero value symbols that can be returned as reference 221 /** 222 @brief Provides zero value symbols that can be returned as reference 223 @see zeroise() 224 */ 195 225 template <typename T> 196 226 struct NilValue … … 207 237 /** 208 238 @brief Interpolates between two values for a time between 0 and 1. 209 @param time The time is a value between 0 and 1 - the function returns start if time is 0 and end if time is 1 and interpolates iftime is between 0 and 1.210 @param start The value at time = 0211 @param end The value at time = 1212 @return The interpolat ionat a given time239 @param time The time is a value between 0 and 1 - the function returns @a start if @a time is 0, @a end if @a time is 1, and interpolates if @a time is between 0 and 1. 240 @param start The value at @a time = 0 241 @param end The value at @a time = 1 242 @return The interpolated value at a given time 213 243 */ 214 244 template <typename T> … … 220 250 /** 221 251 @brief Interpolates smoothly between two values for a time between 0 and 1. The function starts slowly, increases faster and stops slowly again. 222 @param time The time is a value between 0 and 1 - the function returns start if time is 0 and end if time is 1 and interpolates iftime is between 0 and 1.223 @param start The value at time = 0224 @param end The value at time = 1225 @return The smoothed interpolationat a given time252 @param time The time is a value between 0 and 1 - the function returns @a start if @a time is 0, @a end if @a time is 1, and interpolates if @a time is between 0 and 1. 253 @param start The value at @a time = 0 254 @param end The value at @a time = 1 255 @return The interpolated value at a given time 226 256 */ 227 257 template <typename T> … … 232 262 233 263 /** 234 @brief Returns a random number between 0 and almost 1: 0 <= rnd < 1.264 @brief Returns a random number between 0 and almost 1: <tt>0 <= rnd < 1</tt>. 235 265 */ 236 266 inline float rnd() … … 240 270 241 271 /** 242 @brief Returns a random number between 0 and almost max: 0 <= rnd < max.272 @brief Returns a random number between 0 and almost @a max: <tt>0 <= rnd < max</tt>. 243 273 @param max The maximum 244 274 */ … … 249 279 250 280 /** 251 @brief Returns a random number between min and almost max: min <= rnd < max.281 @brief Returns a random number between @a min and almost @a max: <tt>min <= rnd < max</tt>. 252 282 @param min The minimum 253 283 @param max The maximum … … 268 298 _UtilExport unsigned long getUniqueNumber(); 269 299 300 /** 301 @brief A Vector class containing two integers @a x and @a y. 302 */ 270 303 class IntVector2 271 304 { … … 277 310 }; 278 311 312 /** 313 @brief A Vector class containing three integers @a x, @a y, and @a z. 314 */ 279 315 class IntVector3 280 316 { -
code/trunk/src/libraries/util/MathConvert.h
r6417 r7401 28 28 29 29 /** 30 @file 31 @brief 32 Math conversion functions. Definitions are in Math.cc 30 @file 31 @ingroup Convert 32 @brief 33 Conversion functions for Math types like Ogre::Vector3 (definitions are in Math.cc) 33 34 */ 34 35 … … 46 47 //////////////////// 47 48 48 // Vector2 to std::string49 /// Ogre::Vector2 to std::string conversion 49 50 template <> 50 51 struct ConverterExplicit<orxonox::Vector2, std::string> … … 62 63 }; 63 64 64 // Vector3 to std::string65 /// Ogre::Vector3 to std::string conversion 65 66 template <> 66 67 struct ConverterExplicit<orxonox::Vector3, std::string> … … 78 79 }; 79 80 80 // Vector4 to std::string81 /// Ogre::Vector4 to std::string conversion 81 82 template <> 82 83 struct ConverterExplicit<orxonox::Vector4, std::string> … … 94 95 }; 95 96 96 // Quaternion to std::string97 /// Ogre::Quaternion to std::string conversion 97 98 template <> 98 99 struct ConverterExplicit<orxonox::Quaternion, std::string> … … 110 111 }; 111 112 112 // ColourValue to std::string113 /// Ogre::ColourValue to std::string conversion 113 114 template <> 114 115 struct ConverterExplicit<orxonox::ColourValue, std::string> … … 131 132 //////////////////// 132 133 133 // std::string to Vector2134 /// std::string to Ogre::Vector2 conversion 134 135 template <> struct _UtilExport ConverterFallback<std::string, orxonox::Vector2> 135 136 { static bool convert(orxonox::Vector2* output, const std::string& input); }; 136 // std::string to Vector3137 /// std::string to Ogre::Vector3 conversion 137 138 template <> struct _UtilExport ConverterFallback<std::string, orxonox::Vector3> 138 139 { static bool convert(orxonox::Vector3* output, const std::string& input); }; 139 // std::string to Vector4140 /// std::string to Ogre::Vector4 conversion 140 141 template <> struct _UtilExport ConverterFallback<std::string, orxonox::Vector4> 141 142 { static bool convert(orxonox::Vector4* output, const std::string& input); }; 142 // std::string to Quaternion143 /// std::string to Ogre::Quaternion conversion 143 144 template <> struct _UtilExport ConverterFallback<std::string, orxonox::Quaternion> 144 145 { static bool convert(orxonox::Quaternion* output, const std::string& input); }; 145 // std::string to ColourValue146 /// std::string to Ogre::ColourValue conversion 146 147 template <> struct _UtilExport ConverterFallback<std::string, orxonox::ColourValue> 147 148 { static bool convert(orxonox::ColourValue* output, const std::string& input); }; … … 152 153 /////////////////////////////// 153 154 154 // From Radian155 /// Delegates conversions from Radian to conversions from float 155 156 template <class ToType> 156 157 struct ConverterFallback<orxonox::Radian, ToType> … … 162 163 }; 163 164 164 // From Degree165 /// Delegates conversions from Degree to conversions from float 165 166 template <class ToType> 166 167 struct ConverterFallback<orxonox::Degree, ToType> … … 172 173 }; 173 174 174 // To Radian175 /// Delegates conversions to Radian to conversions to float 175 176 template <class FromType> 176 177 struct ConverterFallback<FromType, orxonox::Radian> … … 189 190 }; 190 191 191 // To Degree192 /// Delegates conversions to Degree to conversions to float 192 193 template <class FromType> 193 194 struct ConverterFallback<FromType, orxonox::Degree> -
code/trunk/src/libraries/util/MultiType.cc
r5738 r7401 159 159 } 160 160 161 MultiType::operator char() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Char ) ? (static_cast<MT_Value<char> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */162 MultiType::operator unsigned char() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedChar ) ? (static_cast<MT_Value<unsigned char> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */163 MultiType::operator short() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Short ) ? (static_cast<MT_Value<short> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */164 MultiType::operator unsigned short() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedShort ) ? (static_cast<MT_Value<unsigned short> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */165 MultiType::operator int() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Int ) ? (static_cast<MT_Value<int> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */166 MultiType::operator unsigned int() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedInt ) ? (static_cast<MT_Value<unsigned int> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */167 MultiType::operator long() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Long ) ? (static_cast<MT_Value<long> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */168 MultiType::operator unsigned long() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedLong ) ? (static_cast<MT_Value<unsigned long> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */169 MultiType::operator long long() const { return (this->value_) ? ((this->value_->type_ == MT_Type::LongLong ) ? (static_cast<MT_Value<long long> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */170 MultiType::operator unsigned long long() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedLongLong) ? (static_cast<MT_Value<unsigned long long> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */171 MultiType::operator float() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Float ) ? (static_cast<MT_Value<float> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */172 MultiType::operator double() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Double ) ? (static_cast<MT_Value<double> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */173 MultiType::operator long double() const { return (this->value_) ? ((this->value_->type_ == MT_Type::LongDouble ) ? (static_cast<MT_Value<long double> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */174 MultiType::operator bool() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Bool ) ? (static_cast<MT_Value<bool> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */175 MultiType::operator void*() const { return (this->value_) ? ((this->value_->type_ == MT_Type::VoidPointer ) ? (static_cast<MT_Value<void*> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */176 MultiType::operator std::string() const { return (this->value_) ? ((this->value_->type_ == MT_Type::String ) ? (static_cast<MT_Value<std::string> *>(this->value_))->value_ : (*this->value_)) : NilValue<std::string>(); } / ** @brief Returns the current value, converted to the requested type. */177 MultiType::operator orxonox::Vector2() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Vector2 ) ? (static_cast<MT_Value<orxonox::Vector2> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Vector2>(); } / ** @brief Returns the current value, converted to the requested type. */178 MultiType::operator orxonox::Vector3() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Vector3 ) ? (static_cast<MT_Value<orxonox::Vector3> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Vector3>(); } / ** @brief Returns the current value, converted to the requested type. */179 MultiType::operator orxonox::Vector4() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Vector4 ) ? (static_cast<MT_Value<orxonox::Vector4> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Vector4>(); } / ** @brief Returns the current value, converted to the requested type. */180 MultiType::operator orxonox::ColourValue() const { return (this->value_) ? ((this->value_->type_ == MT_Type::ColourValue ) ? (static_cast<MT_Value<orxonox::ColourValue>*>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::ColourValue>(); } / ** @brief Returns the current value, converted to the requested type. */181 MultiType::operator orxonox::Quaternion() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Quaternion ) ? (static_cast<MT_Value<orxonox::Quaternion> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Quaternion>(); } / ** @brief Returns the current value, converted to the requested type. */182 MultiType::operator orxonox::Radian() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Radian ) ? (static_cast<MT_Value<orxonox::Radian> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Radian>(); } / ** @brief Returns the current value, converted to the requested type. */183 MultiType::operator orxonox::Degree() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Degree ) ? (static_cast<MT_Value<orxonox::Degree> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Degree>(); } / ** @brief Returns the current value, converted to the requested type. */184 185 template <> void MultiType::createNewValueContainer(const char& value) { this->value_ = new MT_Value<char> (value, MT_Type::Char ); } / ** @brief Creates a new value container for the given type. */186 template <> void MultiType::createNewValueContainer(const unsigned char& value) { this->value_ = new MT_Value<unsigned char> (value, MT_Type::UnsignedChar ); } / ** @brief Creates a new value container for the given type. */187 template <> void MultiType::createNewValueContainer(const short& value) { this->value_ = new MT_Value<short> (value, MT_Type::Short ); } / ** @brief Creates a new value container for the given type. */188 template <> void MultiType::createNewValueContainer(const unsigned short& value) { this->value_ = new MT_Value<unsigned short> (value, MT_Type::UnsignedShort ); } / ** @brief Creates a new value container for the given type. */189 template <> void MultiType::createNewValueContainer(const int& value) { this->value_ = new MT_Value<int> (value, MT_Type::Int ); } / ** @brief Creates a new value container for the given type. */190 template <> void MultiType::createNewValueContainer(const unsigned int& value) { this->value_ = new MT_Value<unsigned int> (value, MT_Type::UnsignedInt ); } / ** @brief Creates a new value container for the given type. */191 template <> void MultiType::createNewValueContainer(const long& value) { this->value_ = new MT_Value<long> (value, MT_Type::Long ); } / ** @brief Creates a new value container for the given type. */192 template <> void MultiType::createNewValueContainer(const unsigned long& value) { this->value_ = new MT_Value<unsigned long> (value, MT_Type::UnsignedLong ); } / ** @brief Creates a new value container for the given type. */193 template <> void MultiType::createNewValueContainer(const long long& value) { this->value_ = new MT_Value<long long> (value, MT_Type::LongLong ); } / ** @brief Creates a new value container for the given type. */194 template <> void MultiType::createNewValueContainer(const unsigned long long& value) { this->value_ = new MT_Value<unsigned long long> (value, MT_Type::UnsignedLongLong); } / ** @brief Creates a new value container for the given type. */195 template <> void MultiType::createNewValueContainer(const float& value) { this->value_ = new MT_Value<float> (value, MT_Type::Float ); } / ** @brief Creates a new value container for the given type. */196 template <> void MultiType::createNewValueContainer(const double& value) { this->value_ = new MT_Value<double> (value, MT_Type::Double ); } / ** @brief Creates a new value container for the given type. */197 template <> void MultiType::createNewValueContainer(const long double& value) { this->value_ = new MT_Value<long double> (value, MT_Type::LongDouble ); } / ** @brief Creates a new value container for the given type. */198 template <> void MultiType::createNewValueContainer(const bool& value) { this->value_ = new MT_Value<bool> (value, MT_Type::Bool ); } / ** @brief Creates a new value container for the given type. */199 template <> void MultiType::createNewValueContainer( void* const& value) { this->value_ = new MT_Value<void*> (value, MT_Type::VoidPointer ); } / ** @brief Creates a new value container for the given type. */200 template <> void MultiType::createNewValueContainer(const std::string& value) { this->value_ = new MT_Value<std::string> (value, MT_Type::String ); } / ** @brief Creates a new value container for the given type. */201 template <> void MultiType::createNewValueContainer(const orxonox::Vector2& value) { this->value_ = new MT_Value<orxonox::Vector2> (value, MT_Type::Vector2 ); } / ** @brief Creates a new value container for the given type. */202 template <> void MultiType::createNewValueContainer(const orxonox::Vector3& value) { this->value_ = new MT_Value<orxonox::Vector3> (value, MT_Type::Vector3 ); } / ** @brief Creates a new value container for the given type. */203 template <> void MultiType::createNewValueContainer(const orxonox::Vector4& value) { this->value_ = new MT_Value<orxonox::Vector4> (value, MT_Type::Vector4 ); } / ** @brief Creates a new value container for the given type. */204 template <> void MultiType::createNewValueContainer(const orxonox::ColourValue& value) { this->value_ = new MT_Value<orxonox::ColourValue>(value, MT_Type::ColourValue ); } / ** @brief Creates a new value container for the given type. */205 template <> void MultiType::createNewValueContainer(const orxonox::Quaternion& value) { this->value_ = new MT_Value<orxonox::Quaternion> (value, MT_Type::Quaternion ); } / ** @brief Creates a new value container for the given type. */206 template <> void MultiType::createNewValueContainer(const orxonox::Radian& value) { this->value_ = new MT_Value<orxonox::Radian> (value, MT_Type::Radian ); } / ** @brief Creates a new value container for the given type. */207 template <> void MultiType::createNewValueContainer(const orxonox::Degree& value) { this->value_ = new MT_Value<orxonox::Degree> (value, MT_Type::Degree ); } / ** @brief Creates a new value container for the given type. */161 MultiType::operator char() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Char ) ? (static_cast<MT_Value<char> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 162 MultiType::operator unsigned char() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedChar ) ? (static_cast<MT_Value<unsigned char> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 163 MultiType::operator short() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Short ) ? (static_cast<MT_Value<short> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 164 MultiType::operator unsigned short() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedShort ) ? (static_cast<MT_Value<unsigned short> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 165 MultiType::operator int() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Int ) ? (static_cast<MT_Value<int> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 166 MultiType::operator unsigned int() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedInt ) ? (static_cast<MT_Value<unsigned int> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 167 MultiType::operator long() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Long ) ? (static_cast<MT_Value<long> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 168 MultiType::operator unsigned long() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedLong ) ? (static_cast<MT_Value<unsigned long> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 169 MultiType::operator long long() const { return (this->value_) ? ((this->value_->type_ == MT_Type::LongLong ) ? (static_cast<MT_Value<long long> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 170 MultiType::operator unsigned long long() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedLongLong) ? (static_cast<MT_Value<unsigned long long> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 171 MultiType::operator float() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Float ) ? (static_cast<MT_Value<float> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 172 MultiType::operator double() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Double ) ? (static_cast<MT_Value<double> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 173 MultiType::operator long double() const { return (this->value_) ? ((this->value_->type_ == MT_Type::LongDouble ) ? (static_cast<MT_Value<long double> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 174 MultiType::operator bool() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Bool ) ? (static_cast<MT_Value<bool> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 175 MultiType::operator void*() const { return (this->value_) ? ((this->value_->type_ == MT_Type::VoidPointer ) ? (static_cast<MT_Value<void*> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 176 MultiType::operator std::string() const { return (this->value_) ? ((this->value_->type_ == MT_Type::String ) ? (static_cast<MT_Value<std::string> *>(this->value_))->value_ : (*this->value_)) : NilValue<std::string>(); } ///< Returns the current value, converted to the requested type. 177 MultiType::operator orxonox::Vector2() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Vector2 ) ? (static_cast<MT_Value<orxonox::Vector2> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Vector2>(); } ///< Returns the current value, converted to the requested type. 178 MultiType::operator orxonox::Vector3() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Vector3 ) ? (static_cast<MT_Value<orxonox::Vector3> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Vector3>(); } ///< Returns the current value, converted to the requested type. 179 MultiType::operator orxonox::Vector4() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Vector4 ) ? (static_cast<MT_Value<orxonox::Vector4> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Vector4>(); } ///< Returns the current value, converted to the requested type. 180 MultiType::operator orxonox::ColourValue() const { return (this->value_) ? ((this->value_->type_ == MT_Type::ColourValue ) ? (static_cast<MT_Value<orxonox::ColourValue>*>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::ColourValue>(); } ///< Returns the current value, converted to the requested type. 181 MultiType::operator orxonox::Quaternion() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Quaternion ) ? (static_cast<MT_Value<orxonox::Quaternion> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Quaternion>(); } ///< Returns the current value, converted to the requested type. 182 MultiType::operator orxonox::Radian() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Radian ) ? (static_cast<MT_Value<orxonox::Radian> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Radian>(); } ///< Returns the current value, converted to the requested type. 183 MultiType::operator orxonox::Degree() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Degree ) ? (static_cast<MT_Value<orxonox::Degree> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Degree>(); } ///< Returns the current value, converted to the requested type. 184 185 template <> void MultiType::createNewValueContainer(const char& value) { this->value_ = new MT_Value<char> (value, MT_Type::Char ); } ///< Creates a new value container for the given type. 186 template <> void MultiType::createNewValueContainer(const unsigned char& value) { this->value_ = new MT_Value<unsigned char> (value, MT_Type::UnsignedChar ); } ///< Creates a new value container for the given type. 187 template <> void MultiType::createNewValueContainer(const short& value) { this->value_ = new MT_Value<short> (value, MT_Type::Short ); } ///< Creates a new value container for the given type. 188 template <> void MultiType::createNewValueContainer(const unsigned short& value) { this->value_ = new MT_Value<unsigned short> (value, MT_Type::UnsignedShort ); } ///< Creates a new value container for the given type. 189 template <> void MultiType::createNewValueContainer(const int& value) { this->value_ = new MT_Value<int> (value, MT_Type::Int ); } ///< Creates a new value container for the given type. 190 template <> void MultiType::createNewValueContainer(const unsigned int& value) { this->value_ = new MT_Value<unsigned int> (value, MT_Type::UnsignedInt ); } ///< Creates a new value container for the given type. 191 template <> void MultiType::createNewValueContainer(const long& value) { this->value_ = new MT_Value<long> (value, MT_Type::Long ); } ///< Creates a new value container for the given type. 192 template <> void MultiType::createNewValueContainer(const unsigned long& value) { this->value_ = new MT_Value<unsigned long> (value, MT_Type::UnsignedLong ); } ///< Creates a new value container for the given type. 193 template <> void MultiType::createNewValueContainer(const long long& value) { this->value_ = new MT_Value<long long> (value, MT_Type::LongLong ); } ///< Creates a new value container for the given type. 194 template <> void MultiType::createNewValueContainer(const unsigned long long& value) { this->value_ = new MT_Value<unsigned long long> (value, MT_Type::UnsignedLongLong); } ///< Creates a new value container for the given type. 195 template <> void MultiType::createNewValueContainer(const float& value) { this->value_ = new MT_Value<float> (value, MT_Type::Float ); } ///< Creates a new value container for the given type. 196 template <> void MultiType::createNewValueContainer(const double& value) { this->value_ = new MT_Value<double> (value, MT_Type::Double ); } ///< Creates a new value container for the given type. 197 template <> void MultiType::createNewValueContainer(const long double& value) { this->value_ = new MT_Value<long double> (value, MT_Type::LongDouble ); } ///< Creates a new value container for the given type. 198 template <> void MultiType::createNewValueContainer(const bool& value) { this->value_ = new MT_Value<bool> (value, MT_Type::Bool ); } ///< Creates a new value container for the given type. 199 template <> void MultiType::createNewValueContainer( void* const& value) { this->value_ = new MT_Value<void*> (value, MT_Type::VoidPointer ); } ///< Creates a new value container for the given type. 200 template <> void MultiType::createNewValueContainer(const std::string& value) { this->value_ = new MT_Value<std::string> (value, MT_Type::String ); } ///< Creates a new value container for the given type. 201 template <> void MultiType::createNewValueContainer(const orxonox::Vector2& value) { this->value_ = new MT_Value<orxonox::Vector2> (value, MT_Type::Vector2 ); } ///< Creates a new value container for the given type. 202 template <> void MultiType::createNewValueContainer(const orxonox::Vector3& value) { this->value_ = new MT_Value<orxonox::Vector3> (value, MT_Type::Vector3 ); } ///< Creates a new value container for the given type. 203 template <> void MultiType::createNewValueContainer(const orxonox::Vector4& value) { this->value_ = new MT_Value<orxonox::Vector4> (value, MT_Type::Vector4 ); } ///< Creates a new value container for the given type. 204 template <> void MultiType::createNewValueContainer(const orxonox::ColourValue& value) { this->value_ = new MT_Value<orxonox::ColourValue>(value, MT_Type::ColourValue ); } ///< Creates a new value container for the given type. 205 template <> void MultiType::createNewValueContainer(const orxonox::Quaternion& value) { this->value_ = new MT_Value<orxonox::Quaternion> (value, MT_Type::Quaternion ); } ///< Creates a new value container for the given type. 206 template <> void MultiType::createNewValueContainer(const orxonox::Radian& value) { this->value_ = new MT_Value<orxonox::Radian> (value, MT_Type::Radian ); } ///< Creates a new value container for the given type. 207 template <> void MultiType::createNewValueContainer(const orxonox::Degree& value) { this->value_ = new MT_Value<orxonox::Degree> (value, MT_Type::Degree ); } ///< Creates a new value container for the given type. 208 208 } -
code/trunk/src/libraries/util/MultiType.h
r7284 r7401 28 28 29 29 /** 30 @defgroup MultiType MultiType 31 @ingroup Util 32 */ 33 34 /** 30 35 @file 36 @ingroup MultiType 31 37 @brief Declaration of the MultiType and some helper constructs. 32 38 39 @anchor MultiTypeExamples 40 33 41 The MultiType can hold a value of one of the following types: 34 - all primitives 35 - all pointers 36 - st ring42 - all primitives (int, float, bool, etc.) 43 - all pointers (void* and T*) 44 - std::string 37 45 - Vector2, Vector3, Vector4 38 46 - Quaternion … … 40 48 - Radian, Degree 41 49 42 The MultiType has a "type" determined by the first assigned value, either through 43 - the constructor, 44 - the assignment operator= or 45 - setValue(value). 46 If you assign another value of another type, the MultiType keeps "it's" type and 47 converts the new value to this type. 50 The MultiType has an internal "type" determined by the first assigned value, using one of these ways: 51 - @ref orxonox::MultiType::MultiType "The constructor" 52 - The assignment operator= (orxonox::MultiType::operator=()) 53 - @ref orxonox::MultiType::setValue() "setValue(value)" 54 55 If you assign another value of another type, the MultiType keeps "its" type and 56 converts the new value to the old type. 48 57 49 58 If you want to change the type, there are three possibilities: 50 - convert<T>() set's the type to T and converts the currently assigned value51 - setType<T>() set's the type to T and resets the value59 - @ref orxonox::MultiType::convert "convert<T>()" sets the type to T and converts the currently assigned value 60 - @ref orxonox::MultiType::setType "setType<T>()" sets the type to T and resets the value to zero using zeroise<T>() 52 61 - setValue<T>(value) assigns a new value and changes the type to T. 53 62 54 @example 55 MultiType a = 10;; // a has now the type int and the value 10 63 Examples: 64 @code 65 MultiType a = 10; // a has now the type int and the value 10 56 66 a.setValue("3.14"); // a has still the type int and "3.14" gets converted, therefore the value is now 3 57 a.setValue<float>("3.14"); // a has now the type float and "3.14" gets converted to 3.14 58 a.convert<bool>(); // converts 3.14 to bool, which is true67 a.setValue<float>("3.14"); // a has now the type float and "3.14" gets converted to 3.14f 68 a.convert<bool>(); // converts 3.14f to bool, which is true 59 69 a = false; // assigns false, this is equivalent to a.setValue(false) 70 @endcode 71 72 You can pass a MultiType to a function as an argument, even if the argument is 73 not of type MultiType. This works, because the MultiType is automatically converted 74 to the right type. 75 76 Example: 77 @code 78 void myfunction(int value) 79 { 80 COUT(0) << "doubled value is " << (2 * value) << std::endl; 81 } 82 83 MultiType a = "50"; // Note: We assigned a string 84 myfunction(a); // a is converted to int and passed to the function, which prints "value is 100" 85 @endcode 86 87 Note however that it is of course quite expensive to convert values, especially std::string <-> value. 88 So if you can, always assign a value with the right type to avoid conversion. 60 89 61 90 @note … … 127 156 - Radian, Degree 128 157 129 The internal type of a MultiType is determined by the first assigned value, but can be 130 changed by using setType<T>(), convert<T>() or setValue<T>(value). If a value gets assigned 131 the normal way (operator=, setValue(value)), the value gets converted to the current internal 132 type of the MultiType. 158 For more information and some examples see the description @ref MultiTypeExamples "here". 159 160 @see MultiType.h 133 161 */ 134 162 class _UtilExport MultiType … … 153 181 virtual bool assimilate(const MultiType& other) = 0; 154 182 155 / ** @brief Returns the type of the current value. */183 /// Returns the type of the current value. 156 184 const MT_Type::Value& getType() const { return this->type_; } 157 185 158 / ** @brief Checks whether the value is a default one. */186 /// Checks whether the value is a default one. 159 187 bool hasDefaultValue() const { return this->bHasDefaultValue_; } 160 188 … … 237 265 virtual uint8_t getSize() const=0; 238 266 239 MT_Type::Value type_; // !< The type of the current value240 bool bHasDefaultValue_; // !< True if the last conversion wasn't successful267 MT_Type::Value type_; ///< The type of the current value 268 bool bHasDefaultValue_; ///< True if the last conversion wasn't successful 241 269 }; 242 270 243 271 public: 244 inline MultiType() : value_(0) {} / ** @brief Default constructor: Assigns no value and no type. The type will be determined by the first assignment of a value. */245 inline MultiType(const char& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */246 inline MultiType(const unsigned char& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */247 inline MultiType(const short& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */248 inline MultiType(const unsigned short& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */249 inline MultiType(const int& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */250 inline MultiType(const unsigned int& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */251 inline MultiType(const long& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */252 inline MultiType(const unsigned long& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */253 inline MultiType(const long long& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */254 inline MultiType(const unsigned long long& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */255 inline MultiType(const float& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */256 inline MultiType(const double& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */257 inline MultiType(const long double& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */258 inline MultiType(const bool& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */259 inline MultiType( void* const& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */260 inline MultiType(const std::string& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */261 inline MultiType(const orxonox::Vector2& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */262 inline MultiType(const orxonox::Vector3& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */263 inline MultiType(const orxonox::Vector4& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */264 inline MultiType(const orxonox::ColourValue& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */265 inline MultiType(const orxonox::Quaternion& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */266 inline MultiType(const orxonox::Radian& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */267 inline MultiType(const orxonox::Degree& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */268 inline MultiType(const orxonox::mbool& value) : value_(0) { this->assignValue((bool)value); } / ** @brief Constructor: Assigns the given mbool and converts it to bool. */269 inline MultiType(const char* value) : value_(0) { this->setValue(std::string(value)); } / ** @brief Constructor: Converts the char array to a std::string, assigns the value and sets the type. */270 inline MultiType(const MultiType& other) : value_(0) { this->setValue(other); } / ** @brief Copyconstructor: Assigns value and type of the other MultiType. */271 inline MultiType(MT_Type::Value type) : value_(0) { this->setType(type); } / ** @brief Constructor: Sets the type, the next assignment will determine the value. */272 273 / ** @brief Destructor: Deletes the MT_Value. */272 inline MultiType() : value_(0) {} ///< Default constructor: Assigns no value and no type. The type will be determined by the first assignment of a value. 273 inline MultiType(const char& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 274 inline MultiType(const unsigned char& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 275 inline MultiType(const short& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 276 inline MultiType(const unsigned short& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 277 inline MultiType(const int& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 278 inline MultiType(const unsigned int& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 279 inline MultiType(const long& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 280 inline MultiType(const unsigned long& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 281 inline MultiType(const long long& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 282 inline MultiType(const unsigned long long& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 283 inline MultiType(const float& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 284 inline MultiType(const double& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 285 inline MultiType(const long double& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 286 inline MultiType(const bool& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 287 inline MultiType( void* const& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 288 inline MultiType(const std::string& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 289 inline MultiType(const orxonox::Vector2& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 290 inline MultiType(const orxonox::Vector3& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 291 inline MultiType(const orxonox::Vector4& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 292 inline MultiType(const orxonox::ColourValue& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 293 inline MultiType(const orxonox::Quaternion& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 294 inline MultiType(const orxonox::Radian& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 295 inline MultiType(const orxonox::Degree& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 296 inline MultiType(const orxonox::mbool& value) : value_(0) { this->assignValue((bool)value); } ///< Constructor: Assigns the given mbool and converts it to bool. 297 inline MultiType(const char* value) : value_(0) { this->setValue(std::string(value)); } ///< Constructor: Converts the char array to a std::string, assigns the value and sets the type. 298 inline MultiType(const MultiType& other) : value_(0) { this->setValue(other); } ///< Copyconstructor: Assigns value and type of the other MultiType. 299 inline MultiType(MT_Type::Value type) : value_(0) { this->setType(type); } ///< Constructor: Sets the type, the next assignment will determine the value. 300 301 /// Destructor: Deletes the MT_Value. 274 302 inline ~MultiType() { if (this->value_) { delete this->value_; } } 275 303 276 template <typename V> inline MultiType& operator=(const V& value) { this->setValue(value); return (*this); } / ** @brief Assigns a new value. The value will be converted to the current type of the MultiType. */277 template <typename V> inline MultiType& operator=(V* value) { this->setValue(value); return (*this); } / ** @brief Assigns a pointer. */278 inline MultiType& operator=(const MultiType& other) { this->setValue(other); return (*this); } / ** @brief Assigns the value of the other MultiType and converts it to the current type of the MultiType. */279 inline MultiType& operator=(MT_Type::Value type) { this->setType(type); return (*this); } / ** @brief Resets the value and changes the type. */304 template <typename V> inline MultiType& operator=(const V& value) { this->setValue(value); return (*this); } ///< Assigns a new value. The value will be converted to the current type of the MultiType. 305 template <typename V> inline MultiType& operator=(V* value) { this->setValue(value); return (*this); } ///< Assigns a pointer. 306 inline MultiType& operator=(const MultiType& other) { this->setValue(other); return (*this); } ///< Assigns the value of the other MultiType and converts it to the current type of the MultiType. 307 inline MultiType& operator=(MT_Type::Value type) { this->setType(type); return (*this); } ///< Resets the value and changes the type. 280 308 281 309 inline bool setValue(const char& value); … … 303 331 inline bool setValue(const orxonox::Degree& value); 304 332 inline bool setValue(const char* value); 305 / ** @brief Assigns a pointer. */333 /// Assigns a pointer. 306 334 template <typename V> inline bool setValue(V* value) 307 335 { … … 311 339 return this->assignValue (static_cast<void*>(const_cast<typename Loki::TypeTraits<V>::UnqualifiedType*>(value))); 312 340 } 313 / ** @brief Assigns the value of the other MultiType and converts it to the current type. */341 /// Assigns the value of the other MultiType and converts it to the current type. 314 342 bool setValue(const MultiType& other) { if (this->value_) { return this->value_->assimilate(other); } else { if (other.value_) { this->value_ = other.value_->clone(); } return true; } } 315 / ** @brief Changes the type to T and assigns the new value (which might be of another type than T - it gets converted). */343 /// Changes the type to T and assigns the new value (which might be of another type than T - it gets converted). 316 344 template <typename T, typename V> inline bool setValue(const V& value) { this->setType<T>(); return this->setValue(value); } 317 345 318 346 319 / ** @brief Copies the other MultiType by assigning value and type. */347 /// Copies the other MultiType by assigning value and type. 320 348 inline void copy(const MultiType& other) { if (this == &other) { return; } if (this->value_) { delete this->value_; } this->value_ = (other.value_) ? other.value_->clone() : 0; } 321 349 322 template <typename T> inline bool convert() { return this->setValue<T>((typename Loki::TypeTraits<T>::UnqualifiedReferredType)(*this)); } /** @brief Converts the current value to type T. */ 323 inline bool convert(const MultiType& other) { return this->convert(other.getType()); } /** @brief Converts the current value to the type of the other MultiType. */ 350 /// Converts the current value to type T. 351 template <typename T> inline bool convert() { return this->setValue<T>((typename Loki::TypeTraits<T>::UnqualifiedReferredType)(*this)); } 352 /// Converts the current value to the type of the other MultiType. 353 inline bool convert(const MultiType& other) { return this->convert(other.getType()); } 324 354 bool convert(MT_Type::Value type); 325 355 326 / ** @brief Current content gets deleted. New type is MT_Type::Null */356 /// Current content gets deleted. New type is MT_Type::Null 327 357 inline void reset() { if (this->value_) delete this->value_; this->value_ = 0; } 328 / ** @brief Current content gets overridden with default zero value */358 /// Current content gets overridden with default zero value 329 359 inline void resetValue() { if (this->value_) this->value_->reset(); } 330 360 331 template <typename T> inline void setType() { this->assignValue(typename Loki::TypeTraits<T>::UnqualifiedReferredType()); } /** @brief Resets the value and changes the internal type to T. */ 332 inline void setType(const MultiType& other) { this->setType(other.getType()); } /** @brief Resets the value and changes the internal type to the type of the other MultiType. */ 333 inline void setType(MT_Type::Value type) { this->reset(); this->convert(type); this->resetValue(); } /** @brief Resets the value and changes the internal type to the given type. */ 334 335 /** @brief Returns the current type. */ 361 /// Resets the value and changes the internal type to T. 362 template <typename T> inline void setType() { this->assignValue(typename Loki::TypeTraits<T>::UnqualifiedReferredType()); } 363 /// Resets the value and changes the internal type to the type of the other MultiType. 364 inline void setType(const MultiType& other) { this->setType(other.getType()); } 365 /// Resets the value and changes the internal type to the given type. 366 inline void setType(MT_Type::Value type) { this->reset(); this->convert(type); this->resetValue(); } 367 368 /// Returns the current type. 336 369 inline MT_Type::Value getType() const { return (this->value_) ? this->value_->type_ : MT_Type::Null; } 337 / ** @brief Returns true if the current type equals the given type. */370 /// Returns true if the current type equals the given type. 338 371 inline bool isType(MT_Type::Value type) const { return (this->value_) ? (this->value_->type_ == type) : (type == MT_Type::Null); } 339 / ** @brief Returns true if the current type is T. */372 /// Returns true if the current type is T. 340 373 template <typename T> inline bool isType() const { return false; } // Only works for specialized values - see below 341 374 std::string getTypename() const; 342 375 343 / ** @brief Saves the value of the MT to a bytestream (pointed at by mem) and increases mem pointer by size of MT */376 /// Saves the value of the MT to a bytestream (pointed at by mem) and increases mem pointer by size of MT 344 377 inline void exportData(uint8_t*& mem) const { assert(sizeof(MT_Type::Value)<=8); *static_cast<uint8_t*>(mem) = this->getType(); mem+=sizeof(uint8_t); this->value_->exportData(mem); } 345 / ** @brief Loads the value of the MT from a bytestream (pointed at by mem) and increases mem pointer by size of MT */378 /// Loads the value of the MT from a bytestream (pointed at by mem) and increases mem pointer by size of MT 346 379 inline void importData(uint8_t*& mem) { assert(sizeof(MT_Type::Value)<=8); this->setType(static_cast<MT_Type::Value>(*static_cast<uint8_t*>(mem))); mem+=sizeof(uint8_t); this->value_->importData(mem); } 347 / ** @brief Saves the value of the MT to a bytestream and increases pointer to bytestream by size of MT */380 /// Saves the value of the MT to a bytestream and increases pointer to bytestream by size of MT 348 381 inline uint8_t*& operator << (uint8_t*& mem) { importData(mem); return mem; } 349 / ** @brief Loads the value of the MT to a bytestream and increases pointer to bytestream by size of MT */382 /// Loads the value of the MT to a bytestream and increases pointer to bytestream by size of MT 350 383 inline void operator >> (uint8_t*& mem) const { exportData(mem); } 351 384 inline uint32_t getNetworkSize() const { assert(this->value_); return this->value_->getSize() + sizeof(uint8_t); } 352 385 353 / ** @brief Checks whether the value is a default one. */386 /// Checks whether the value is a default one (assigned after a failed conversion) 354 387 bool hasDefaultValue() const { return this->value_->hasDefaultValue(); } 355 388 356 / ** @brief Checks if the MT contains no value. */389 /// Checks if the MT contains no value. 357 390 bool null() const { return (!this->value_); } 358 391 … … 380 413 operator orxonox::Radian() const; 381 414 operator orxonox::Degree() const; 382 / ** @brief Returns the current value, converted to a T* pointer. */415 /// Returns the current value, converted to a T* pointer. 383 416 template <class T> operator T*() const { return (static_cast<T*>(this->operator void*())); } 384 417 385 inline bool getValue(char* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */386 inline bool getValue(unsigned char* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */387 inline bool getValue(short* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */388 inline bool getValue(unsigned short* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */389 inline bool getValue(int* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */390 inline bool getValue(unsigned int* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */391 inline bool getValue(long* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */392 inline bool getValue(unsigned long* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */393 inline bool getValue(long long* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */394 inline bool getValue(unsigned long long* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */395 inline bool getValue(float* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */396 inline bool getValue(double* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */397 inline bool getValue(long double* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */398 inline bool getValue(bool* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */399 inline bool getValue(void** value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */400 inline bool getValue(std::string* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */401 inline bool getValue(orxonox::Vector2* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */402 inline bool getValue(orxonox::Vector3* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */403 inline bool getValue(orxonox::Vector4* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */404 inline bool getValue(orxonox::ColourValue* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */405 inline bool getValue(orxonox::Quaternion* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */406 inline bool getValue(orxonox::Radian* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */407 inline bool getValue(orxonox::Degree* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */408 409 inline char getChar() const { return this->operator char(); } / ** @brief Returns the current value, converted to the requested type. */410 inline unsigned char getUnsignedChar() const { return this->operator unsigned char(); } / ** @brief Returns the current value, converted to the requested type. */411 inline short getShort() const { return this->operator short(); } / ** @brief Returns the current value, converted to the requested type. */412 inline unsigned short getUnsignedShort() const { return this->operator unsigned short(); } / ** @brief Returns the current value, converted to the requested type. */413 inline int getInt() const { return this->operator int(); } / ** @brief Returns the current value, converted to the requested type. */414 inline unsigned int getUnsignedInt() const { return this->operator unsigned int(); } / ** @brief Returns the current value, converted to the requested type. */415 inline long getLong() const { return this->operator long(); } / ** @brief Returns the current value, converted to the requested type. */416 inline unsigned long getUnsignedLong() const { return this->operator unsigned long(); } / ** @brief Returns the current value, converted to the requested type. */417 inline long long getLongLong() const { return this->operator long long(); } / ** @brief Returns the current value, converted to the requested type. */418 inline unsigned long long getUnsignedLongLong() const { return this->operator unsigned long long(); } / ** @brief Returns the current value, converted to the requested type. */419 inline float getFloat() const { return this->operator float(); } / ** @brief Returns the current value, converted to the requested type. */420 inline double getDouble() const { return this->operator double(); } / ** @brief Returns the current value, converted to the requested type. */421 inline long double getLongDouble() const { return this->operator long double(); } / ** @brief Returns the current value, converted to the requested type. */422 inline bool getBool() const { return this->operator bool(); } / ** @brief Returns the current value, converted to the requested type. */423 inline void* getVoid() const { return this->operator void*(); } / ** @brief Returns the current value, converted to the requested type. */424 inline std::string getString() const { return this->operator std::string(); } / ** @brief Returns the current value, converted to the requested type. */425 inline orxonox::Vector2 getVector2() const { return this->operator orxonox::Vector2(); } / ** @brief Returns the current value, converted to the requested type. */426 inline orxonox::Vector3 getVector3() const { return this->operator orxonox::Vector3(); } / ** @brief Returns the current value, converted to the requested type. */427 inline orxonox::Vector4 getVector4() const { return this->operator orxonox::Vector4(); } / ** @brief Returns the current value, converted to the requested type. */428 inline orxonox::ColourValue getColourValue() const { return this->operator orxonox::ColourValue(); } / ** @brief Returns the current value, converted to the requested type. */429 inline orxonox::Quaternion getQuaternion() const { return this->operator orxonox::Quaternion(); } / ** @brief Returns the current value, converted to the requested type. */430 inline orxonox::Radian getRadian() const { return this->operator orxonox::Radian(); } / ** @brief Returns the current value, converted to the requested type. */431 inline orxonox::Degree getDegree() const { return this->operator orxonox::Degree(); } / ** @brief Returns the current value, converted to the requested type. */432 template <typename T> inline T* getPointer() const { return static_cast<T*>(this->getVoid()); } / ** @brief Returns the current value, converted to a T* pointer. */418 inline bool getValue(char* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 419 inline bool getValue(unsigned char* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 420 inline bool getValue(short* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 421 inline bool getValue(unsigned short* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 422 inline bool getValue(int* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 423 inline bool getValue(unsigned int* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 424 inline bool getValue(long* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 425 inline bool getValue(unsigned long* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 426 inline bool getValue(long long* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 427 inline bool getValue(unsigned long long* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 428 inline bool getValue(float* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 429 inline bool getValue(double* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 430 inline bool getValue(long double* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 431 inline bool getValue(bool* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 432 inline bool getValue(void** value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 433 inline bool getValue(std::string* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 434 inline bool getValue(orxonox::Vector2* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 435 inline bool getValue(orxonox::Vector3* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 436 inline bool getValue(orxonox::Vector4* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 437 inline bool getValue(orxonox::ColourValue* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 438 inline bool getValue(orxonox::Quaternion* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 439 inline bool getValue(orxonox::Radian* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 440 inline bool getValue(orxonox::Degree* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 441 442 inline char getChar() const { return this->operator char(); } ///< Returns the current value, converted to the requested type. 443 inline unsigned char getUnsignedChar() const { return this->operator unsigned char(); } ///< Returns the current value, converted to the requested type. 444 inline short getShort() const { return this->operator short(); } ///< Returns the current value, converted to the requested type. 445 inline unsigned short getUnsignedShort() const { return this->operator unsigned short(); } ///< Returns the current value, converted to the requested type. 446 inline int getInt() const { return this->operator int(); } ///< Returns the current value, converted to the requested type. 447 inline unsigned int getUnsignedInt() const { return this->operator unsigned int(); } ///< Returns the current value, converted to the requested type. 448 inline long getLong() const { return this->operator long(); } ///< Returns the current value, converted to the requested type. 449 inline unsigned long getUnsignedLong() const { return this->operator unsigned long(); } ///< Returns the current value, converted to the requested type. 450 inline long long getLongLong() const { return this->operator long long(); } ///< Returns the current value, converted to the requested type. 451 inline unsigned long long getUnsignedLongLong() const { return this->operator unsigned long long(); } ///< Returns the current value, converted to the requested type. 452 inline float getFloat() const { return this->operator float(); } ///< Returns the current value, converted to the requested type. 453 inline double getDouble() const { return this->operator double(); } ///< Returns the current value, converted to the requested type. 454 inline long double getLongDouble() const { return this->operator long double(); } ///< Returns the current value, converted to the requested type. 455 inline bool getBool() const { return this->operator bool(); } ///< Returns the current value, converted to the requested type. 456 inline void* getVoid() const { return this->operator void*(); } ///< Returns the current value, converted to the requested type. 457 inline std::string getString() const { return this->operator std::string(); } ///< Returns the current value, converted to the requested type. 458 inline orxonox::Vector2 getVector2() const { return this->operator orxonox::Vector2(); } ///< Returns the current value, converted to the requested type. 459 inline orxonox::Vector3 getVector3() const { return this->operator orxonox::Vector3(); } ///< Returns the current value, converted to the requested type. 460 inline orxonox::Vector4 getVector4() const { return this->operator orxonox::Vector4(); } ///< Returns the current value, converted to the requested type. 461 inline orxonox::ColourValue getColourValue() const { return this->operator orxonox::ColourValue(); } ///< Returns the current value, converted to the requested type. 462 inline orxonox::Quaternion getQuaternion() const { return this->operator orxonox::Quaternion(); } ///< Returns the current value, converted to the requested type. 463 inline orxonox::Radian getRadian() const { return this->operator orxonox::Radian(); } ///< Returns the current value, converted to the requested type. 464 inline orxonox::Degree getDegree() const { return this->operator orxonox::Degree(); } ///< Returns the current value, converted to the requested type. 465 template <typename T> inline T* getPointer() const { return static_cast<T*>(this->getVoid()); } ///< Returns the current value, converted to a T* pointer. 433 466 434 467 private: 435 inline bool assignValue(const char& value) { if (this->value_ && this->value_->type_ == MT_Type::Char) { return this->value_->setValue(value); } else { this->changeValueContainer<char>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */436 inline bool assignValue(const unsigned char& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedChar) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned char>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */437 inline bool assignValue(const short& value) { if (this->value_ && this->value_->type_ == MT_Type::Short) { return this->value_->setValue(value); } else { this->changeValueContainer<short>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */438 inline bool assignValue(const unsigned short& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedShort) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned short>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */439 inline bool assignValue(const int& value) { if (this->value_ && this->value_->type_ == MT_Type::Int) { return this->value_->setValue(value); } else { this->changeValueContainer<int>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */440 inline bool assignValue(const unsigned int& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedInt) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned int>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */441 inline bool assignValue(const long& value) { if (this->value_ && this->value_->type_ == MT_Type::Long) { return this->value_->setValue(value); } else { this->changeValueContainer<long>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */442 inline bool assignValue(const unsigned long& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedLong) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned long>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */443 inline bool assignValue(const long long& value) { if (this->value_ && this->value_->type_ == MT_Type::LongLong) { return this->value_->setValue(value); } else { this->changeValueContainer<long long>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */444 inline bool assignValue(const unsigned long long& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedLongLong) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned long long>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */445 inline bool assignValue(const float& value) { if (this->value_ && this->value_->type_ == MT_Type::Float) { return this->value_->setValue(value); } else { this->changeValueContainer<float>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */446 inline bool assignValue(const double& value) { if (this->value_ && this->value_->type_ == MT_Type::Double) { return this->value_->setValue(value); } else { this->changeValueContainer<double>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */447 inline bool assignValue(const long double& value) { if (this->value_ && this->value_->type_ == MT_Type::LongDouble) { return this->value_->setValue(value); } else { this->changeValueContainer<long double>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */448 inline bool assignValue(const bool& value) { if (this->value_ && this->value_->type_ == MT_Type::Bool) { return this->value_->setValue(value); } else { this->changeValueContainer<bool>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */449 inline bool assignValue( void* const& value) { if (this->value_ && this->value_->type_ == MT_Type::VoidPointer) { return this->value_->setValue(value); } else { this->changeValueContainer<void*>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */450 inline bool assignValue(const std::string& value) { if (this->value_ && this->value_->type_ == MT_Type::String) { return this->value_->setValue(value); } else { this->changeValueContainer<std::string>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */451 inline bool assignValue(const orxonox::Vector2& value) { if (this->value_ && this->value_->type_ == MT_Type::Vector2) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector2>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */452 inline bool assignValue(const orxonox::Vector3& value) { if (this->value_ && this->value_->type_ == MT_Type::Vector3) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector3>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */453 inline bool assignValue(const orxonox::Vector4& value) { if (this->value_ && this->value_->type_ == MT_Type::Vector4) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector4>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */454 inline bool assignValue(const orxonox::ColourValue& value) { if (this->value_ && this->value_->type_ == MT_Type::ColourValue) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::ColourValue>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */455 inline bool assignValue(const orxonox::Quaternion& value) { if (this->value_ && this->value_->type_ == MT_Type::Quaternion) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Quaternion>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */456 inline bool assignValue(const orxonox::Radian& value) { if (this->value_ && this->value_->type_ == MT_Type::Radian) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Radian>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */457 inline bool assignValue(const orxonox::Degree& value) { if (this->value_ && this->value_->type_ == MT_Type::Degree) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Degree>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */458 459 / ** @brief Changes the value container. */468 inline bool assignValue(const char& value) { if (this->value_ && this->value_->type_ == MT_Type::Char) { return this->value_->setValue(value); } else { this->changeValueContainer<char>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 469 inline bool assignValue(const unsigned char& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedChar) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned char>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 470 inline bool assignValue(const short& value) { if (this->value_ && this->value_->type_ == MT_Type::Short) { return this->value_->setValue(value); } else { this->changeValueContainer<short>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 471 inline bool assignValue(const unsigned short& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedShort) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned short>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 472 inline bool assignValue(const int& value) { if (this->value_ && this->value_->type_ == MT_Type::Int) { return this->value_->setValue(value); } else { this->changeValueContainer<int>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 473 inline bool assignValue(const unsigned int& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedInt) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned int>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 474 inline bool assignValue(const long& value) { if (this->value_ && this->value_->type_ == MT_Type::Long) { return this->value_->setValue(value); } else { this->changeValueContainer<long>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 475 inline bool assignValue(const unsigned long& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedLong) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned long>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 476 inline bool assignValue(const long long& value) { if (this->value_ && this->value_->type_ == MT_Type::LongLong) { return this->value_->setValue(value); } else { this->changeValueContainer<long long>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 477 inline bool assignValue(const unsigned long long& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedLongLong) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned long long>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 478 inline bool assignValue(const float& value) { if (this->value_ && this->value_->type_ == MT_Type::Float) { return this->value_->setValue(value); } else { this->changeValueContainer<float>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 479 inline bool assignValue(const double& value) { if (this->value_ && this->value_->type_ == MT_Type::Double) { return this->value_->setValue(value); } else { this->changeValueContainer<double>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 480 inline bool assignValue(const long double& value) { if (this->value_ && this->value_->type_ == MT_Type::LongDouble) { return this->value_->setValue(value); } else { this->changeValueContainer<long double>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 481 inline bool assignValue(const bool& value) { if (this->value_ && this->value_->type_ == MT_Type::Bool) { return this->value_->setValue(value); } else { this->changeValueContainer<bool>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 482 inline bool assignValue( void* const& value) { if (this->value_ && this->value_->type_ == MT_Type::VoidPointer) { return this->value_->setValue(value); } else { this->changeValueContainer<void*>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 483 inline bool assignValue(const std::string& value) { if (this->value_ && this->value_->type_ == MT_Type::String) { return this->value_->setValue(value); } else { this->changeValueContainer<std::string>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 484 inline bool assignValue(const orxonox::Vector2& value) { if (this->value_ && this->value_->type_ == MT_Type::Vector2) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector2>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 485 inline bool assignValue(const orxonox::Vector3& value) { if (this->value_ && this->value_->type_ == MT_Type::Vector3) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector3>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 486 inline bool assignValue(const orxonox::Vector4& value) { if (this->value_ && this->value_->type_ == MT_Type::Vector4) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector4>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 487 inline bool assignValue(const orxonox::ColourValue& value) { if (this->value_ && this->value_->type_ == MT_Type::ColourValue) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::ColourValue>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 488 inline bool assignValue(const orxonox::Quaternion& value) { if (this->value_ && this->value_->type_ == MT_Type::Quaternion) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Quaternion>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 489 inline bool assignValue(const orxonox::Radian& value) { if (this->value_ && this->value_->type_ == MT_Type::Radian) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Radian>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 490 inline bool assignValue(const orxonox::Degree& value) { if (this->value_ && this->value_->type_ == MT_Type::Degree) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Degree>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 491 492 /// Changes the value container. 460 493 template <typename T> inline void changeValueContainer(const T& value) { if (this->value_) { delete this->value_; } this->createNewValueContainer<T>(value); } 461 / ** @brief Creates a new value container (works only with specialized types). */494 /// Creates a new value container (works only with specialized types). 462 495 template <typename T> void createNewValueContainer(const T& value) { /* STATIC ASSERT */ *****value; return false; } 463 496 … … 465 498 }; 466 499 467 / ** @brief Puts the MultiType on a stream by using the native << operator of the current type. */500 /// Puts the MultiType on a stream by using the native << operator of the current type. 468 501 _UtilExport inline std::ostream& operator<<(std::ostream& outstream, const MultiType& mt) { if (mt.value_) { mt.value_->toString(outstream); } return outstream; } 469 502 470 template <> inline bool MultiType::isType<char>() const { return (this->value_ && this->value_->type_ == MT_Type::Char); } /** @brief Returns true if the current type equals the given type. */ 471 template <> inline bool MultiType::isType<unsigned char>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedChar); } /** @brief Returns true if the current type equals the given type. */ 472 template <> inline bool MultiType::isType<short>() const { return (this->value_ && this->value_->type_ == MT_Type::Short); } /** @brief Returns true if the current type equals the given type. */ 473 template <> inline bool MultiType::isType<unsigned short>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedShort); } /** @brief Returns true if the current type equals the given type. */ 474 template <> inline bool MultiType::isType<int>() const { return (this->value_ && this->value_->type_ == MT_Type::Int); } /** @brief Returns true if the current type equals the given type. */ 475 template <> inline bool MultiType::isType<unsigned int>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedInt); } /** @brief Returns true if the current type equals the given type. */ 476 template <> inline bool MultiType::isType<long>() const { return (this->value_ && this->value_->type_ == MT_Type::Long); } /** @brief Returns true if the current type equals the given type. */ 477 template <> inline bool MultiType::isType<unsigned long>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedLong); } /** @brief Returns true if the current type equals the given type. */ 478 template <> inline bool MultiType::isType<long long>() const { return (this->value_ && this->value_->type_ == MT_Type::LongLong); } /** @brief Returns true if the current type equals the given type. */ 479 template <> inline bool MultiType::isType<unsigned long long>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedLongLong); } /** @brief Returns true if the current type equals the given type. */ 480 template <> inline bool MultiType::isType<float>() const { return (this->value_ && this->value_->type_ == MT_Type::Float); } /** @brief Returns true if the current type equals the given type. */ 481 template <> inline bool MultiType::isType<double>() const { return (this->value_ && this->value_->type_ == MT_Type::Double); } /** @brief Returns true if the current type equals the given type. */ 482 template <> inline bool MultiType::isType<long double>() const { return (this->value_ && this->value_->type_ == MT_Type::LongDouble); } /** @brief Returns true if the current type equals the given type. */ 483 template <> inline bool MultiType::isType<bool>() const { return (this->value_ && this->value_->type_ == MT_Type::Bool); } /** @brief Returns true if the current type equals the given type. */ 484 template <> inline bool MultiType::isType<void*>() const { return (this->value_ && this->value_->type_ == MT_Type::VoidPointer); } /** @brief Returns true if the current type equals the given type. */ 485 template <> inline bool MultiType::isType<std::string>() const { return (this->value_ && this->value_->type_ == MT_Type::String); } /** @brief Returns true if the current type equals the given type. */ 486 template <> inline bool MultiType::isType<orxonox::Vector2>() const { return (this->value_ && this->value_->type_ == MT_Type::Vector2); } /** @brief Returns true if the current type equals the given type. */ 487 template <> inline bool MultiType::isType<orxonox::Vector3>() const { return (this->value_ && this->value_->type_ == MT_Type::Vector3); } /** @brief Returns true if the current type equals the given type. */ 488 template <> inline bool MultiType::isType<orxonox::Vector4>() const { return (this->value_ && this->value_->type_ == MT_Type::Vector4); } /** @brief Returns true if the current type equals the given type. */ 489 template <> inline bool MultiType::isType<orxonox::ColourValue>() const { return (this->value_ && this->value_->type_ == MT_Type::ColourValue); } /** @brief Returns true if the current type equals the given type. */ 490 template <> inline bool MultiType::isType<orxonox::Quaternion>() const { return (this->value_ && this->value_->type_ == MT_Type::Quaternion); } /** @brief Returns true if the current type equals the given type. */ 491 template <> inline bool MultiType::isType<orxonox::Radian>() const { return (this->value_ && this->value_->type_ == MT_Type::Radian); } /** @brief Returns true if the current type equals the given type. */ 492 template <> inline bool MultiType::isType<orxonox::Degree>() const { return (this->value_ && this->value_->type_ == MT_Type::Degree); } /** @brief Returns true if the current type equals the given type. */ 493 494 template <> inline bool MultiType::convert<void>() { this->reset(); return true; } /** @brief Deletes the content, type becomes MT_Type::Null. */ 503 template <> inline bool MultiType::isType<char>() const { return (this->value_ && this->value_->type_ == MT_Type::Char); } ///< Returns true if the current type equals the given type. 504 template <> inline bool MultiType::isType<unsigned char>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedChar); } ///< Returns true if the current type equals the given type. 505 template <> inline bool MultiType::isType<short>() const { return (this->value_ && this->value_->type_ == MT_Type::Short); } ///< Returns true if the current type equals the given type. 506 template <> inline bool MultiType::isType<unsigned short>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedShort); } ///< Returns true if the current type equals the given type. 507 template <> inline bool MultiType::isType<int>() const { return (this->value_ && this->value_->type_ == MT_Type::Int); } ///< Returns true if the current type equals the given type. 508 template <> inline bool MultiType::isType<unsigned int>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedInt); } ///< Returns true if the current type equals the given type. 509 template <> inline bool MultiType::isType<long>() const { return (this->value_ && this->value_->type_ == MT_Type::Long); } ///< Returns true if the current type equals the given type. 510 template <> inline bool MultiType::isType<unsigned long>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedLong); } ///< Returns true if the current type equals the given type. 511 template <> inline bool MultiType::isType<long long>() const { return (this->value_ && this->value_->type_ == MT_Type::LongLong); } ///< Returns true if the current type equals the given type. 512 template <> inline bool MultiType::isType<unsigned long long>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedLongLong); } ///< Returns true if the current type equals the given type. 513 template <> inline bool MultiType::isType<float>() const { return (this->value_ && this->value_->type_ == MT_Type::Float); } ///< Returns true if the current type equals the given type. 514 template <> inline bool MultiType::isType<double>() const { return (this->value_ && this->value_->type_ == MT_Type::Double); } ///< Returns true if the current type equals the given type. 515 template <> inline bool MultiType::isType<long double>() const { return (this->value_ && this->value_->type_ == MT_Type::LongDouble); } ///< Returns true if the current type equals the given type. 516 template <> inline bool MultiType::isType<bool>() const { return (this->value_ && this->value_->type_ == MT_Type::Bool); } ///< Returns true if the current type equals the given type. 517 template <> inline bool MultiType::isType<void*>() const { return (this->value_ && this->value_->type_ == MT_Type::VoidPointer); } ///< Returns true if the current type equals the given type. 518 template <> inline bool MultiType::isType<std::string>() const { return (this->value_ && this->value_->type_ == MT_Type::String); } ///< Returns true if the current type equals the given type. 519 template <> inline bool MultiType::isType<orxonox::Vector2>() const { return (this->value_ && this->value_->type_ == MT_Type::Vector2); } ///< Returns true if the current type equals the given type. 520 template <> inline bool MultiType::isType<orxonox::Vector3>() const { return (this->value_ && this->value_->type_ == MT_Type::Vector3); } ///< Returns true if the current type equals the given type. 521 template <> inline bool MultiType::isType<orxonox::Vector4>() const { return (this->value_ && this->value_->type_ == MT_Type::Vector4); } ///< Returns true if the current type equals the given type. 522 template <> inline bool MultiType::isType<orxonox::ColourValue>() const { return (this->value_ && this->value_->type_ == MT_Type::ColourValue); } ///< Returns true if the current type equals the given type. 523 template <> inline bool MultiType::isType<orxonox::Quaternion>() const { return (this->value_ && this->value_->type_ == MT_Type::Quaternion); } ///< Returns true if the current type equals the given type. 524 template <> inline bool MultiType::isType<orxonox::Radian>() const { return (this->value_ && this->value_->type_ == MT_Type::Radian); } ///< Returns true if the current type equals the given type. 525 template <> inline bool MultiType::isType<orxonox::Degree>() const { return (this->value_ && this->value_->type_ == MT_Type::Degree); } ///< Returns true if the current type equals the given type. 526 527 /// Deletes the content, type becomes MT_Type::Null. 528 template <> inline bool MultiType::convert<void>() { this->reset(); return true; } 495 529 496 530 // Specialization to avoid ambiguities with the conversion operator 497 template <> inline bool MultiType::convert<std::string>() { return this->setValue<std::string> (this->operator std::string()); } / ** @brief Converts the current value to the given type. */498 template <> inline bool MultiType::convert<orxonox::Vector2>() { return this->setValue<orxonox::Vector2> (this->operator orxonox::Vector2()); } / ** @brief Converts the current value to the given type. */499 template <> inline bool MultiType::convert<orxonox::Vector3>() { return this->setValue<orxonox::Vector3> (this->operator orxonox::Vector3()); } / ** @brief Converts the current value to the given type. */500 template <> inline bool MultiType::convert<orxonox::Vector4>() { return this->setValue<orxonox::Vector4> (this->operator orxonox::Vector4()); } / ** @brief Converts the current value to the given type. */501 template <> inline bool MultiType::convert<orxonox::ColourValue>() { return this->setValue<orxonox::ColourValue>(this->operator orxonox::ColourValue()); } / ** @brief Converts the current value to the given type. */502 template <> inline bool MultiType::convert<orxonox::Quaternion>() { return this->setValue<orxonox::Quaternion> (this->operator orxonox::Quaternion()); } / ** @brief Converts the current value to the given type. */503 template <> inline bool MultiType::convert<orxonox::Radian>() { return this->setValue<orxonox::Radian> (this->operator orxonox::Radian()); } / ** @brief Converts the current value to the given type. */504 template <> inline bool MultiType::convert<orxonox::Degree>() { return this->setValue<orxonox::Degree> (this->operator orxonox::Degree()); } / ** @brief Converts the current value to the given type. */531 template <> inline bool MultiType::convert<std::string>() { return this->setValue<std::string> (this->operator std::string()); } ///< Converts the current value to the given type. 532 template <> inline bool MultiType::convert<orxonox::Vector2>() { return this->setValue<orxonox::Vector2> (this->operator orxonox::Vector2()); } ///< Converts the current value to the given type. 533 template <> inline bool MultiType::convert<orxonox::Vector3>() { return this->setValue<orxonox::Vector3> (this->operator orxonox::Vector3()); } ///< Converts the current value to the given type. 534 template <> inline bool MultiType::convert<orxonox::Vector4>() { return this->setValue<orxonox::Vector4> (this->operator orxonox::Vector4()); } ///< Converts the current value to the given type. 535 template <> inline bool MultiType::convert<orxonox::ColourValue>() { return this->setValue<orxonox::ColourValue>(this->operator orxonox::ColourValue()); } ///< Converts the current value to the given type. 536 template <> inline bool MultiType::convert<orxonox::Quaternion>() { return this->setValue<orxonox::Quaternion> (this->operator orxonox::Quaternion()); } ///< Converts the current value to the given type. 537 template <> inline bool MultiType::convert<orxonox::Radian>() { return this->setValue<orxonox::Radian> (this->operator orxonox::Radian()); } ///< Converts the current value to the given type. 538 template <> inline bool MultiType::convert<orxonox::Degree>() { return this->setValue<orxonox::Degree> (this->operator orxonox::Degree()); } ///< Converts the current value to the given type. 505 539 506 540 // Specialization to avoid ambiguities with the conversion operator 507 template <> inline bool MultiType::convert<const std::string&>() { return this->convert<std::string>(); } / ** @brief Converts the current value to the given type. */508 template <> inline bool MultiType::convert<const orxonox::Vector2&>() { return this->convert<orxonox::Vector2>(); } / ** @brief Converts the current value to the given type. */509 template <> inline bool MultiType::convert<const orxonox::Vector3&>() { return this->convert<orxonox::Vector3>(); } / ** @brief Converts the current value to the given type. */510 template <> inline bool MultiType::convert<const orxonox::Vector4&>() { return this->convert<orxonox::Vector4>(); } / ** @brief Converts the current value to the given type. */511 template <> inline bool MultiType::convert<const orxonox::ColourValue&>() { return this->convert<orxonox::ColourValue>(); } / ** @brief Converts the current value to the given type. */512 template <> inline bool MultiType::convert<const orxonox::Quaternion&>() { return this->convert<orxonox::Quaternion>(); } / ** @brief Converts the current value to the given type. */513 template <> inline bool MultiType::convert<const orxonox::Radian&>() { return this->convert<orxonox::Radian>(); } / ** @brief Converts the current value to the given type. */514 template <> inline bool MultiType::convert<const orxonox::Degree&>() { return this->convert<orxonox::Degree>(); } / ** @brief Converts the current value to the given type. */541 template <> inline bool MultiType::convert<const std::string&>() { return this->convert<std::string>(); } ///< Converts the current value to the given type. 542 template <> inline bool MultiType::convert<const orxonox::Vector2&>() { return this->convert<orxonox::Vector2>(); } ///< Converts the current value to the given type. 543 template <> inline bool MultiType::convert<const orxonox::Vector3&>() { return this->convert<orxonox::Vector3>(); } ///< Converts the current value to the given type. 544 template <> inline bool MultiType::convert<const orxonox::Vector4&>() { return this->convert<orxonox::Vector4>(); } ///< Converts the current value to the given type. 545 template <> inline bool MultiType::convert<const orxonox::ColourValue&>() { return this->convert<orxonox::ColourValue>(); } ///< Converts the current value to the given type. 546 template <> inline bool MultiType::convert<const orxonox::Quaternion&>() { return this->convert<orxonox::Quaternion>(); } ///< Converts the current value to the given type. 547 template <> inline bool MultiType::convert<const orxonox::Radian&>() { return this->convert<orxonox::Radian>(); } ///< Converts the current value to the given type. 548 template <> inline bool MultiType::convert<const orxonox::Degree&>() { return this->convert<orxonox::Degree>(); } ///< Converts the current value to the given type. 515 549 516 550 template <> _UtilExport void MultiType::createNewValueContainer(const char& value); … … 538 572 template <> _UtilExport void MultiType::createNewValueContainer(const orxonox::Degree& value); 539 573 540 inline bool MultiType::setValue(const char& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 541 inline bool MultiType::setValue(const unsigned char& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 542 inline bool MultiType::setValue(const short& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 543 inline bool MultiType::setValue(const unsigned short& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 544 inline bool MultiType::setValue(const int& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 545 inline bool MultiType::setValue(const unsigned int& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 546 inline bool MultiType::setValue(const long& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 547 inline bool MultiType::setValue(const unsigned long& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 548 inline bool MultiType::setValue(const long long& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 549 inline bool MultiType::setValue(const unsigned long long& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 550 inline bool MultiType::setValue(const float& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 551 inline bool MultiType::setValue(const double& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 552 inline bool MultiType::setValue(const long double& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 553 inline bool MultiType::setValue(const bool& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 554 inline bool MultiType::setValue( void* const& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 555 inline bool MultiType::setValue(const std::string& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 556 inline bool MultiType::setValue(const orxonox::Vector2& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 557 inline bool MultiType::setValue(const orxonox::Vector3& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 558 inline bool MultiType::setValue(const orxonox::Vector4& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 559 inline bool MultiType::setValue(const orxonox::ColourValue& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 560 inline bool MultiType::setValue(const orxonox::Quaternion& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 561 inline bool MultiType::setValue(const orxonox::Radian& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 562 inline bool MultiType::setValue(const orxonox::Degree& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 563 564 inline bool MultiType::setValue(const char* value) { if (this->value_) { return this->value_->setValue(std::string(value)); } else { return this->assignValue(std::string(value)); } } /** @brief Assigns the given value and converts it to the current type. */ 574 inline bool MultiType::setValue(const char& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 575 inline bool MultiType::setValue(const unsigned char& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 576 inline bool MultiType::setValue(const short& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 577 inline bool MultiType::setValue(const unsigned short& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 578 inline bool MultiType::setValue(const int& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 579 inline bool MultiType::setValue(const unsigned int& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 580 inline bool MultiType::setValue(const long& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 581 inline bool MultiType::setValue(const unsigned long& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 582 inline bool MultiType::setValue(const long long& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 583 inline bool MultiType::setValue(const unsigned long long& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 584 inline bool MultiType::setValue(const float& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 585 inline bool MultiType::setValue(const double& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 586 inline bool MultiType::setValue(const long double& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 587 inline bool MultiType::setValue(const bool& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 588 inline bool MultiType::setValue( void* const& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 589 inline bool MultiType::setValue(const std::string& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 590 inline bool MultiType::setValue(const orxonox::Vector2& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 591 inline bool MultiType::setValue(const orxonox::Vector3& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 592 inline bool MultiType::setValue(const orxonox::Vector4& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 593 inline bool MultiType::setValue(const orxonox::ColourValue& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 594 inline bool MultiType::setValue(const orxonox::Quaternion& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 595 inline bool MultiType::setValue(const orxonox::Radian& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 596 inline bool MultiType::setValue(const orxonox::Degree& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 597 598 /// Assigns the given value and converts it to the current type. 599 inline bool MultiType::setValue(const char* value) { if (this->value_) { return this->value_->setValue(std::string(value)); } else { return this->assignValue(std::string(value)); } } 565 600 } 566 601 -
code/trunk/src/libraries/util/MultiTypeValue.h
r6417 r7401 29 29 /** 30 30 @file 31 @ingroup MultiType 31 32 @brief Declaration and Implementation of the MT_Value<T> class. 32 33 … … 53 54 { 54 55 public: 55 / ** @brief Constructor: Assigns the value and the type identifier. */56 /// Constructor: Assigns the value and the type identifier. 56 57 MT_Value(const T& value, MT_Type::Value type) : MT_ValueBase(type), value_(value) {} 57 58 58 / ** @brief Creates a copy of itself. */59 /// Creates a copy of itself. 59 60 inline MT_ValueBase* clone() const { return new MT_Value<T>(this->value_, this->type_); } 60 61 61 / ** @brief Resets the current value to the default. */62 /// Resets the current value to the default. 62 63 inline void reset() { this->value_ = zeroise<T>(); bHasDefaultValue_ = true; } 63 64 64 /** @brief Assigns the value of the other MultiType, converted to T. @param other The other MultiType */ 65 /** 66 @brief Assigns the value of the other MultiType, converted to T. 67 @param other The other MultiType 68 */ 65 69 inline bool assimilate(const MultiType& other) 66 70 { … … 76 80 } 77 81 78 inline bool getValue(char* value) const { return convertValue<T, char >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */79 inline bool getValue(unsigned char* value) const { return convertValue<T, unsigned char >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */80 inline bool getValue(short* value) const { return convertValue<T, short >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */81 inline bool getValue(unsigned short* value) const { return convertValue<T, unsigned short >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */82 inline bool getValue(int* value) const { return convertValue<T, int >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */83 inline bool getValue(unsigned int* value) const { return convertValue<T, unsigned int >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */84 inline bool getValue(long* value) const { return convertValue<T, long >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */85 inline bool getValue(unsigned long* value) const { return convertValue<T, unsigned long >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */86 inline bool getValue(long long* value) const { return convertValue<T, long long >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */87 inline bool getValue(unsigned long long* value) const { return convertValue<T, unsigned long long >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */88 inline bool getValue(float* value) const { return convertValue<T, float >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */89 inline bool getValue(double* value) const { return convertValue<T, double >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */90 inline bool getValue(long double* value) const { return convertValue<T, long double >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */91 inline bool getValue(bool* value) const { return convertValue<T, bool >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */92 inline bool getValue(void** value) const { return convertValue<T, void* >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */93 inline bool getValue(std::string* value) const { return convertValue<T, std::string >(value, value_, zeroise<std::string> ()); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */94 inline bool getValue(orxonox::Vector2* value) const { return convertValue<T, orxonox::Vector2 >(value, value_, zeroise<orxonox::Vector2> ()); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */95 inline bool getValue(orxonox::Vector3* value) const { return convertValue<T, orxonox::Vector3 >(value, value_, zeroise<orxonox::Vector3> ()); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */96 inline bool getValue(orxonox::Vector4* value) const { return convertValue<T, orxonox::Vector4 >(value, value_, zeroise<orxonox::Vector4> ()); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */97 inline bool getValue(orxonox::ColourValue* value) const { return convertValue<T, orxonox::ColourValue>(value, value_, zeroise<orxonox::ColourValue>()); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */98 inline bool getValue(orxonox::Quaternion* value) const { return convertValue<T, orxonox::Quaternion >(value, value_, zeroise<orxonox::Quaternion> ()); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */99 inline bool getValue(orxonox::Radian* value) const { return convertValue<T, orxonox::Radian >(value, value_, zeroise<orxonox::Radian> ()); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */100 inline bool getValue(orxonox::Degree* value) const { return convertValue<T, orxonox::Degree >(value, value_, zeroise<orxonox::Degree> ()); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */101 102 inline bool setValue(const char& value) { return !(bHasDefaultValue_ = !convertValue<char , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */103 inline bool setValue(const unsigned char& value) { return !(bHasDefaultValue_ = !convertValue<unsigned char , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */104 inline bool setValue(const short& value) { return !(bHasDefaultValue_ = !convertValue<short , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */105 inline bool setValue(const unsigned short& value) { return !(bHasDefaultValue_ = !convertValue<unsigned short , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */106 inline bool setValue(const int& value) { return !(bHasDefaultValue_ = !convertValue<int , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */107 inline bool setValue(const unsigned int& value) { return !(bHasDefaultValue_ = !convertValue<unsigned int , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */108 inline bool setValue(const long& value) { return !(bHasDefaultValue_ = !convertValue<long , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */109 inline bool setValue(const unsigned long& value) { return !(bHasDefaultValue_ = !convertValue<unsigned long , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */110 inline bool setValue(const long long& value) { return !(bHasDefaultValue_ = !convertValue<long long , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */111 inline bool setValue(const unsigned long long& value) { return !(bHasDefaultValue_ = !convertValue<unsigned long long , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */112 inline bool setValue(const float& value) { return !(bHasDefaultValue_ = !convertValue<float , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */113 inline bool setValue(const double& value) { return !(bHasDefaultValue_ = !convertValue<double , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */114 inline bool setValue(const long double& value) { return !(bHasDefaultValue_ = !convertValue<long double , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */115 inline bool setValue(const bool& value) { return !(bHasDefaultValue_ = !convertValue<bool , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */116 inline bool setValue( void* const& value) { return !(bHasDefaultValue_ = !convertValue<void* , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */117 inline bool setValue(const std::string& value) { return !(bHasDefaultValue_ = !convertValue<std::string , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */118 inline bool setValue(const orxonox::Vector2& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Vector2 , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */119 inline bool setValue(const orxonox::Vector3& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Vector3 , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */120 inline bool setValue(const orxonox::Vector4& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Vector4 , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */121 inline bool setValue(const orxonox::ColourValue& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::ColourValue, T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */122 inline bool setValue(const orxonox::Quaternion& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Quaternion , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */123 inline bool setValue(const orxonox::Radian& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Radian , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */124 inline bool setValue(const orxonox::Degree& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Degree , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */125 126 inline operator char() const { return getConvertedValue<T, char> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */127 inline operator unsigned char() const { return getConvertedValue<T, unsigned char> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */128 inline operator short() const { return getConvertedValue<T, short> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */129 inline operator unsigned short() const { return getConvertedValue<T, unsigned short> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */130 inline operator int() const { return getConvertedValue<T, int> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */131 inline operator unsigned int() const { return getConvertedValue<T, unsigned int> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */132 inline operator long() const { return getConvertedValue<T, long> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */133 inline operator unsigned long() const { return getConvertedValue<T, unsigned long> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */134 inline operator long long() const { return getConvertedValue<T, long long> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */135 inline operator unsigned long long() const { return getConvertedValue<T, unsigned long long> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */136 inline operator float() const { return getConvertedValue<T, float> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */137 inline operator double() const { return getConvertedValue<T, double> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */138 inline operator long double() const { return getConvertedValue<T, long double> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */139 inline operator bool() const { return getConvertedValue<T, bool> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */140 inline operator void*() const { return getConvertedValue<T, void*> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */141 inline operator std::string() const { return getConvertedValue<T, std::string> (this->value_, NilValue<std::string >()); } / ** @brief Returns the current value, converted to the requested type. */142 inline operator orxonox::Vector2() const { return getConvertedValue<T, orxonox::Vector2> (this->value_, NilValue<orxonox::Vector2 >()); } / ** @brief Returns the current value, converted to the requested type. */143 inline operator orxonox::Vector3() const { return getConvertedValue<T, orxonox::Vector3> (this->value_, NilValue<orxonox::Vector3 >()); } / ** @brief Returns the current value, converted to the requested type. */144 inline operator orxonox::Vector4() const { return getConvertedValue<T, orxonox::Vector4> (this->value_, NilValue<orxonox::Vector4 >()); } / ** @brief Returns the current value, converted to the requested type. */145 inline operator orxonox::ColourValue() const { return getConvertedValue<T, orxonox::ColourValue>(this->value_, NilValue<orxonox::ColourValue>()); } / ** @brief Returns the current value, converted to the requested type. */146 inline operator orxonox::Quaternion() const { return getConvertedValue<T, orxonox::Quaternion> (this->value_, NilValue<orxonox::Quaternion >()); } / ** @brief Returns the current value, converted to the requested type. */147 inline operator orxonox::Radian() const { return getConvertedValue<T, orxonox::Radian> (this->value_, NilValue<orxonox::Radian >()); } / ** @brief Returns the current value, converted to the requested type. */148 inline operator orxonox::Degree() const { return getConvertedValue<T, orxonox::Degree> (this->value_, NilValue<orxonox::Degree >()); } / ** @brief Returns the current value, converted to the requested type. */149 150 / ** @brief Puts the current value on the stream */82 inline bool getValue(char* value) const { return convertValue<T, char >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 83 inline bool getValue(unsigned char* value) const { return convertValue<T, unsigned char >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 84 inline bool getValue(short* value) const { return convertValue<T, short >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 85 inline bool getValue(unsigned short* value) const { return convertValue<T, unsigned short >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 86 inline bool getValue(int* value) const { return convertValue<T, int >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 87 inline bool getValue(unsigned int* value) const { return convertValue<T, unsigned int >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 88 inline bool getValue(long* value) const { return convertValue<T, long >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 89 inline bool getValue(unsigned long* value) const { return convertValue<T, unsigned long >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 90 inline bool getValue(long long* value) const { return convertValue<T, long long >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 91 inline bool getValue(unsigned long long* value) const { return convertValue<T, unsigned long long >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 92 inline bool getValue(float* value) const { return convertValue<T, float >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 93 inline bool getValue(double* value) const { return convertValue<T, double >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 94 inline bool getValue(long double* value) const { return convertValue<T, long double >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 95 inline bool getValue(bool* value) const { return convertValue<T, bool >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 96 inline bool getValue(void** value) const { return convertValue<T, void* >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 97 inline bool getValue(std::string* value) const { return convertValue<T, std::string >(value, value_, zeroise<std::string> ()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 98 inline bool getValue(orxonox::Vector2* value) const { return convertValue<T, orxonox::Vector2 >(value, value_, zeroise<orxonox::Vector2> ()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 99 inline bool getValue(orxonox::Vector3* value) const { return convertValue<T, orxonox::Vector3 >(value, value_, zeroise<orxonox::Vector3> ()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 100 inline bool getValue(orxonox::Vector4* value) const { return convertValue<T, orxonox::Vector4 >(value, value_, zeroise<orxonox::Vector4> ()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 101 inline bool getValue(orxonox::ColourValue* value) const { return convertValue<T, orxonox::ColourValue>(value, value_, zeroise<orxonox::ColourValue>()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 102 inline bool getValue(orxonox::Quaternion* value) const { return convertValue<T, orxonox::Quaternion >(value, value_, zeroise<orxonox::Quaternion> ()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 103 inline bool getValue(orxonox::Radian* value) const { return convertValue<T, orxonox::Radian >(value, value_, zeroise<orxonox::Radian> ()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 104 inline bool getValue(orxonox::Degree* value) const { return convertValue<T, orxonox::Degree >(value, value_, zeroise<orxonox::Degree> ()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 105 106 inline bool setValue(const char& value) { return !(bHasDefaultValue_ = !convertValue<char , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 107 inline bool setValue(const unsigned char& value) { return !(bHasDefaultValue_ = !convertValue<unsigned char , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 108 inline bool setValue(const short& value) { return !(bHasDefaultValue_ = !convertValue<short , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 109 inline bool setValue(const unsigned short& value) { return !(bHasDefaultValue_ = !convertValue<unsigned short , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 110 inline bool setValue(const int& value) { return !(bHasDefaultValue_ = !convertValue<int , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 111 inline bool setValue(const unsigned int& value) { return !(bHasDefaultValue_ = !convertValue<unsigned int , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 112 inline bool setValue(const long& value) { return !(bHasDefaultValue_ = !convertValue<long , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 113 inline bool setValue(const unsigned long& value) { return !(bHasDefaultValue_ = !convertValue<unsigned long , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 114 inline bool setValue(const long long& value) { return !(bHasDefaultValue_ = !convertValue<long long , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 115 inline bool setValue(const unsigned long long& value) { return !(bHasDefaultValue_ = !convertValue<unsigned long long , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 116 inline bool setValue(const float& value) { return !(bHasDefaultValue_ = !convertValue<float , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 117 inline bool setValue(const double& value) { return !(bHasDefaultValue_ = !convertValue<double , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 118 inline bool setValue(const long double& value) { return !(bHasDefaultValue_ = !convertValue<long double , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 119 inline bool setValue(const bool& value) { return !(bHasDefaultValue_ = !convertValue<bool , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 120 inline bool setValue( void* const& value) { return !(bHasDefaultValue_ = !convertValue<void* , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 121 inline bool setValue(const std::string& value) { return !(bHasDefaultValue_ = !convertValue<std::string , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 122 inline bool setValue(const orxonox::Vector2& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Vector2 , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 123 inline bool setValue(const orxonox::Vector3& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Vector3 , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 124 inline bool setValue(const orxonox::Vector4& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Vector4 , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 125 inline bool setValue(const orxonox::ColourValue& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::ColourValue, T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 126 inline bool setValue(const orxonox::Quaternion& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Quaternion , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 127 inline bool setValue(const orxonox::Radian& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Radian , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 128 inline bool setValue(const orxonox::Degree& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Degree , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 129 130 inline operator char() const { return getConvertedValue<T, char> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 131 inline operator unsigned char() const { return getConvertedValue<T, unsigned char> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 132 inline operator short() const { return getConvertedValue<T, short> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 133 inline operator unsigned short() const { return getConvertedValue<T, unsigned short> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 134 inline operator int() const { return getConvertedValue<T, int> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 135 inline operator unsigned int() const { return getConvertedValue<T, unsigned int> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 136 inline operator long() const { return getConvertedValue<T, long> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 137 inline operator unsigned long() const { return getConvertedValue<T, unsigned long> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 138 inline operator long long() const { return getConvertedValue<T, long long> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 139 inline operator unsigned long long() const { return getConvertedValue<T, unsigned long long> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 140 inline operator float() const { return getConvertedValue<T, float> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 141 inline operator double() const { return getConvertedValue<T, double> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 142 inline operator long double() const { return getConvertedValue<T, long double> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 143 inline operator bool() const { return getConvertedValue<T, bool> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 144 inline operator void*() const { return getConvertedValue<T, void*> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 145 inline operator std::string() const { return getConvertedValue<T, std::string> (this->value_, NilValue<std::string >()); } ///< Returns the current value, converted to the requested type. 146 inline operator orxonox::Vector2() const { return getConvertedValue<T, orxonox::Vector2> (this->value_, NilValue<orxonox::Vector2 >()); } ///< Returns the current value, converted to the requested type. 147 inline operator orxonox::Vector3() const { return getConvertedValue<T, orxonox::Vector3> (this->value_, NilValue<orxonox::Vector3 >()); } ///< Returns the current value, converted to the requested type. 148 inline operator orxonox::Vector4() const { return getConvertedValue<T, orxonox::Vector4> (this->value_, NilValue<orxonox::Vector4 >()); } ///< Returns the current value, converted to the requested type. 149 inline operator orxonox::ColourValue() const { return getConvertedValue<T, orxonox::ColourValue>(this->value_, NilValue<orxonox::ColourValue>()); } ///< Returns the current value, converted to the requested type. 150 inline operator orxonox::Quaternion() const { return getConvertedValue<T, orxonox::Quaternion> (this->value_, NilValue<orxonox::Quaternion >()); } ///< Returns the current value, converted to the requested type. 151 inline operator orxonox::Radian() const { return getConvertedValue<T, orxonox::Radian> (this->value_, NilValue<orxonox::Radian >()); } ///< Returns the current value, converted to the requested type. 152 inline operator orxonox::Degree() const { return getConvertedValue<T, orxonox::Degree> (this->value_, NilValue<orxonox::Degree >()); } ///< Returns the current value, converted to the requested type. 153 154 /// Puts the current value on the stream 151 155 inline void toString(std::ostream& outstream) const { outstream << this->value_; } 152 156 153 / ** @brief loads data from the bytestream (mem) into the MT and increases the bytestream pointer by the size of the data */157 /// loads data from the bytestream (mem) into the MT and increases the bytestream pointer by the size of the data 154 158 inline void importData( uint8_t*& mem ) { loadAndIncrease( /*(const T&)*/this->value_, mem ); } 155 / ** @brief saves data from the MT into the bytestream (mem) and increases the bytestream pointer by the size of the data */159 /// saves data from the MT into the bytestream (mem) and increases the bytestream pointer by the size of the data 156 160 inline void exportData( uint8_t*& mem ) const { saveAndIncrease( /*(const T&)*/this->value_, mem ); } 157 / ** @brief returns the size of the data that would be saved by exportData */161 /// returns the size of the data that would be saved by exportData 158 162 inline uint8_t getSize() const { return returnSize( this->value_ ); } 159 163 160 T value_; // !< The stored value164 T value_; ///< The stored value 161 165 }; 162 166 -
code/trunk/src/libraries/util/OrxAssert.h
r6105 r7401 29 29 /** 30 30 @file 31 @ingroup ExceptionAssertion 31 32 @brief 32 33 Declaration of custom assertion facilities … … 41 42 #include "OutputHandler.h" 42 43 43 // define an assert macro that can display a message44 44 #ifndef NDEBUG 45 /** Run time assertion like assert(), but with an embedded message. 46 @details 47 The message will be printed as error with COUT(1). <br> 48 You can use the same magic here as you can with \ref ThrowException 49 @code 50 OrxAssert(condition, "Text: " << number << " more text"); 51 @endcode 52 */ 45 53 #define OrxAssert(Assertion, ErrorMessage) \ 46 54 Assertion ? ((void)0) : (void)(orxonox::OutputHandler::getOutStream(1) << ErrorMessage << std::endl); \ -
code/trunk/src/libraries/util/OrxEnum.h
r5738 r7401 28 28 29 29 /** 30 @file 31 @brief 32 Declaration of the OrxEnum class. 30 @file 31 @ingroup Util 33 32 */ 34 33 … … 40 39 namespace orxonox 41 40 { 41 /** Lightweight enumeration class that can be extended at run time. 42 @details 43 The class accepts type int and also defines operator int(). Therefore 44 int and OrxEnum can be used interchangeably so you can extend the content 45 of the enumeration at run time by adding ints. 46 @par Declaring an OrxEnum 47 Write a struct that inherits OrxEnum and use some macros: 48 @code 49 struct MyEnum : OrxEnum<MyEnum> 50 { 51 OrxEnumConstructors(MyEnum); 52 53 static const int Value1 = -1; 54 static const int Value2 = 0; 55 static const int Value3 = Value2 + 10; 56 }; 57 @endcode 58 */ 42 59 template <class T> 43 60 struct OrxEnum … … 45 62 public: 46 63 OrxEnum() { } 47 OrxEnum(int type) 64 OrxEnum(int type) { type_ = type; } 48 65 OrxEnum(const T& instance) { type_ = instance.type_; } 49 66 50 operator int() 67 operator int() { return type_; } 51 68 T& operator =(int type) { type_ = type; return *this; } 52 69 bool operator <(const T& right) const { return (type_ < right.type_); } … … 59 76 } 60 77 78 /// See orxonox::OrxEnum for more info 61 79 #define OrxEnumConstructors(enumName) \ 62 80 enumName() { } \ -
code/trunk/src/libraries/util/OutputHandler.cc
r6417 r7401 67 67 @brief 68 68 Gets temporary log path and starts the log file 69 @param outputHandler70 This is only required to avoid another call to getInstance (this c'tor was71 called from getInstance!)72 69 */ 73 70 LogFileWriter() … … 117 114 118 115 private: 119 std::ofstream logFile_; //! File handle for the log file120 std::string logFilename_; //! Filename of the log file116 std::ofstream logFile_; //!< File handle for the log file 117 std::string logFilename_; //!< Filename of the log file 121 118 }; 122 119 … … 162 159 @brief 163 160 Sets the right soft debug level and registers itself 164 @param outputHandler165 This is only required to avoid another call to getInstance (this c'tor was166 called from getInstance!)167 161 */ 168 162 MemoryLogWriter() … … 186 180 187 181 private: 188 std::ostringstream buffer_; //! Stream object used to process the output189 std::vector<std::pair<int, std::string> > output_; //! Vector containing ALL output182 std::ostringstream buffer_; //!< Stream object used to process the output 183 std::vector<std::pair<int, std::string> > output_; //!< Vector containing ALL output 190 184 }; 191 185 -
code/trunk/src/libraries/util/OutputHandler.h
r7284 r7401 29 29 /** 30 30 @file 31 @ingroup Util Output 31 32 @brief 32 Declaration of classes related to output (logging) .33 Declaration of classes related to output (logging), most notably OutputHandler and OutputListener. 33 34 */ 34 35 … … 50 51 Denotes different levels of text output (log output) 51 52 52 0, None : Very important output53 1, Error : Errors54 2, Warning: Warnings55 3, Info : Information56 4, Debug : Debug information57 5, Verbose: More debug information58 6, Ultra : Crazy debug information53 - 0, None : Very important output 54 - 1, Error : Errors 55 - 2, Warning: Warnings 56 - 3, Info : Information 57 - 4, Debug : Debug information 58 - 5, Verbose: More debug information 59 - 6, Ultra : Crazy debug information 59 60 */ 60 61 namespace OutputLevel … … 79 80 /** 80 81 @brief 81 The OutputHandler acts like std::cout, but output isn't only shown in the console. 82 83 You can register your own listener for output by inheriting from OutputListner. 82 The OutputHandler acts like @c std::cout, but output isn't only shown in the console. 83 84 Output passed to the OutputHandler is distributed to all registered listeners, 85 for example the console, the logfile, or the ingame shell. 86 87 You can register your own listener for output by inheriting from OutputListener. 84 88 And if you need the output previously processed, iterate over it with 85 OutputHandler::getOutputVector[Begin/End]. 89 OutputHandler::getOutputVectorBegin and OutputHandler::getOutputVectorEnd. 90 86 91 The way to output text is to first set the desired output level with 87 OutputHandler::getOutStream(level) and then use the "<<" operator like with std::cout. 92 @ref getOutStream "OutputHandler::getOutStream(level)" and then use 93 the "<<" operator like with @c std::cout. Alternatively you can use the COUT() macro. 88 94 */ 89 95 class _UtilExport OutputHandler … … 213 219 OutputHandler(); 214 220 ~OutputHandler(); 215 OutputHandler(const OutputHandler& rhs); //!Unused and undefined221 OutputHandler(const OutputHandler& rhs); //!< Copy-constructor: Unused and undefined 216 222 217 223 std::list<OutputListener*> listeners_; //!< Array with all registered output listeners -
code/trunk/src/libraries/util/Scope.cc
r5738 r7401 27 27 */ 28 28 29 /** 30 @file 31 @brief Static linkage of the two maps in orxonox::ScopeManager. 32 */ 33 29 34 #include "Scope.h" 30 35 -
code/trunk/src/libraries/util/Scope.h
r7266 r7401 27 27 */ 28 28 29 /** 30 @file 31 @ingroup SingletonScope 32 @brief Declaration of the classes that are needed to use Scopes: 33 orxonox::Scope, orxonox::ScopeListener, and orxonox::ScopeManager. 34 35 @anchor Scope 36 37 A virtual scope can be represented by an instance of class orxonox::Scope. orxonox::Scope<@a scope> is a template 38 an its template argument defines the name of the virtual scope. See orxonox::ScopeID for an enumeration of the 39 available values for @a scope. The orxonox::Scope object for a given @a scope can be activated or deactivated. 40 Instances of orxonox::ScopeListener can register for a given @a scope and will get a notification if the 41 corresponding orxonox::Scope object changes its state. 42 43 To avoid multiple instances of orxonox::Scope<@a scope> in different libraries, each instance of orxonox::Scope 44 registers in orxonox::ScopeManager, where they are linked statically in the util library. 45 46 Scopes are usually used to control the creation and destruction of Singletons. 47 48 @see orxonox::ScopedSingletonManager 49 @see orxonox::Singleton 50 */ 51 29 52 #ifndef __Util_Scope_H__ 30 53 #define __Util_Scope_H__ … … 42 65 { 43 66 /** 44 @brief The ScopeManager stores the variables of the scope templates in a statically linked context. 67 @brief The ScopeManager stores the variables of the Scope templates in a statically linked context. 68 69 If all Scope objects are managed by this class, they are statically linked in the util library. 70 Without this, a new instance of Scope<T> for each T would be created in every library of Orxonox, 71 which is of course not the desired behavior. 72 73 @see See @ref Scope "this description" for details about the interrelationship of Scope, ScopeListener, and ScopeManager. 45 74 */ 46 75 class _UtilExport ScopeManager … … 56 85 57 86 /** 58 @brief ScopeListeners register themselves in the corresponding scope and wait for notifications. 87 @brief ScopeListeners register themselves in the corresponding Scope and wait for notifications. 88 Notifications are sent if a Scope is activated or deactivated. 89 90 @see See @ref Scope "this description" for details about the interrelationship of Scope, ScopeListener, and ScopeManager. 59 91 */ 60 92 class _UtilExport ScopeListener … … 86 118 Objects inheriting from a ScopeListener are registered in a list (different for each scope). 87 119 If the scope gets activated or deactivated, all objects in this list are notified. 120 121 @see See @ref Scope "this description" for details about the interrelationship of Scope, ScopeListener, and ScopeManager. 88 122 */ 89 123 template <ScopeID::Value scope> … … 130 164 } 131 165 166 //! Deactivates the listeners of this scope in case the scope is destroyed or the construction fails. 132 167 void deactivateListeners() 133 168 { -
code/trunk/src/libraries/util/ScopedSingletonManager.cc
r7284 r7401 27 27 */ 28 28 29 /** 30 @file 31 @brief Static linkage of the ScopedSingletonManager maps. 32 */ 33 29 34 #include "ScopedSingletonManager.h" 30 35 -
code/trunk/src/libraries/util/ScopedSingletonManager.h
r7284 r7401 26 26 * 27 27 */ 28 29 /** 30 @file 31 @ingroup SingletonScope 32 @brief Definition of orxonox::ScopedSingletonManager, orxonox::ClassScopedSingletonManager, and the ManageScopedSingleton macro. 33 34 ScopedSingletonManager is used to create and destroy Singletons that belong to 35 a given Scope. For each one of these singletons, the macro ManageScopedSingleton() 36 has to be called to register the singleton with orxonox::ScopedSingletonManager. 37 38 See @ref SingletonExample "this code" for an example. 39 40 @see orxonox::Singleton 41 @see orxonox::Scope 42 */ 28 43 29 44 #ifndef __ScopedSingletonManager_H__ … … 38 53 #include "util/Singleton.h" 39 54 55 /** 56 @brief Registers an orxonox::Singleton with orxonox::ScopedSingletonManager. 57 @param className The name of the singleton class 58 @param scope The scope in which the singleton should exist 59 @param allowedToFail If true, the singleton is allowed to fail and thus a try-catch block is used when creating the singleton. 60 61 If this macro is called for a singleton, it is registered with ScopedSingletonManager 62 and will thus be created if its scope becomes active and destroyed if is deactivated. 63 */ 40 64 #define ManageScopedSingleton(className, scope, allowedToFail) \ 41 65 className* className::singletonPtr_s = NULL; \ … … 46 70 class OrxonoxClass; 47 71 72 /** 73 @brief Base class of ClassScopedSingletonManager, implements some static functions 74 used to dispatch calls to preUpdate and postUpdate to all instances of this class. 75 It also keeps track of all existing ScopedSingletonManagers and stores them in a 76 map, sorted by the scope they belong to. 77 */ 48 78 class _UtilExport ScopedSingletonManager 49 79 { 50 80 public: 81 /// Constructor: Initializes all the values 51 82 ScopedSingletonManager(const std::string& className, ScopeID::Value scope) 52 83 : className_(className) … … 54 85 { } 55 86 virtual ~ScopedSingletonManager() { } 87 88 /// Adds a new instance of ScopedSingletonManager to the map. 56 89 static void addManager(ScopedSingletonManager* manager); 57 90 91 /// Calls preUpdate in all instances of ScopedSingletonManager that are registered in the map. 58 92 template<ScopeID::Value scope> 59 93 static void preUpdate(const Clock& time) … … 64 98 } 65 99 virtual void preUpdate(const Clock& time) = 0; 100 101 /// Calls postUpdate in all instances of ScopedSingletonManager that are registered in the map. 66 102 template<ScopeID::Value scope> 67 103 static void postUpdate(const Clock& time) … … 78 114 79 115 protected: 80 const std::string className_; 81 const ScopeID::Value scope_; 116 const std::string className_; ///< The name of the scoped singleton class that is managed by this object 117 const ScopeID::Value scope_; ///< The scope of the singleton that is managed by this object 82 118 }; 83 119 120 /** 121 @anchor ClassScopedSingletonManager 122 123 @brief Manages a scoped singleton for a given scope. 124 @param T The managed singleton class 125 @param scope The scope in which the singleton @a T should be active 126 @param allowedToFail If true, a specialization of this template is used, that uses try-catch blocks to handle possible failures. 127 128 This class inherits from ScopeListener for the given scope and thus its functions 129 activated() and deactivated() are called whenever the Scope changes its state. 130 131 If the Scope is activated, a new instance of @a T (which must be a singleton) is created. 132 If the Scope is deactivated, the singleton is destroyed. 133 134 @see Singleton 135 */ 84 136 template <class T, ScopeID::Value scope, bool allowedToFail> 85 137 class ClassScopedSingletonManager : public ScopedSingletonManager, public ScopeListener 86 138 { 87 139 public: 140 //! Constructor: Initializes the singleton pointer and passes the scope to ScopedSingletonManager and ScopeListener 88 141 ClassScopedSingletonManager(const std::string& className) 89 142 : ScopedSingletonManager(className, scope) … … 113 166 } 114 167 168 //! Destroys the singleton instance - overloaded for OrxonoxClass, calls OrxonoxClass::destroy() 115 169 void destroy(OrxonoxClass*) 116 170 { 117 171 singletonPtr_->destroy(); 118 172 } 173 //! Destroys the singleton instance - overloaded for all other pointers, calls delete 119 174 void destroy(void*) 120 175 { … … 139 194 140 195 private: 141 T* singletonPtr_; 196 T* singletonPtr_; ///< Unique instance of the singleton class @a T 142 197 }; 143 198 199 /** 200 @brief This class partially spezializes ClassScopedSingletonManager for classes @a T that are allowed to fail. 201 @param T The managed singleton class 202 @param scope The scope in which the singleton @a T should be active 203 204 Because @a T could fail when being created, this partial spezialization of ClassScopedSingletonManager 205 uses a try-catch block to handle exceptions. 206 207 See @ref ClassScopedSingletonManager for a full documentation of the basis template. 208 */ 144 209 template <class T, ScopeID::Value scope> 145 210 class ClassScopedSingletonManager<T, scope, true> : public ScopedSingletonManager, public ScopeListener 146 211 { 147 212 public: 213 //! Constructor: Initializes the singleton pointer and passes the scope to ScopedSingletonManager and ScopeListener 148 214 ClassScopedSingletonManager(const std::string& className) 149 215 : ScopedSingletonManager(className, scope) … … 180 246 } 181 247 248 //! Destroys the singleton instance - overloaded for OrxonoxClass, calls OrxonoxClass::destroy() 182 249 void destroy(OrxonoxClass* ptr) 183 250 { 184 251 singletonPtr_->destroy(); 185 252 } 253 //! Destroys the singleton instance - overloaded for void*, calls delete 186 254 void destroy(void* ptr) 187 255 { … … 208 276 209 277 private: 210 T* singletonPtr_; 278 T* singletonPtr_; ///< Unique instance of the singleton class @a T 211 279 }; 212 280 } -
code/trunk/src/libraries/util/Serialise.h
r7182 r7401 29 29 /** 30 30 @file 31 @ingroup Util 31 32 @brief Functions to serialise most of the types/classed used in Orxonox 32 33 */ … … 53 54 template <class T> inline bool checkEquality( const T& variable, uint8_t* mem ); 54 55 55 56 56 57 // =========== char* 57 58 58 59 inline uint32_t returnSize( char*& variable ) 59 60 { 60 61 return strlen(variable)+1; 61 62 } 62 63 63 64 inline void saveAndIncrease( char*& variable, uint8_t*& mem ) 64 65 { … … 66 67 mem += returnSize(variable); 67 68 } 68 69 69 70 inline void loadAndIncrease( char*& variable, uint8_t*& mem ) 70 71 { … … 76 77 mem += len; 77 78 } 78 79 79 80 inline bool checkEquality( char*& variable, uint8_t* mem ) 80 81 { 81 82 return strcmp(variable, (char*)mem)==0; 82 83 } 83 84 84 85 // =================== Template specialisation stuff ============= 85 86 … … 423 424 return memcmp(&temp, mem, sizeof(uint64_t))==0; 424 425 } 425 426 426 427 // =========== string 427 428 -
code/trunk/src/libraries/util/SharedPtr.cc
r7284 r7401 27 27 */ 28 28 29 /** 30 @file 31 @brief Static linkage of the SmallObjectAllocator used by SharedPtr. 32 */ 33 29 34 #include "SharedPtr.h" 30 35 31 36 namespace orxonox 32 37 { 33 SmallObjectAllocator& createSharedCounterPool()38 namespace detail 34 39 { 35 static SmallObjectAllocator instance(sizeof(SharedCounterImpl<void>)); 36 return instance; 40 SmallObjectAllocator& createSharedCounterPool() 41 { 42 static SmallObjectAllocator instance(sizeof(SharedCounterImpl<void>)); 43 return instance; 44 } 37 45 } 38 46 } -
code/trunk/src/libraries/util/SharedPtr.h
r7284 r7401 27 27 */ 28 28 29 /** 30 @defgroup SharedPtr SharedPtr<T> 31 @ingroup Util 32 */ 33 34 /** 35 @file 36 @ingroup SharedPtr 37 @brief Definition of the SharedPtr template that is used to manage pointers. 38 39 @anchor SharedPtrExample 40 41 The orxonox::SharedPtr template can be used to manage a pointer to an object 42 that was created with new. The SharedPtr acts like the pointer itself, but it 43 keeps track of the number of references to it. If all references are removed, 44 SharedPtr deletes the managed object automatically. 45 46 Example: 47 48 Classic implementation using new and delete: 49 @code 50 void someFunction() 51 { 52 MyClass* object = new MyClass(); // Create a new instance of MyClass 53 54 object->myFunction(); // Calls MyClass::myFunction() 55 56 delete object; // Delete the object at the end of the scope 57 } 58 @endcode 59 60 The same function using SharedPtr: 61 @code 62 void someFunction() 63 { 64 SharedPtr<MyClass> object = new MyClass(); // Create a new instance of MyClass and store its pointer in a SharedPtr 65 66 object->myFunction(); // Calls MyClass::myFunction() 67 68 } // At the end of the scope, the SharedPtr is destroyed. Because no other SharedPtrs 69 // point at the object, the object itself is also destroyed automatically 70 @endcode 71 72 This is especially handy if you do not know what will happen with an object that was 73 created with new, for example if you pass it to another object. If multiple instances 74 share a pointer to the same object, none of these instances can delete the object 75 without interfering with the other instances. But if none of the instances destroy the 76 object, it will never be destroyed and results in a memory leak. With a SharedPtr 77 however you don't have to think about destroying the object, because the SharedPtr 78 itself keeps track of the references. 79 80 Example: 81 82 Classic implementation using new and delete: 83 @code 84 class OtherClass // Declaration of some class 85 { 86 public: 87 OtherClass(MyClass* object) // Constructor 88 { 89 this->object_ = object; // Assigns the pointer to the member variable object_ 90 } 91 92 ~OtherClass() // Destructor 93 { 94 ??? // What to do with object_? 95 } 96 97 private: 98 MyClass* object_; // A pointer to the object 99 }; 100 101 void someFunction() 102 { 103 MyClass* object = new MyClass(); // Create a new instance of MyClass 104 105 OtherClass* other1 = new OtherClass(object); // Create an instance of OtherClass and pass the object pointer 106 OtherClass* other2 = new OtherClass(object); // " 107 OtherClass* other3 = new OtherClass(object); // " 108 109 ??? // What happens with object now? 110 } 111 @endcode 112 113 If you use SharedPtr<MyClass> instead of a classic MyClass* pointer, the instance of 114 MyClass would be automatically destroyed if all instances of OtherClass are destroyed. 115 You don't need any code in the destructor and you can completely forget about the 116 object, because its managed by the SharedPtr. 117 118 The same code using SharedPtr: 119 @code 120 class OtherClass // Declaration of some class 121 { 122 public: 123 OtherClass(const SharedPtr<MyClass>& object) // Constructor 124 { 125 this->object_ = object; // Assigns the pointer to the member variable object_ 126 } 127 128 private: 129 SharedPtr<MyClass> object_; // A SharedPtr to the object 130 }; 131 132 void someFunction() 133 { 134 SharedPtr<MyClass> object = new MyClass(); // Create a new instance of MyClass 135 136 OtherClass* other1 = new OtherClass(object); // Create an instance of OtherClass and pass the object pointer 137 OtherClass* other2 = new OtherClass(object); // " 138 OtherClass* other3 = new OtherClass(object); // " 139 140 } // The SmartPtr "object" is destroyed at the end of the scope, 141 // but the three instances of OtherClass keep the object alive 142 // until they are all destroyed. 143 @endcode 144 */ 145 29 146 #ifndef _SharedPtr_H__ 30 147 #define _SharedPtr_H__ … … 39 156 namespace orxonox 40 157 { 41 class SharedCounter 42 { 43 public: 44 SharedCounter() : count_(1) {} 45 virtual void destroy() = 0; 46 47 int count_; 48 }; 49 50 template <class T> 51 class SharedCounterImpl : public SharedCounter 52 { 53 public: 54 SharedCounterImpl(T* pointer) : pointer_(pointer) {} 55 56 void destroy() 57 { 58 delete this->pointer_; 59 } 60 61 private: 62 T* pointer_; 63 }; 64 65 _UtilExport SmallObjectAllocator& createSharedCounterPool(); 66 67 FORCEINLINE SmallObjectAllocator& getSharedCounterPool() 68 { 69 static SmallObjectAllocator& instance = createSharedCounterPool(); 70 return instance; 158 namespace detail 159 { 160 /// BaseClass of SharedCounterImpl, has a counter that is initialized with 1 161 class SharedCounter 162 { 163 public: 164 SharedCounter() : count_(1) {} 165 virtual void destroy() = 0; 166 167 int count_; 168 }; 169 170 /// Child class of SharedCounter, keeps a pointer to an object of type T that can be destroyed with destroy() 171 template <class T> 172 class SharedCounterImpl : public SharedCounter 173 { 174 public: 175 SharedCounterImpl(T* pointer) : pointer_(pointer) {} 176 177 void destroy() 178 { 179 delete this->pointer_; 180 } 181 182 private: 183 T* pointer_; 184 }; 185 186 _UtilExport SmallObjectAllocator& createSharedCounterPool(); 187 188 FORCEINLINE SmallObjectAllocator& getSharedCounterPool() 189 { 190 static SmallObjectAllocator& instance = createSharedCounterPool(); 191 return instance; 192 } 71 193 } 72 194 195 /** 196 @brief The SharedPtr template is a utility to manage pointers to an object. 197 @param T The type of the managed object 198 199 SharedPtr acts like a real pointer, except that it keeps track of the number of 200 references to the object. If the the number of references drops to zero, the 201 object is destroyed automatically. 202 203 @see See @ref SharedPtrExample "this description" for some examples and more information. 204 205 @note The number of references is stored in a separate object that is shared 206 among all instances of SharedPtr that point to the same pointer. This object is 207 also responsible for destroying the pointer if the reference counter becomes zero. 208 */ 73 209 template <class T> 74 210 class SharedPtr … … 78 214 79 215 public: 216 /// Default constructor, the pointer is set to NULL. 80 217 inline SharedPtr() : pointer_(0), counter_(0) 81 218 { 82 219 } 83 220 221 /// Constructor, creates a SharedPtr that points to @a pointer, increments the counter. 84 222 inline SharedPtr(T* pointer) : pointer_(pointer), counter_(0) 85 223 { 86 224 if (this->pointer_) 87 225 { 88 void* chunk = getSharedCounterPool().alloc();89 this->counter_ = new (chunk) SharedCounterImpl<T>(this->pointer_);226 void* chunk = detail::getSharedCounterPool().alloc(); 227 this->counter_ = new (chunk) detail::SharedCounterImpl<T>(this->pointer_); 90 228 } 91 229 } 92 230 231 /// Copy-constructor, this SharedPtr now points to the same object like the other SharedPtr, increments the counter. 93 232 inline SharedPtr(const SharedPtr& other) : pointer_(other.pointer_), counter_(other.counter_) 94 233 { … … 97 236 } 98 237 238 /// Copy-constructor for SharedPtr with another template agument, increments the counter. 99 239 template <class O> 100 240 inline SharedPtr(const SharedPtr<O>& other) : pointer_(other.pointer_), counter_(other.counter_) … … 104 244 } 105 245 246 /// Destructor, decrements the counter and deletes the object if the counter becomes zero. 106 247 inline ~SharedPtr() 107 248 { … … 113 254 { 114 255 this->counter_->destroy(); 115 getSharedCounterPool().free(this->counter_);256 detail::getSharedCounterPool().free(this->counter_); 116 257 } 117 258 } 118 259 } 119 260 261 /// Assigns a new object, decrements the counter of the old object, increments the counter of the new object. 120 262 inline SharedPtr& operator=(const SharedPtr& other) 121 263 { … … 124 266 } 125 267 268 /// Assigns a new object with another template argument, decrements the counter of the old object, increments the counter of the new object. 126 269 template <class O> 127 270 inline SharedPtr& operator=(const SharedPtr<O>& other) … … 131 274 } 132 275 276 /// Casts the pointer to another type 133 277 template <class O> 134 278 inline SharedPtr<O> cast() const … … 138 282 } 139 283 284 /// Overloaded -> operator, returns the pointer to the managed object. 140 285 inline T* operator->() const 141 286 { … … 144 289 } 145 290 291 /// Overloaded * operator, returns a reference ot the managed object. 146 292 inline T& operator*() const 147 293 { … … 150 296 } 151 297 298 /// Returns the pointer to the managed object. 152 299 inline T* get() const 153 300 { … … 155 302 } 156 303 304 /// Returns true if the pointer is not NULL. 157 305 inline operator bool() const 158 306 { … … 160 308 } 161 309 310 /// Swaps the pointer and the counter of two instances of SharedPtr with the same template argument. 162 311 inline void swap(SharedPtr& other) 163 312 { … … 167 316 168 317 private: 169 inline SharedPtr(T* pointer, SharedCounter* counter) : pointer_(pointer), counter_(counter) 318 /// Private constructor, used by the cast() function. 319 inline SharedPtr(T* pointer, detail::SharedCounter* counter) : pointer_(pointer), counter_(counter) 170 320 { 171 321 if (this->pointer_) … … 173 323 } 174 324 175 T* pointer_; 176 SharedCounter* counter_;325 T* pointer_; ///< A pointer to the managed object of type @a T 326 detail::SharedCounter* counter_; ///< A pointer to the shared reference counter 177 327 }; 178 328 329 /** 330 @brief A child class of SharedPtr, used to reflect the hierarchy of the underlying class @a T. 331 @param T The type of the managed object 332 @param Parent The type of the SharedPtr that manages the parent class of @a T 333 334 This class is used to reflect the hierarchy of the underlying class @a T. 335 For example the @c Functor classes: While a @c Functor* pointer would be managed by 336 @c SharedPtr<Functor>, the child class @c FunctorStatic is managed by the class 337 <tt>SharedChildPtr<FunctorStatic, SharedPtr<Functor> ></tt>. 338 339 The second template argument @a Parent is used as the parent class of 340 SharedChildPtr. This means that each instance of <tt>SharedChildPtr<T, Parent></tt> 341 can be upcasted to @c Parent. 342 343 So for example this works: 344 @code 345 SharedChildPtr<FunctorStatic, SharedPtr<Functor> > functorStatic = createFunctor(&MyClass::myStaticFunction); 346 SharedPtr<Functor> functor = functorStatic; 347 @endcode 348 349 @note There are some typedefs and more to make the usage of SharedChildPtr easier 350 for the classes Functor and Executor. See FunctorPtr.h and ExecutorPtr.h. The above 351 example could thus be simplified the following way: 352 @code 353 FunctorStaticPtr functorStatic = createFunctor(&MyClass::myStaticFunction); 354 FunctorPtr functor = functorStatic; 355 @endcode 356 357 @see See SharedPtr for more information about the base class SharedPtr. 358 @see See @ref SharedPtrExample "this description" for some examples about how to use SharedPtr. 359 */ 179 360 template <class T, class Parent> 180 361 class SharedChildPtr : public Parent -
code/trunk/src/libraries/util/SignalHandler.h
r5738 r7401 29 29 /** 30 30 @file 31 @ingroup Util 31 32 @brief Declaration of the SignalHandler class. 32 33 */ … … 68 69 typedef std::list<SignalCallbackRec> SignalCallbackList; 69 70 71 /// The SignalHandler is used to catch signals like SIGSEGV and write a backtrace to the logfile. 70 72 class SignalHandler : public Singleton<SignalHandler> 71 73 { … … 99 101 namespace orxonox 100 102 { 103 /// The SignalHandler is used to catch signals like SIGSEGV and write a backtrace to the logfile. Not implemented on Windows. 101 104 class _UtilExport SignalHandler : public Singleton<SignalHandler> 102 105 { -
code/trunk/src/libraries/util/Singleton.h
r7163 r7401 27 27 */ 28 28 29 /** 30 @defgroup SingletonScope Singletons and Scope 31 @ingroup Util 32 */ 33 34 /** 35 @file 36 @ingroup SingletonScope 37 @brief Definition of the Singleton template that is used as base class for classes that allow only one instance. 38 39 @anchor SingletonExample 40 41 Classes that inherit from orxonox::Singleton follow the singleton pattern and thus 42 allow only one instance of the class to exist. This istance is stored in a static 43 variable called @c singletonPtr_s. orxonox::Singleton will access this variable, but 44 it must be implemented in the deriving class. 45 46 Example: 47 @code 48 class TestSingleton : public Singleton<TestSingleton> // inherit from Singleton, pass the own class as template argument 49 { 50 friend class Singleton<TestSingleton>; // friend declaration so Singleton can access singletonPtr_s 51 52 public: 53 TestSingleton(); // public constructor because we may want to manage this singleton 54 // with an orxonox::ScopedSingletonManager (see below) 55 virtual ~TestSingleton(); // public destructor 56 57 void testFunction(); // put your functions here 58 59 private: 60 int testValue_; // put your variables here 61 62 static TestSingleton* singletonPtr_s; // static singleton instance pointer, used by the Singleton template 63 }; 64 @endcode 65 66 And don't forget to initialize the static singleton pointer in the source (*.cc) %file: 67 @code 68 TestSingleton* TestSingleton::singletonPtr_s = NULL; 69 @endcode 70 71 Usually a singleton gets created automatically when it is first used, but it will never 72 be destroyed (unless the singleton explicitly deletes itself). To allow controlled 73 construction and destruction, the singleton can be put within a virtual scope. This is 74 done by registering the singleton class with orxonox::ScopedSingletonManager. To 75 do so, the ManageScopedSingleton() macro has to be called: 76 77 @code 78 ManageScopedSingleton(TestSingleton, ScopeID::Graphics, false); // muste be called in a source (*.cc) file 79 @endcode 80 81 @b Important: If you call ManageScopedSingleton(), you don't have to initialize singletonPtr_s anymore, 82 because that's already done by the macro. 83 84 Now the singleton TestSingleton gets automatically created if the scope Graphics becomes 85 active and also gets destroyed if the scope is deactivated. 86 87 Note that not all singletons must register with a scope, but it's recommended. 88 89 If a class inherits from orxonox::Singleton, it also inherits its functions. The most important 90 function is orxonox::Singleton::getInstance() which returns a reference to the only instance 91 of the singleton. 92 93 Example: 94 @code 95 TestSingleton::TestSingleton() // implement the constructor 96 { 97 this->testValue_ = 15; 98 } 99 100 void TestSingleton::testFunction() // implement testFunction 101 { 102 COUT(0) << "My value is " << this->testValue_ << std::endl; 103 } 104 105 TestSingleton::getInstance().testFunction(); // prints "My value is 15" 106 @endcode 107 */ 108 29 109 #ifndef __Util_Singleton_H__ 30 110 #define __Util_Singleton_H__ … … 42 122 43 123 Usage: 44 Inherit publicly from Singleton<MyClass> and provide access to 45 MyClass::singletonPtr_s. 124 Inherit publicly from Singleton<MyClass> and provide access to MyClass::singletonPtr_s. 46 125 This can easily be done with a friend declaration. 126 127 See @ref SingletonExample "this example" for an exemplary implementation. 47 128 */ 48 129 template <class T> … … 80 161 } 81 162 82 //! Constructor resets the singleton instance pointer163 //! Destructor resets the singleton instance pointer 83 164 ~Singleton() 84 165 { -
code/trunk/src/libraries/util/SmallObjectAllocator.cc
r7284 r7401 27 27 */ 28 28 29 /** 30 @file 31 @brief Implementation of SmallObjectAllocator 32 */ 33 29 34 #include "SmallObjectAllocator.h" 30 35 31 36 namespace orxonox 32 37 { 38 /** 39 @brief Constructor: initializes the allocator and its values. 40 @param objectSize The size in bytes (returned by sizeof()) of the allocated objects 41 @param numObjects The number of objects that are allocated in one block of memory 42 */ 33 43 SmallObjectAllocator::SmallObjectAllocator(size_t objectSize, size_t numObjects) 34 44 { 35 this-> objectSize_ = std::max(objectSize, sizeof(Chunk));36 this->num Objects_ = numObjects;45 this->chunkSize_ = std::max(objectSize, sizeof(Chunk)); // the chunk's size will be the maximum of the object's size and the size of a Chunk object itself 46 this->numChunksPerBlock_ = numObjects; 37 47 this->first_ = 0; 38 48 } 39 49 50 /** 51 @brief Destructor: deletes the allocated memory blocks. 52 */ 40 53 SmallObjectAllocator::~SmallObjectAllocator() 41 54 { … … 44 57 } 45 58 59 /** 60 @brief Helper function, used to set the next_ pointer of a Chunk. 61 */ 46 62 /* static */ void SmallObjectAllocator::setNext(void* chunk, void* next) 47 63 { … … 49 65 } 50 66 67 /** 68 @brief Helper function, returns the next_ pointer of a Chunk 69 */ 51 70 /* static */ void* SmallObjectAllocator::getNext(void* chunk) 52 71 { … … 54 73 } 55 74 75 /** 76 @brief Returns the first free memory chunk or allocates a new block of memory. 77 */ 56 78 void* SmallObjectAllocator::alloc() 57 79 { 80 // get the first free chunk 58 81 void* chunk = this->first_; 59 82 83 // check if the chunk exists 60 84 if (chunk) 61 85 { 86 // yes it does - the first_ pointer now points to the second element in the list 62 87 this->first_ = getNext(chunk); 63 88 } 64 89 else 65 90 { 66 char* block = new char[this->objectSize_ * this->numObjects_]; 91 // no it doesnt - allocate a new block of memory 92 char* block = new char[this->chunkSize_ * this->numChunksPerBlock_]; 67 93 this->blocks_.push_back(block); 68 94 69 for (size_t i = 1; i < this->numObjects_ - 1; ++i) 70 setNext(block + i * this->objectSize_, block + (i + 1) * this->objectSize_); 95 // iterate through the chunks in the new memory block and link them together to a single linked list 96 for (size_t i = 1; i < this->numChunksPerBlock_ - 1; ++i) 97 setNext(block + i * this->chunkSize_, block + (i + 1) * this->chunkSize_); 71 98 72 setNext(block + (this->numObjects_ - 1) * this->objectSize_, 0); 99 // the next_ pointer of the last chunk must point to NULL 100 setNext(block + (this->numChunksPerBlock_ - 1) * this->chunkSize_, 0); 73 101 74 this->first_ = block + this->objectSize_; 102 // The second chunk in the block is assigned to the first_ pointer 103 this->first_ = block + this->chunkSize_; 75 104 105 // The first chunk in the block is returned 76 106 chunk = block; 77 107 } 78 108 109 // return the pointer to the chunk 79 110 return chunk; 80 111 } 81 112 113 /** 114 @brief Puts the memory chunk back on the list of free memory. 115 */ 82 116 void SmallObjectAllocator::free(void* chunk) 83 117 { 118 // The first_ pointer points to the freed chunk, its next_ pointer points to the rest of the list 84 119 setNext(chunk, this->first_); 85 120 this->first_ = chunk; -
code/trunk/src/libraries/util/SmallObjectAllocator.h
r7284 r7401 27 27 */ 28 28 29 /** 30 @defgroup SmallObjectAllocator SmallObjectAllocator 31 @ingroup Util 32 */ 33 34 /** 35 @file 36 @ingroup SmallObjectAllocator 37 @brief Declaration of SmallObjectAllocator 38 39 @anchor SmallObjectAllocatorExample 40 41 The default implementations of new and delete are designed to work with objects of 42 arbitrary size. They are thus not optimal for small objects. 43 @ref orxonox::SmallObjectAllocator "SmallObjectAllocator" allocates a large memory 44 block and divides it into small chunks. These chunks are returned by the function 45 @ref orxonox::SmallObjectAllocator::alloc() "alloc()" and can be used to create a 46 new object using the placement new operator. Instead of delete, the function 47 @ref orxonox::SmallObjectAllocator::free() "free()" is used to give the memory 48 back to SmallObjectAllocator. 49 50 Example: 51 @code 52 SmallObjectAllocator allocator(sizeof(MySmallObject)); // Create an allocator. The size of the memory chunks must equal the size of the desired class 53 54 void* chunk = allocator.alloc(); // Allocate a memory chunk 55 MySmallObject* object = new (chunk) MySmallObject(); // Call the placement new operator 56 57 object->someFunction(); // Do something with the object 58 59 object->~MySmallObject(); // Call the destructor 60 allocator.free(object); // Free the allocated memory 61 @endcode 62 63 @b Important: You have to call the destructor of the object manually, because this 64 is not automatically done by the allocator nor free(). 65 66 @note The destructor can be ignored if it is empty or not implemented. This saves 67 another amount of time. 68 69 @remarks For a distributed usage of SmallObjectAllocator it may be a good idea to 70 create a static function that returns an instance to it. The allocator then works 71 like a singleton and can be accesses from everywhere. 72 */ 73 29 74 #ifndef _SmallObjectAllocator_H__ 30 75 #define _SmallObjectAllocator_H__ … … 35 80 namespace orxonox 36 81 { 82 /** 83 @brief This class is used to allocate and free small objects (usually not polymorphic). 84 85 SmallObjectAllocator provides a fast alternative to new and delete for small objects. 86 87 @see See @ref SmallObjectAllocatorExample "this description" for more information and an example. 88 */ 37 89 class _UtilExport SmallObjectAllocator 38 90 { 91 /// The memory chunk is at the same time an element of a single linked list. 39 92 struct Chunk 40 93 { 41 Chunk* next_; 94 Chunk* next_; ///< A pointer to the next chunk in the list 42 95 }; 43 96 … … 53 106 static void* getNext(void* chunk); 54 107 55 void* first_; 56 size_t objectSize_;57 size_t num Objects_;108 void* first_; ///< A pointer to the first free memory chunk 109 size_t chunkSize_; ///< The size of each chunk (and usually also the size of the created objects) 110 size_t numChunksPerBlock_; ///< The number of chunks per memory block 58 111 59 std::vector<char*> blocks_; 112 std::vector<char*> blocks_; ///< A list of all allocated memory blocks (used to destroy them again) 60 113 }; 61 114 } -
code/trunk/src/libraries/util/StringUtils.cc
r7284 r7401 41 41 namespace orxonox 42 42 { 43 /// A blank string (""). Used to return a blank string by reference. 43 44 std::string BLANKSTRING; 44 45 46 /// Returns a string of a unique number. This function is guaranteed to never return the same string twice. 45 47 std::string getUniqueNumberString() 46 48 { … … 48 50 } 49 51 50 /** 51 @brief Removes all whitespaces from a string. 52 @param str The string to strip 53 */ 52 /// Removes all whitespaces from a string. 54 53 void strip(std::string* str) 55 54 { … … 63 62 } 64 63 65 /** 66 @brief Returns a copy of a string without whitespaces. 67 @param str The string to strip 68 @return The stripped line 69 */ 64 /// Returns a copy of a string without whitespaces. 70 65 std::string getStripped(const std::string& str) 71 66 { … … 75 70 } 76 71 77 /** 78 @brief Returns a copy of a string without trailing whitespaces. 79 @param str The string 80 @return The modified copy 81 */ 72 /// Returns a copy of a string without trailing whitespaces. 82 73 std::string removeTrailingWhitespaces(const std::string& str) 83 74 { … … 90 81 91 82 /** 92 @brief Returns the position of the next quot ein the string, starting with start.83 @brief Returns the position of the next quotation mark in the string, starting with start. 93 84 @param str The string 94 @param start The startposition95 @return The position of the next quot e (std::string::npos if there is no next quote)85 @param start The first position to look at 86 @return The position of the next quotation mark (@c std::string::npos if there is none) 96 87 */ 97 88 size_t getNextQuote(const std::string& str, size_t start) … … 115 106 116 107 /** 117 @brief Returns true if pos is between two quot es.108 @brief Returns true if pos is between two quotation marks. 118 109 @param str The string 119 110 @param pos The position to check 120 @return True if pos is between two quot es111 @return True if pos is between two quotation marks 121 112 */ 122 113 bool isBetweenQuotes(const std::string& str, size_t pos) … … 140 131 } 141 132 142 /** 143 @brief Returns true if the string contains something like '..."between quotes"...'. 144 @param The string 145 @return True if there is something between quotes 146 */ 133 /// Returns true if the string contains something like '..."between quotaton marks"...'. 147 134 bool hasStringBetweenQuotes(const std::string& str) 148 135 { … … 152 139 } 153 140 154 /** 155 @brief If the string contains something like '..."between quotes"...' then 'between quotes' gets returned (without quotes). 156 @param The string 157 @param The string between the quotes 158 */ 141 /// If the string contains something like '..."between quotaton marks"...' then 'between quotaton marks' gets returned, otherwise "". 159 142 std::string getStringBetweenQuotes(const std::string& str) 160 143 { … … 168 151 169 152 /** 170 @brief Removes enclosing quotes if available (including whitespaces at the outside of the quotes). 171 @brief str The string to strip 172 @return The string with removed quotes 153 @brief Removes enclosing quotation marks if available (including whitespaces at the outside of the quotation marks). 154 @return The striped string without quotation marks 173 155 */ 174 156 std::string stripEnclosingQuotes(const std::string& str) … … 208 190 209 191 /** 210 @brief Removes enclosing {braces} (braces must be exactly on the beginning and the end of the string). 211 @param str The string to strip 212 @return The striped string 192 @brief Removes enclosing braces '{' and '}' (the braces must be exactly on the beginning and the end of the string). 193 @return The striped string without braces 213 194 */ 214 195 std::string stripEnclosingBraces(const std::string& str) … … 224 205 /** 225 206 @brief Determines if a string is a comment (starts with a comment-symbol). 226 @param str The string to check227 @return True = it's a comment228 207 229 208 A comment is defined by a leading '#', '%', ';' or '//'. … … 253 232 } 254 233 255 /** 256 @brief Determines if a string is empty (contains only whitespaces). 257 @param str The string to check 258 @return True = it's empty 259 */ 234 /// Determines if a string is empty (contains only whitespaces). 260 235 bool isEmpty(const std::string& str) 261 236 { … … 263 238 } 264 239 265 /** 266 @brief Determines if a string contains only numbers and maximal one '.'. 267 @param str The string to check 268 @return True = it's a number 269 */ 240 /// Determines if a string contains only numbers and maximal one '.'. 270 241 bool isNumeric(const std::string& str) 271 242 { … … 288 259 /** 289 260 @brief Adds backslashes to the given string which makes special chars visible. Existing slashes will be doubled. 290 @param str The string to manipulate 291 @return The string with added slashes 261 262 This function converts all special chars like line breaks, tabs, quotation marks etc. into 263 a human readable format by adding a backslash. So for example "\n" will be converted to 264 "\\" + "n". 265 266 This is usually used when a string is written to a file. 267 268 @see removeSlashes 292 269 */ 293 270 std::string addSlashes(const std::string& str) … … 320 297 /** 321 298 @brief Removes backslashes from the given string. Double backslashes are interpreted as one backslash. 322 @param str The string to manipulate 323 @return The string with removed slashes 299 300 This function removes all backslashes and converts the human readable equivalents of 301 special chars like "\\" + "n" into their real meaning (in this case a line break or "\n"). 302 303 This is usually used when reading a string from a file. 304 305 @see addSlashes 324 306 */ 325 307 std::string removeSlashes(const std::string& str) … … 361 343 } 362 344 363 /** 364 @brief Replaces each char between A and Z with its lowercase equivalent. 365 @param str The string to convert 366 */ 345 /// Replaces each char between A and Z with its lowercase equivalent. 367 346 void lowercase(std::string* str) 368 347 { … … 373 352 } 374 353 375 /** 376 @brief Returns a copy of the given string without uppercase chars. 377 @param str The string 378 @return The copy 379 */ 354 /// Returns a copy of the given string where all chars are converted to lowercase. 380 355 std::string getLowercase(const std::string& str) 381 356 { … … 385 360 } 386 361 387 /** 388 @brief Replaces each char between a and z with its uppercase equivalent. 389 @param str The string to convert 390 */ 362 /// Replaces each char between a and z with its uppercase equivalent. 391 363 void uppercase(std::string* str) 392 364 { … … 397 369 } 398 370 399 /** 400 @brief Returns a copy of the given string without lowercase chars. 401 @param str The string 402 @return The copy 403 */ 371 /// Returns a copy of the given string where all chars are converted to uppercase. 404 372 std::string getUppercase(const std::string& str) 405 373 { … … 411 379 /** 412 380 @brief Compares two strings ignoring different casing. 413 @param s1 First string 414 @param s2 Second string 381 @return s1 == s1 -> returns 0 / s1 < s2 -> returns -1 / s1 >= s2 -> returns 1 415 382 */ 416 383 int nocaseCmp(const std::string& s1, const std::string& s2) … … 438 405 439 406 /** 440 @brief Compares the first 'len'chars of two strings ignoring different casing.407 @brief Compares the first @a len chars of two strings ignoring different casing. 441 408 @param s1 First string 442 409 @param s2 Second string … … 463 430 } 464 431 465 /** 466 @brief Returns true if the string contains a comment, introduced by #, %, ; or //. 432 /// Returns true if the string contains a comment, introduced by #, %, ; or //. 433 bool hasComment(const std::string& str) 434 { 435 return (getCommentPosition(str) != std::string::npos); 436 } 437 438 /// If the string contains a comment, the comment gets returned (including the comment symbol), an empty string otherwise. 439 std::string getComment(const std::string& str) 440 { 441 return str.substr(getCommentPosition(str)); 442 } 443 444 /// If the string contains a comment, the position of the comment-symbol gets returned, @c std::string::npos otherwise. 445 size_t getCommentPosition(const std::string& str) 446 { 447 return getNextCommentPosition(str, 0); 448 } 449 450 /** 451 @brief Returns the position of the next comment-symbol, starting with @a start. 467 452 @param str The string 468 @return True if the string contains a comment 469 */ 470 bool hasComment(const std::string& str) 471 { 472 return (getCommentPosition(str) != std::string::npos); 473 } 474 475 /** 476 @brief If the string contains a comment, the comment gets returned (including the comment symbol), an empty string otherwise. 477 @param str The string 478 @return The comment 479 */ 480 std::string getComment(const std::string& str) 481 { 482 return str.substr(getCommentPosition(str)); 483 } 484 485 /** 486 @brief If the string contains a comment, the position of the comment-symbol gets returned, std::string::npos otherwise. 487 @param str The string 488 @return The position 489 */ 490 size_t getCommentPosition(const std::string& str) 491 { 492 return getNextCommentPosition(str, 0); 493 } 494 495 /** 496 @brief Returns the position of the next comment-symbol, starting with start. 497 @param str The string 498 @param start The startposition 499 @return The position 453 @param start The first position to look at 500 454 */ 501 455 size_t getNextCommentPosition(const std::string& str, size_t start) -
code/trunk/src/libraries/util/StringUtils.h
r7284 r7401 28 28 29 29 /** 30 @defgroup String String functions 31 @ingroup Util 32 */ 33 34 /** 30 35 @file 36 @ingroup String 31 37 @brief Declaration of several string manipulation functions, used in many parts of the game. 32 38 */ -
code/trunk/src/libraries/util/SubString.cc
r7284 r7401 38 38 */ 39 39 40 /** 41 @file 42 @brief Implementation of the SubString class. 43 */ 44 40 45 #include "SubString.h" 41 46 #include <cstdio> 47 #include "Debug.h" 42 48 43 49 namespace orxonox 44 50 { 45 /** 46 * @brief default constructor 47 */ 51 const std::string SubString::WhiteSpaces = " \n\t"; 52 const std::string SubString::WhiteSpacesWithComma = " \n\t,"; 53 const SubString SubString::NullSubString = SubString(); 54 55 /** 56 @brief Default constructor. 57 */ 48 58 SubString::SubString() 49 {} 50 51 52 /** 53 * @brief create a SubString from 54 * @param string the String to Split 55 * @param delimiter the Character at which to split string (delimiter) 56 */ 57 SubString::SubString(const std::string& string, char delimiter) 58 { 59 this->split(string, delimiter); 60 } 61 62 63 /** 64 * @brief Splits a String into multiple splitters. 65 * @param string the String to split 66 * @param delimiters multiple set of characters at what to split. (delimiters) 67 * @param delimiterNeighbours neighbours of the delimiters, that will be erased only when near a delimiter. 68 * @param emptyEntries If empty entries should be allewed or removed. 69 * @param escapeChar The Escape Character that overrides splitters commends and so on... 70 * @param safemode_char within these characters splitting won't happen 71 * @param comment_char the Comment character. 72 */ 73 SubString::SubString(const std::string& string, 74 const std::string& delimiters, const std::string& delimiterNeighbours, bool emptyEntries, 75 char escapeChar, bool removeEscapeChar, char safemode_char, bool removeSafemodeChar, 76 char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, char comment_char) 77 { 78 SubString::splitLine(this->strings, this->bInSafemode, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, removeEscapeChar, safemode_char, removeSafemodeChar, openparenthesis_char, closeparenthesis_char, removeParenthesisChars, comment_char); 79 } 80 81 /** 82 * @brief creates a SubSet of a SubString. 83 * @param subString the SubString to take a set from. 84 * @param subSetBegin the beginning to the end 85 */ 86 SubString::SubString(const SubString& subString, unsigned int subSetBegin) 87 { 88 for (unsigned int i = subSetBegin; i < subString.size(); i++) 89 { 90 this->strings.push_back(subString[i]); 91 this->bInSafemode.push_back(subString.isInSafemode(i)); 92 } 93 } 94 95 96 /** 97 * @brief creates a SubSet of a SubString. 98 * @param subString the SubString to take a Set from 99 * @param subSetBegin the beginning to the end 100 * @param subSetEnd the end of the SubSet (max subString.size() will be checked internaly) 101 */ 102 SubString::SubString(const SubString& subString, unsigned int subSetBegin, unsigned int subSetEnd) 103 { 104 for (unsigned int i = subSetBegin; i < subString.size() && i < subSetEnd; i++) 105 { 106 this->strings.push_back(subString[i]); 107 this->bInSafemode.push_back(subString.isInSafemode(i)); 108 } 109 } 110 111 /** 112 * @brief creates a Substring from a count and values set. 113 * @param argc: the Arguments Count. 114 * @param argv: Argument Values. 115 */ 59 { 60 } 61 62 /** 63 @brief Splits a string into multiple tokens. 64 @param line The line to split 65 @param delimiters Multiple characters at which to split the line 66 @param delimiterNeighbours Neighbours of the delimiters that will be erased as well (for example white-spaces) 67 @param bAllowEmptyEntries If true, empty tokens are also added to the SubString (if there are two delimiters without a char in between) 68 @param escapeChar The escape character that is used to escape safemode chars (for example if you want to use a quotation mark between two other quotation marks). 69 @param bRemoveEscapeChar If true, the escape char is removed from the tokens 70 @param safemodeChar Within these characters splitting won't happen (usually the quotation marks) 71 @param bRemoveSafemodeChar Removes the safemodeChar from the beginning and the ending of a token 72 @param openparenthesisChar The beginning of a safemode is marked with this (usually an opening brace) 73 @param closeparenthesisChar The ending of a safemode is marked with this (usually a closing brace) 74 @param bRemoveParenthesisChars Removes the parenthesis chars from the beginning and the ending of a token 75 @param commentChar The comment character (used to ignore the part of the line after the comment char). 76 */ 77 SubString::SubString(const std::string& line, 78 const std::string& delimiters, const std::string& delimiterNeighbours, bool bAllowEmptyEntries, 79 char escapeChar, bool bRemoveEscapeChar, char safemodeChar, bool bRemoveSafemodeChar, 80 char openparenthesisChar, char closeparenthesisChar, bool bRemoveParenthesisChars, char commentChar) 81 { 82 SubString::splitLine(this->tokens_, this->bTokenInSafemode_, line, delimiters, delimiterNeighbours, bAllowEmptyEntries, escapeChar, bRemoveEscapeChar, safemodeChar, bRemoveSafemodeChar, openparenthesisChar, closeparenthesisChar, bRemoveParenthesisChars, commentChar); 83 } 84 85 /** 86 @brief creates a new SubString based on a subset of an other SubString. 87 @param other The other SubString 88 @param begin The beginning of the subset 89 90 The subset ranges from the token with index @a begin to the end of the tokens. 91 If @a begin is greater than the greatest index, the new SubString will be empty. 92 */ 93 SubString::SubString(const SubString& other, unsigned int begin) 94 { 95 for (unsigned int i = begin; i < other.size(); ++i) 96 { 97 this->tokens_.push_back(other[i]); 98 this->bTokenInSafemode_.push_back(other.isInSafemode(i)); 99 } 100 } 101 102 /** 103 @brief creates a new SubString based on a subset of an other SubString. 104 @param other The other SubString 105 @param begin The beginning of the subset 106 @param end The end of the subset 107 108 The subset ranges from the token with index @a begin until (but not including) the token with index @a end. 109 If @a begin or @a end are beyond the allowed index, the resulting SubString will be empty. 110 */ 111 SubString::SubString(const SubString& other, unsigned int begin, unsigned int end) 112 { 113 for (unsigned int i = begin; i < std::min(other.size(), end); ++i) 114 { 115 this->tokens_.push_back(other[i]); 116 this->bTokenInSafemode_.push_back(other.isInSafemode(i)); 117 } 118 } 119 120 /** 121 @brief Creates a SubString from a count and values set. 122 @param argc The number of arguments 123 @param argv An array of pointers to the arguments 124 */ 116 125 SubString::SubString(unsigned int argc, const char** argv) 117 126 { 118 127 for(unsigned int i = 0; i < argc; ++i) 119 128 { 120 this-> strings.push_back(std::string(argv[i]));121 this->b InSafemode.push_back(false);122 } 123 } 124 125 /** 126 * @brief removes the object from memory127 129 this->tokens_.push_back(std::string(argv[i])); 130 this->bTokenInSafemode_.push_back(false); 131 } 132 } 133 134 /** 135 @brief Destructor 136 */ 128 137 SubString::~SubString() 129 138 { } 130 139 131 /** @brief An empty String */ 132 // const std::string SubString::emptyString = ""; 133 /** @brief Helper that gets you a String consisting of all White Spaces */ 134 const std::string SubString::WhiteSpaces = " \n\t"; 135 /** @brief Helper that gets you a String consisting of all WhiteSpaces and the Comma */ 136 const std::string SubString::WhiteSpacesWithComma = " \n\t,"; 137 /** An Empty SubString */ 138 const SubString SubString::NullSubString = SubString(); 139 140 /** 141 * @brief stores the Value of subString in this SubString 142 * @param subString will be copied into this String. 143 * @returns this SubString. 144 */ 145 SubString& SubString::operator=(const SubString& subString) 146 { 147 this->strings = subString.strings; 148 this->bInSafemode = subString.bInSafemode; 140 /** 141 @brief Stores the tokens of @a other in this SubString 142 @return This SubString. 143 */ 144 SubString& SubString::operator=(const SubString& other) 145 { 146 this->tokens_ = other.tokens_; 147 this->bTokenInSafemode_ = other.bTokenInSafemode_; 149 148 return *this; 150 149 } 151 150 152 153 /** 154 * @brief comparator. 155 * @param subString the SubString to compare against this one. 156 * @returns true if the Stored Strings match 157 */ 158 bool SubString::operator==(const SubString& subString) const 159 { 160 return ((this->strings == subString.strings) && (this->bInSafemode == subString.bInSafemode)); 161 } 162 163 /** 164 * @brief comparator. 165 * @param subString the SubString to compare against this one. 166 * @returns true if the Stored Strings match 167 */ 168 bool SubString::compare(const SubString& subString) const 169 { 170 return (*this == subString); 171 } 172 173 /** 174 * @brief comparator. 175 * @param subString the SubString to compare against this one. 176 * @param length how many entries to compare. (from 0 to length) 177 * @returns true if the Stored Strings match 178 */ 179 bool SubString::compare(const SubString& subString, unsigned int length) const 180 { 181 if (length > this->size() || length > subString.size()) 151 /** 152 @brief Compares this SubString to another SubString and returns true if they contain the same values. 153 */ 154 bool SubString::operator==(const SubString& other) const 155 { 156 return ((this->tokens_ == other.tokens_) && (this->bTokenInSafemode_ == other.bTokenInSafemode_)); 157 } 158 159 /** 160 @copydoc operator== 161 */ 162 bool SubString::compare(const SubString& other) const 163 { 164 return (*this == other); 165 } 166 167 /** 168 @brief Compares this SubString to another SubString and returns true if the first @a length values match. 169 @param other The other SubString 170 @param length How many tokens to compare 171 */ 172 bool SubString::compare(const SubString& other, unsigned int length) const 173 { 174 if (length > this->size() || length > other.size()) 182 175 return false; 183 176 184 for (unsigned int i = 0; i < length; i++)185 if ((this-> strings[i] != subString.strings[i]) || (this->bInSafemode[i] != subString.bInSafemode[i]))177 for (unsigned int i = 0; i < length; ++i) 178 if ((this->tokens_[i] != other.tokens_[i]) || (this->bTokenInSafemode_[i] != other.bTokenInSafemode_[i])) 186 179 return false; 187 180 return true; 188 181 } 189 182 190 191 /** 192 * @brief append operator 193 * @param subString the String to append. 194 * @returns a SubString where this and subString are appended. 195 */ 196 SubString SubString::operator+(const SubString& subString) const 197 { 198 return SubString(*this) += subString; 199 } 200 201 202 /** 203 * @brief append operator. 204 * @param subString append subString to this SubString. 205 * @returns this substring appended with subString 206 */ 207 SubString& SubString::operator+=(const SubString& subString) 208 { 209 for (unsigned int i = 0; i < subString.size(); i++) 210 { 211 this->strings.push_back(subString[i]); 212 this->bInSafemode.push_back(subString.isInSafemode(i)); 183 /** 184 @brief Concatenates the tokens of two SubStrings and returns the resulting new SubString 185 @return A new SubString that contains the tokens of this and the other SubString 186 */ 187 SubString SubString::operator+(const SubString& other) const 188 { 189 return SubString(*this) += other; 190 } 191 192 /** 193 @brief Appends the tokens of @a other to this SubString 194 @return This SubString 195 */ 196 SubString& SubString::operator+=(const SubString& other) 197 { 198 for (unsigned int i = 0; i < other.size(); ++i) 199 { 200 this->tokens_.push_back(other[i]); 201 this->bTokenInSafemode_.push_back(other.isInSafemode(i)); 213 202 } 214 203 return *this; 215 204 } 216 205 217 218 /** 219 * @brief Split the String at 220 * @param string where to split 221 * @param splitter delimiter. 222 */ 223 unsigned int SubString::split(const std::string& string, char splitter) 224 { 225 this->strings.clear(); 226 this->bInSafemode.clear(); 227 char split[2]; 228 split[0] = splitter; 229 split[1] = '\0'; 230 SubString::splitLine(this->strings, this->bInSafemode, string, split); 231 return strings.size(); 232 } 233 234 235 /** 236 * @brief Splits a String into multiple splitters. 237 * @param string the String to split 238 * @param delimiters multiple set of characters at what to split. (delimiters) 239 * @param delimiterNeighbours: Neighbours to the Delimiters that will be erased too. 240 * @param emptyEntries: If empty entries are added to the List of SubStrings 241 * @param escapeChar The Escape Character that overrides splitters commends and so on... 242 * @param safemode_char within these characters splitting won't happen 243 * @param comment_char the Comment character. 244 */ 245 unsigned int SubString::split(const std::string& string, 246 const std::string& delimiters, const std::string& delimiterNeighbours, bool emptyEntries, 247 char escapeChar, bool removeExcapeChar, char safemode_char, bool removeSafemodeChar, 248 char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, char comment_char) 249 { 250 this->strings.clear(); 251 this->bInSafemode.clear(); 252 SubString::splitLine(this->strings, this->bInSafemode, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, removeExcapeChar, safemode_char, removeSafemodeChar, openparenthesis_char, closeparenthesis_char, removeParenthesisChars, comment_char); 253 return this->strings.size(); 254 } 255 256 257 /** 258 * @brief joins together all Strings of this Substring. 259 * @param delimiter the String between the subStrings. 260 * @returns the joined String. 261 */ 206 /** 207 @copydoc SubString(const std::string&,const std::string&,const std::string&,bool,char,bool,char,bool,char,char,bool,char) 208 */ 209 unsigned int SubString::split(const std::string& line, 210 const std::string& delimiters, const std::string& delimiterNeighbours, bool bAllowEmptyEntries, 211 char escapeChar, bool bRemoveEscapeChar, char safemodeChar, bool bRemoveSafemodeChar, 212 char openparenthesisChar, char closeparenthesisChar, bool bRemoveParenthesisChars, char commentChar) 213 { 214 this->tokens_.clear(); 215 this->bTokenInSafemode_.clear(); 216 SubString::splitLine(this->tokens_, this->bTokenInSafemode_, line, delimiters, delimiterNeighbours, bAllowEmptyEntries, escapeChar, bRemoveEscapeChar, safemodeChar, bRemoveSafemodeChar, openparenthesisChar, closeparenthesisChar, bRemoveParenthesisChars, commentChar); 217 return this->tokens_.size(); 218 } 219 220 /** 221 @brief Joins the tokens of this SubString using the given delimiter and returns a string. 222 @param delimiter This delimiter will be placed between each two tokens 223 @return The joined string. 224 */ 262 225 std::string SubString::join(const std::string& delimiter) const 263 226 { 264 if (!this-> strings.empty())265 { 266 std::string retVal = this-> strings[0];267 for (unsigned int i = 1; i < this-> strings.size(); i++)268 retVal += delimiter + this-> strings[i];227 if (!this->tokens_.empty()) 228 { 229 std::string retVal = this->tokens_[0]; 230 for (unsigned int i = 1; i < this->tokens_.size(); ++i) 231 retVal += delimiter + this->tokens_[i]; 269 232 return retVal; 270 233 } … … 273 236 } 274 237 275 276 /** 277 * @brief creates a SubSet of a SubString. 278 * @param subSetBegin the beginning to the end 279 * @returns the SubSet 280 * 281 * This function is added for your convenience, and does the same as 282 * SubString::SubString(const SubString& subString, unsigned int subSetBegin) 283 */ 284 SubString SubString::subSet(unsigned int subSetBegin) const 285 { 286 return SubString(*this, subSetBegin); 287 } 288 289 290 /** 291 * @brief creates a SubSet of a SubString. 292 * @param subSetBegin the beginning to 293 * @param subSetEnd the end of the SubSet to select (if bigger than subString.size() it will be downset.) 294 * @returns the SubSet 295 * 296 * This function is added for your convenience, and does the same as 297 * SubString::SubString(const SubString& subString, unsigned int subSetBegin) 298 */ 299 SubString SubString::subSet(unsigned int subSetBegin, unsigned int subSetEnd) const 300 { 301 return SubString(*this, subSetBegin, subSetEnd); 302 } 303 304 305 /** 306 * @brief splits line into tokens and stores them in ret. 307 * @param ret the Array, where the Splitted strings will be stored in 308 * to the beginning of the current token is stored 309 * @param line the inputLine to split 310 * @param delimiters a String of Delimiters (here the input will be splitted) 311 * @param delimiterNeighbours Neighbours to the Delimiter, that will be removed if they are to the left or the right of a Delimiter. 312 * @param emptyEntries: if empty Strings are added to the List of Strings. 313 * @param escape_char: Escape carater (escapes splitters) 314 * @param safemode_char: the beginning of the safemode is marked with this 315 * @param removeSafemodeChar removes the safemode_char from the beginning and the ending of a token 316 * @param openparenthesis_char the beginning of a safemode is marked with this 317 * @param closeparenthesis_char the ending of a safemode is marked with this 318 * @param removeParenthesisChars removes the parenthesis from the beginning and the ending of a token 319 * @param comment_char: the beginning of a comment is marked with this: (until the end of a Line) 320 * @param start_state: the Initial state on how to parse the String. 321 * @return SPLIT_LINE_STATE the parser was in when returning 322 * 323 * This is the Actual Splitting Algorithm from Clemens Wacha 324 * Supports delimiters, escape characters, 325 * ignores special characters between safemode_char and between comment_char and linend '\n'. 326 */ 238 /** 239 @brief Creates a subset of this SubString. 240 @param begin The beginning of the subset 241 @return A new SubString containing the defined subset. 242 243 The subset ranges from the token with index @a begin to the end of the tokens. 244 If @a begin is greater than the greatest index, the new SubString will be empty. 245 246 This function is added for your convenience, and does the same as 247 SubString::SubString(const SubString& other, unsigned int begin) 248 */ 249 SubString SubString::subSet(unsigned int begin) const 250 { 251 return SubString(*this, begin); 252 } 253 254 /** 255 @brief Creates a subset of this SubString. 256 @param begin The beginning of the subset 257 @param end The ending of the subset 258 @return A new SubString containing the defined subset. 259 260 The subset ranges from the token with index @a begin until (but not including) the token with index @a end. 261 If @a begin or @a end are beyond the allowed index, the resulting SubString will be empty. 262 263 This function is added for your convenience, and does the same as 264 SubString::SubString(const SubString& other, unsigned int begin, unsigned int end) 265 */ 266 SubString SubString::subSet(unsigned int begin, unsigned int end) const 267 { 268 return SubString(*this, begin, end); 269 } 270 271 /** 272 @copydoc SubString(const std::string&,const std::string&,const std::string&,bool,char,bool,char,bool,char,char,bool,char) 273 @param tokens The array, where the splitted strings will be stored in 274 @param bTokenInSafemode A vector wich stores for each character of the string if it is in safemode or not 275 @param start_state The internal state of the parser 276 277 This is the actual splitting algorithm from Clemens Wacha. 278 Supports delimiters, escape characters, ignores special characters between safemodeChar and between commentChar and line end "\n". 279 280 Extended by Orxonox to support parenthesis as additional safe-mode. 281 */ 327 282 SubString::SPLIT_LINE_STATE 328 SubString::splitLine(std::vector<std::string>& ret,329 std::vector<bool>& b InSafemode,283 SubString::splitLine(std::vector<std::string>& tokens, 284 std::vector<bool>& bTokenInSafemode, 330 285 const std::string& line, 331 286 const std::string& delimiters, 332 287 const std::string& delimiterNeighbours, 333 bool emptyEntries,334 char escape _char,335 bool removeExcapeChar,336 char safemode _char,337 bool removeSafemodeChar,338 char openparenthesis _char,339 char closeparenthesis _char,340 bool removeParenthesisChars,341 char comment _char,288 bool bAllowEmptyEntries, 289 char escapeChar, 290 bool bRemoveEscapeChar, 291 char safemodeChar, 292 bool bRemoveSafemodeChar, 293 char openparenthesisChar, 294 char closeparenthesisChar, 295 bool bRemoveParenthesisChars, 296 char commentChar, 342 297 SPLIT_LINE_STATE start_state) 343 298 { … … 349 304 bool inSafemode = false; 350 305 351 if(start_state != SL_NORMAL && ret.size() > 0)352 { 353 token = ret[ret.size()-1];354 ret.pop_back();355 } 356 if(start_state != SL_NORMAL && b InSafemode.size() > 0)357 { 358 inSafemode = b InSafemode[bInSafemode.size()-1];359 b InSafemode.pop_back();306 if(start_state != SL_NORMAL && tokens.size() > 0) 307 { 308 token = tokens[tokens.size()-1]; 309 tokens.pop_back(); 310 } 311 if(start_state != SL_NORMAL && bTokenInSafemode.size() > 0) 312 { 313 inSafemode = bTokenInSafemode[bTokenInSafemode.size()-1]; 314 bTokenInSafemode.pop_back(); 360 315 } 361 316 … … 365 320 { 366 321 case SL_NORMAL: 367 if(line[i] == escape _char)322 if(line[i] == escapeChar) 368 323 { 369 324 state = SL_ESCAPE; 370 if (! removeExcapeChar)325 if (!bRemoveEscapeChar) 371 326 token += line[i]; 372 } 373 else if(line[i] == safemode_char) 327 fallBackNeighbours = 0; 328 } 329 else if(line[i] == safemodeChar) 374 330 { 375 331 state = SL_SAFEMODE; 376 332 inSafemode = true; 377 if (! removeSafemodeChar)333 if (!bRemoveSafemodeChar) 378 334 token += line[i]; 379 } 380 else if(line[i] == openparenthesis_char) 335 fallBackNeighbours = 0; 336 } 337 else if(line[i] == openparenthesisChar) 381 338 { 382 339 state = SL_PARENTHESES; 383 340 inSafemode = true; 384 if (! removeParenthesisChars)341 if (!bRemoveParenthesisChars) 385 342 token += line[i]; 386 } 387 else if(line[i] == comment_char) 343 fallBackNeighbours = 0; 344 } 345 else if(line[i] == commentChar) 388 346 { 389 347 if (fallBackNeighbours > 0) 390 348 token = token.substr(0, token.size() - fallBackNeighbours); 391 /// FINISH 392 if(emptyEntries || token.size() > 0) 349 fallBackNeighbours = 0; 350 // FINISH 351 if(bAllowEmptyEntries || token.size() > 0) 393 352 { 394 ret.push_back(token);353 tokens.push_back(token); 395 354 token.clear(); 396 b InSafemode.push_back(inSafemode);355 bTokenInSafemode.push_back(inSafemode); 397 356 inSafemode = false; 398 357 } … … 405 364 if (fallBackNeighbours > 0) 406 365 token = token.substr(0, token.size() - fallBackNeighbours); 407 /// FINISH 408 if(emptyEntries || token.size() > 0) 366 fallBackNeighbours = 0; 367 // FINISH 368 if(bAllowEmptyEntries || token.size() > 0) 409 369 { 410 ret.push_back(token);370 tokens.push_back(token); 411 371 token.clear(); 412 b InSafemode.push_back(inSafemode);372 bTokenInSafemode.push_back(inSafemode); 413 373 inSafemode = false; 414 374 } … … 423 383 else 424 384 { 425 i++;385 ++i; 426 386 continue; 427 387 } … … 433 393 break; 434 394 case SL_ESCAPE: 435 if (! removeSafemodeChar)395 if (!bRemoveSafemodeChar) 436 396 token += line[i]; 437 397 else … … 450 410 break; 451 411 case SL_SAFEMODE: 452 if(line[i] == safemode _char)412 if(line[i] == safemodeChar) 453 413 { 454 414 state = SL_NORMAL; 455 if (! removeSafemodeChar)415 if (!bRemoveSafemodeChar) 456 416 token += line[i]; 457 417 } 458 else if(line[i] == escape _char)418 else if(line[i] == escapeChar) 459 419 { 460 420 state = SL_SAFEESCAPE; … … 480 440 481 441 case SL_PARENTHESES: 482 if(line[i] == closeparenthesis _char)442 if(line[i] == closeparenthesisChar) 483 443 { 484 444 state = SL_NORMAL; 485 if (! removeParenthesisChars)445 if (!bRemoveParenthesisChars) 486 446 token += line[i]; 487 447 } 488 else if(line[i] == escape _char)448 else if(line[i] == escapeChar) 489 449 { 490 450 state = SL_PARENTHESESESCAPE; … … 512 472 if(line[i] == '\n') 513 473 { 514 // /FINISH474 // FINISH 515 475 if(token.size() > 0) 516 476 { 517 ret.push_back(token);477 tokens.push_back(token); 518 478 token.clear(); 519 b InSafemode.push_back(inSafemode);479 bTokenInSafemode.push_back(inSafemode); 520 480 inSafemode = false; 521 481 } … … 532 492 break; 533 493 } 534 i++;535 } 536 537 // /FINISH494 ++i; 495 } 496 497 // FINISH 538 498 if (fallBackNeighbours > 0) 539 499 token = token.substr(0, token.size() - fallBackNeighbours); 540 if( emptyEntries || token.size() > 0)541 { 542 ret.push_back(token);500 if(bAllowEmptyEntries || token.size() > 0) 501 { 502 tokens.push_back(token); 543 503 token.clear(); 544 b InSafemode.push_back(inSafemode);504 bTokenInSafemode.push_back(inSafemode); 545 505 inSafemode = false; 546 506 } … … 548 508 } 549 509 550 551 /** 552 * @brief Some nice debug information about this SubString 553 */ 510 /** 511 @brief Some nice debug information about this SubString. 512 */ 554 513 void SubString::debug() const 555 514 { 556 printf("Substring-information::count=%d ::", this->strings.size());557 for (unsigned int i = 0; i < this-> strings.size(); i++)558 printf("s%d='%s'::", i, this->strings[i].c_str());559 printf("\n");515 COUT(0) << "Substring-information::count=" << this->tokens_.size() << " ::"; 516 for (unsigned int i = 0; i < this->tokens_.size(); ++i) 517 COUT(0) << "s" << i << "='" << this->tokens_[i].c_str() << "'::"; 518 COUT(0) << std::endl; 560 519 } 561 520 } -
code/trunk/src/libraries/util/SubString.h
r7284 r7401 37 37 */ 38 38 39 /*! 40 * @file 41 * @brief a small class to get the parts of a string separated by commas 42 * 43 * This class is also identified as a Tokenizer. It splits up one long 44 * String into multiple small ones by a designated Delimiter. 45 * 46 * Substring is Advanced, and it is possible, to split a string by ',' 47 * but also removing leading and trailing spaces around the comma. 48 * 49 * @example 50 * Split the String std::string st = "1345, The new empire , is , orxonox" 51 * is splitted with: 52 * SubString(st, ',', " \n\t") 53 * into 54 * "1345", "The new empire", "is", "orxonox" 55 * As you can see, the useless spaces around ',' were removed. 56 */ 39 /** 40 @file 41 @ingroup String 42 @brief A helper class to split a string into several tokens. 43 44 @anchor SubStringExample 45 46 The class SubString can be used to split an std::string into multiple tokens, using 47 a delimiter. SubString allows different options, for example to remove whitespaces 48 around the delimiters or different safe-mode chars, like quotation marks and braces. 49 50 You can access the tokens of the SubString using the [] operator like an array. 51 SubString also supports to join the tokens (or a subset of the tokens) again using 52 @ref orxonox::SubString::join() "join()". It's even possible to get a subset of the 53 SubString as another SubString using @ref orxonox::SubString::subSet() "subSet()". 54 55 Example: 56 @code 57 std::string text = "This is a test, \"Hello \\\" World\" and vector {1, 2, 3}"; 58 SubString tokens(text, SubString::WhiteSpaces, "", false, '\\', true, '"', true, '{', '}', true, '\0'); 59 60 for (unsigned int i = 0; i < tokens.size(); ++i) 61 COUT(0) << i << ": " << tokens[i] << std::endl; 62 @endcode 63 64 The output of this code is: 65 - 0: This 66 - 1: is 67 - 2: a 68 - 3: test, 69 - 4: Hello " World 70 - 5: and 71 - 6: vector 72 - 7: 1, 2, 3 73 74 The string was split using the delimiter " ". A string between quotation mark is not 75 split, the same holds for strings between '{' and '}'. Note how the quotation marks and 76 the braces were removed from the tokens, because the corresponding argument is 'true'. 77 78 Also note that the comma after "test" in token 3 is still there - it is neither part of the 79 delimiters SubString::WhiteSpaces nor part of the delimiterNeighbours parameter, so it 80 remains a part of the token. 81 */ 57 82 58 83 #ifndef __SubString_H__ … … 66 91 namespace orxonox 67 92 { 68 //! A class that can load one string and split it in multipe ones69 93 /** 70 * SubString is a very Powerfull way to create a SubSet from a String 71 * It can be used, to Split strings append them and join them again. 72 */ 94 @brief A class that splits a string into multiple tokens using different options. 95 96 The string is split into multiple tokens using a delimiter. Different options like 97 escape character, quotation marks, and more can be used to satisfy your needs. 98 99 See @ref SubStringExample "this description" for an example. 100 */ 73 101 class _UtilExport SubString 74 102 { 75 public:76 //! An enumerator for the State the Parser is in77 typedef enum{103 /// An enumerator for the internal state of the parser 104 enum SPLIT_LINE_STATE 105 { 78 106 SL_NORMAL, //!< Normal state 79 107 SL_ESCAPE, //!< After an escape character 80 SL_SAFEMODE, //!< In safe mode ( between "" mostly).108 SL_SAFEMODE, //!< In safe mode (usually between quotation marks). 81 109 SL_SAFEESCAPE, //!< In safe mode with the internal escape character, that escapes even the savemode character. 82 110 SL_COMMENT, //!< In Comment mode. 83 111 SL_PARENTHESES, //!< Between parentheses (usually '{' and '}') 84 112 SL_PARENTHESESESCAPE, //!< Between parentheses with the internal escape character, that escapes even the closing paranthesis character. 85 } SPLIT_LINE_STATE; 86 113 }; 87 114 88 115 public: 89 116 SubString(); 90 SubString(const std::string& string, char delimiter = ','); 91 SubString(const std::string& string, 92 const std::string& delimiters, const std::string& delimiterNeighbours = "", bool emptyEntries=false, 93 char escapeChar ='\\', bool removeEscapeChar = true, char safemode_char = '"', bool removeSafemodeChar = true, 94 char openparenthesis_char = '{', char closeparenthesis_char = '}', bool removeParenthesisChars = true, char comment_char = '\0'); 117 SubString(const std::string& line, 118 const std::string& delimiters = SubString::WhiteSpaces, 119 const std::string& delimiterNeighbours = "", 120 bool bAllowEmptyEntries=false, 121 char escapeChar ='\\', 122 bool bRemoveEscapeChar = true, 123 char safemodeChar = '"', 124 bool bRemoveSafemodeChar = true, 125 char openparenthesisChar = '{', 126 char closeparenthesisChar = '}', 127 bool bRemoveParenthesisChars = true, 128 char commentChar = '\0'); 95 129 SubString(unsigned int argc, const char** argv); 96 /** @brief create a Substring as a copy of another one. @param subString the SubString to copy. */ 97 SubString(const SubString& subString) { *this = subString; }; 98 SubString(const SubString& subString, unsigned int subSetBegin); 99 SubString(const SubString& subString, unsigned int subSetBegin, unsigned int subSetEnd); 130 SubString(const SubString& other, unsigned int begin); 131 SubString(const SubString& other, unsigned int begin, unsigned int end); 100 132 ~SubString(); 101 133 102 134 // operate on the SubString 103 SubString& operator=(const SubString& subString);104 bool operator==(const SubString& subString) const;105 bool compare(const SubString& subString) const;106 bool compare(const SubString& subString, unsigned int length) const;107 SubString operator+(const SubString& subString) const;108 SubString& operator+=(const SubString& subString);109 / ** @param subString the String to append @returns appended String. @brief added for convenience */110 SubString& append(const SubString subString) { return (*this += subString); };135 SubString& operator=(const SubString& other); 136 bool operator==(const SubString& other) const; 137 bool compare(const SubString& other) const; 138 bool compare(const SubString& other, unsigned int length) const; 139 SubString operator+(const SubString& other) const; 140 SubString& operator+=(const SubString& other); 141 /// Appends the tokens of another SubString to this. @return This SubString. 142 inline SubString& append(const SubString& other) { return (*this += other); } 111 143 112 144 ///////////////////////////////////////// 113 145 // Split and Join the any String. /////// 114 unsigned int split(const std::string& string = "", char delimiter = ','); 115 unsigned int split(const std::string& string, 116 const std::string& delimiters, const std::string& delimiterNeighbours = "", bool emptyEntries = false, 117 char escapeChar ='\\', bool removeExcapeChar = true, char safemode_char = '"', bool removeSafemodeChar = true, 118 char openparenthesis_char = '{', char closeparenthesis_char = '}', bool removeParenthesisChars = true, char comment_char = '\0'); 146 unsigned int split(const std::string& line, 147 const std::string& delimiters = SubString::WhiteSpaces, 148 const std::string& delimiterNeighbours = "", 149 bool bAllowEmptyEntries = false, 150 char escapeChar ='\\', 151 bool bRemoveEscapeChar = true, 152 char safemodeChar = '"', 153 bool bRemoveSafemodeChar = true, 154 char openparenthesisChar = '{', 155 char closeparenthesisChar = '}', 156 bool bRemoveParenthesisChars = true, 157 char commentChar = '\0'); 158 119 159 std::string join(const std::string& delimiter = " ") const; 120 160 //////////////////////////////////////// 121 161 122 162 // retrieve a SubSet from the String 123 SubString subSet(unsigned int subSetBegin) const;124 SubString subSet(unsigned int subSetBegin, unsigned int subSetEnd) const;163 SubString subSet(unsigned int begin) const; 164 SubString subSet(unsigned int begin, unsigned int end) const; 125 165 126 166 // retrieve Information from within 127 /** @brief Returns true if the SubString is empty */ 128 inline bool empty() const { return this->strings.empty(); }; 129 /** @brief Returns the count of Strings stored in this substring */ 130 inline unsigned int size() const { return this->strings.size(); }; 131 /** @brief Returns the i'th string from the subset of Strings @param i the i'th String */ 132 inline const std::string& operator[](unsigned int i) const { return this->strings[i]; }; 133 /** @brief Returns the i'th string from the subset of Strings @param i the i'th String */ 134 inline const std::string& getString(unsigned int i) const { return (*this)[i]; }; 135 /** @brief Returns all Strings as std::vector */ 136 inline const std::vector<std::string>& getAllStrings() const { return this->strings; } 137 /** @brief Returns true if the token is in safemode. @param i the i'th token */ 138 inline bool isInSafemode(unsigned int i) const { return this->bInSafemode[i]; } 139 /** @brief Returns the front of the StringList. */ 140 inline const std::string& front() const { return this->strings.front(); }; 141 /** @brief Returns the back of the StringList. */ 142 inline const std::string& back() const { return this->strings.back(); }; 143 /** @brief removes the back of the strings list. */ 144 inline void pop_back() { this->strings.pop_back(); this->bInSafemode.pop_back(); }; 145 167 /// Returns true if the SubString is empty 168 inline bool empty() const { return this->tokens_.empty(); } 169 /// Returns the number of tokens stored in this SubString 170 inline unsigned int size() const { return this->tokens_.size(); } 171 /// Returns the i'th token from the subset of strings @param index The index of the requested doken 172 inline const std::string& operator[](unsigned int index) const { return this->tokens_[index]; } 173 /// Returns the i'th token from the subset of strings @param index The index of the requested token 174 inline const std::string& getString(unsigned int index) const { return (*this)[index]; } 175 /// Returns all tokens as std::vector 176 inline const std::vector<std::string>& getAllStrings() const { return this->tokens_; } 177 /// Returns true if the token is in safemode. @param index The index of the token 178 inline bool isInSafemode(unsigned int index) const { return this->bTokenInSafemode_[index]; } 179 /// Returns the front of the list of tokens. 180 inline const std::string& front() const { return this->tokens_.front(); } 181 /// Returns the back of the list of tokens. 182 inline const std::string& back() const { return this->tokens_.back(); } 183 /// Removes the back of the list of tokens. 184 inline void pop_back() { this->tokens_.pop_back(); this->bTokenInSafemode_.pop_back(); } 185 186 void debug() const; 187 188 public: 189 static const std::string WhiteSpaces; ///< All whitespaces (usually used as delimiters or delimiterNeighbours 190 static const std::string WhiteSpacesWithComma; ///< All whitespaces and the comma (usually used as delimiters) 191 static const SubString NullSubString; ///< An empty SubString 192 193 private: 146 194 // the almighty algorithm. 147 static SPLIT_LINE_STATE splitLine(std::vector<std::string>& ret,148 std::vector<bool>& b InSafemode,195 static SPLIT_LINE_STATE splitLine(std::vector<std::string>& tokens, 196 std::vector<bool>& bTokenInSafemode, 149 197 const std::string& line, 150 198 const std::string& delimiters = SubString::WhiteSpaces, 151 199 const std::string& delimiterNeighbours = "", 152 bool emptyEntries = false,153 char escape _char = '\\',154 bool removeExcapeChar = true,155 char safemode _char = '"',156 bool removeSafemodeChar = true,157 char openparenthesis _char = '{',158 char closeparenthesis _char = '}',159 bool removeParenthesisChars = true,160 char comment _char = '\0',200 bool bAllowEmptyEntries = false, 201 char escapeChar = '\\', 202 bool bRemoveEscapeChar = true, 203 char safemodeChar = '"', 204 bool bRemoveSafemodeChar = true, 205 char openparenthesisChar = '{', 206 char closeparenthesisChar = '}', 207 bool bRemoveParenthesisChars = true, 208 char commentChar = '\0', 161 209 SPLIT_LINE_STATE start_state = SL_NORMAL); 162 // debugging. 163 void debug() const; 164 165 public: 166 static const std::string WhiteSpaces; 167 static const std::string WhiteSpacesWithComma; 168 static const SubString NullSubString; 169 170 private: 171 std::vector<std::string> strings; //!< strings produced from a single string splitted in multiple strings 172 std::vector<bool> bInSafemode; 210 211 std::vector<std::string> tokens_; ///< The tokens after spliting the input line 212 std::vector<bool> bTokenInSafemode_; ///< Saves for each token if it was in safe mode (between quotation marks or parenthesis) 173 213 }; 174 214 } -
code/trunk/src/libraries/util/TriBool.h
r6746 r7401 27 27 */ 28 28 29 /** 30 @file 31 @ingroup Util 32 */ 33 29 34 #ifndef _TriBool_H__ 30 35 #define _TriBool_H__ … … 35 40 namespace orxonox 36 41 { 42 /** Sort of a boolean value that also has state \c Dontcare 43 @remarks 44 Even though \c False has the value 0, both \c True and \c Dontcare have 45 a value other than 0. Keep that in mind when using TriBools in if statements. 46 */ 37 47 namespace TriBool 38 48 { -
code/trunk/src/libraries/util/VA_NARGS.h
r7284 r7401 29 29 /** 30 30 @file 31 @ingroup Util 31 32 @brief Declaration of the ORXONOX_VA_NARGS macro which returns the number of arguments passed to a variadic macro. 33 34 With this utility you can overload a macro for different numbers of arguments 35 (of course overloading is not possible for different types, as macros are not 36 type aware, but for different numbers of arguments is still very powerful). 37 38 Example: A macro to call functions 39 @code 40 myfunction(); // A static function 41 MyClass::myStaticFunction(); // A static class function 42 MyClass::myFunction(); // A member function 43 44 #define CallFunction(...) \ // Define a variadic macro that passes the arguments to the overloaded implementations 45 BOOST_PP_EXPAND(BOOST_PP_CAT(CallFunction, ORXONOX_VA_NARGS(__VA_ARGS__))(__VA_ARGS__)) 46 47 #define CallFunction1(function) \ // Overloaded macro for 1 argument 48 function() // Calls the static function 49 50 #define CallFunction2(class, function) \ // Overloaded macro for 2 arguments 51 class::function() // Calls the static class function 52 53 #define CallFunction3(class, function, object) \ // Overloaded macro for 3 arguments 54 object->class::function() // Calls the function on the object 55 56 57 CallFunction(myFunction); // Call the macro with 1 argument 58 CallFunction(MyClass, myStaticFunction); // Call the macro with 2 arguments 59 CallFunction(MyClass, myFunction, new MyClass()); // Call the macro with 3 arguments 60 @endcode 61 62 Note that the first (variadic) macro concatenates the name "CallFunction" with 63 the number of arguments ("1" - "N"). Then all arguments are passed to the right macro. 32 64 */ 33 65 -
code/trunk/src/libraries/util/mbool.h
r7268 r7401 27 27 */ 28 28 29 /** 30 @file 31 @ingroup Util 32 @brief Declaration and implementation of the @ref orxonox::mbool class. 33 */ 34 29 35 #ifndef _mbool_H__ 30 36 #define _mbool_H__ … … 34 40 namespace orxonox 35 41 { 42 /** 43 @brief mbool is a small helper class that acts like a bool, but keeps track of the number of its state changes. 44 45 The mbool class acts like a bool, but it has an internal counter that counts 46 the number state changes (i.e. when the bool changes from true to false or 47 back). This is used in the network if a boolean value is synchronized, because 48 if a value changes quickly from false to true and back in the same tick, the 49 clients will never be notified of this action. By using mbool however this 50 behaviour is fixed, which is important for triggers and other objects. 51 52 @note This is efficiently solved by using a union that combines a counter and a 53 boolean bitfield of size 1. The boolean value corresponds always to the first 54 bit of the counter - this means, if the counter is incremented, the boolean state 55 changes. On the other hand, if you want to change the state, you can simply increase 56 the counter. 57 */ 36 58 struct _UtilExport mbool 37 59 { 38 60 public: 61 /// Constructor: Creates the mbool and initializes the boolean value (default to false). 39 62 inline mbool(bool value = false) 40 63 { this->value_.memory_ = 0; this->value_.bool_ = value; } 64 /// Copy-constructor, copies state and memory. 41 65 inline mbool(const mbool& value) 42 66 { this->value_.memory_ = value.value_.memory_; } 43 67 68 /// Assigns a boolean value (and increases the memory value if the value is different to the old value). 44 69 inline mbool& operator=(bool value) 45 70 { if (value != this->value_.bool_) { ++this->value_.memory_; } return (*this); } 71 /// Assigns another mbool, copies state and memory. 46 72 inline mbool& operator=(const mbool& value) 47 73 { this->value_.memory_ = value.value_.memory_; return (*this); } 48 74 75 /// Increases the memory which also inverts it's state (++mbool). 49 76 inline mbool& operator++() 50 77 { ++this->value_.memory_; return (*this); } 51 inline mbool operator++(int i) 78 /// Increases the memory which also inverts it's state (mbool++). 79 inline mbool operator++(int) 52 80 { mbool temp = (*this); ++this->value_.memory_; return temp; } 53 81 82 /// Implicitly converts the mbool to a bool. 54 83 inline operator bool() const 55 84 { return this->value_.bool_; } 56 85 86 /// Compares the mbool to a bool, returns true if the bool has the same value as the state of the mbool. 57 87 inline bool operator==(bool other) const 58 88 { return this->value_.bool_ == other; } 89 /// Compares the mbool to a bool, returns true if the bool has a different value than the state of the mbool. 59 90 inline bool operator!=(bool other) const 60 91 { return this->value_.bool_ != other; } 61 92 93 /// Compares two mbools, returns true if their memory matches. 62 94 inline bool operator==(const mbool& other) const 63 95 { return this->value_.memory_ == other.value_.memory_; } 96 /// Compares two mbools, returns true if they have a different memory value. 64 97 inline bool operator!=(const mbool& other) const 65 98 { return this->value_.memory_ != other.value_.memory_; } 66 99 100 /// Returns the inverted state of the bool (doesn't change the internal state). 67 101 inline bool operator!() const 68 102 { return (!this->value_.bool_); } 69 103 104 /// Returns the memory value. 70 105 inline unsigned char& getMemory(){ return value_.memory_; } 71 106 … … 73 108 union 74 109 { 75 bool bool_ : 1; 76 unsigned char memory_; 77 } value_; 110 bool bool_ : 1; ///< The boolean state of the mbool, is located on the first bit of the memory variable 111 unsigned char memory_; ///< The memory of the mbool, counts the state-changes (and the first bit represents also the boolean value) 112 } value_; ///< A union containing the state and the memory of the mbool 78 113 }; 79 114 }
Note: See TracChangeset
for help on using the changeset viewer.