Changeset 3196 for code/trunk/src/util
- Timestamp:
- Jun 20, 2009, 9:20:47 AM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 28 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/pch (added) merged: 3114-3118,3124-3125,3127-3131,3133,3138-3194
- Property svn:mergeinfo changed
-
code/trunk/src/util/CMakeLists.txt
r3089 r3196 18 18 # 19 19 20 SET_SOURCE_FILES(UTIL_FILES 21 CRC32.h 22 Clipboard.h 23 Convert.h 24 Debug.h 25 Exception.h 26 ExprParser.h 27 Math.h 28 MathConvert.h 29 MultiType.h 30 MultiTypeValue.h 31 OrxEnum.h 32 OutputBuffer.h 33 OutputHandler.h 34 SignalHandler.h 35 Sleep.h 36 String.h 37 SubString.h 38 UtilPrereqs.h 39 mbool.h 40 20 SET_SOURCE_FILES(UTIL_SRC_FILES 41 21 Clipboard.cc 42 22 CRC32.cc … … 52 32 SubString.cc 53 33 ) 54 #GET_ALL_HEADER_FILES(UTIL_HDR_FILES)55 #SET(UTIL_FILES ${UTIL_SRC_FILES} ${UTIL_HDR_FILES})56 GENERATE_SOURCE_GROUPS(${UTIL_FILES})57 # Also add OrxonoxConfig to have it least somewhere in the IDE58 LIST(APPEND UTIL_FILES59 ${CMAKE_BINARY_DIR}/src/OrxonoxConfig.h60 ${CMAKE_SOURCE_DIR}/src/OrxonoxConfig.h.in61 ${CMAKE_BINARY_DIR}/src/SpecialConfig.h62 ${CMAKE_SOURCE_DIR}/src/SpecialConfig.h.in63 )64 SOURCE_GROUP("" FILES65 ${CMAKE_BINARY_DIR}/src/OrxonoxConfig.h66 ${CMAKE_SOURCE_DIR}/src/OrxonoxConfig.h.in67 ${CMAKE_BINARY_DIR}/src/SpecialConfig.h68 ${CMAKE_SOURCE_DIR}/src/SpecialConfig.h.in69 )70 34 71 35 IF(GCC_NO_SYSTEM_HEADER_SUPPORT) … … 74 38 ENDIF() 75 39 76 ADD_LIBRARY(util SHARED ${UTIL_FILES}) 77 SET_TARGET_PROPERTIES(util PROPERTIES DEFINE_SYMBOL "UTIL_SHARED_BUILD") 78 TARGET_LINK_LIBRARIES(util ${OGRE_LIBRARY}) 79 80 ORXONOX_INSTALL(util) 40 ORXONOX_ADD_LIBRARY(util 41 FIND_HEADER_FILES 42 DEFINE_SYMBOL 43 "UTIL_SHARED_BUILD" 44 LINK_LIBRARIES 45 ${OGRE_LIBRARY} 46 SOURCE_FILES 47 ${UTIL_SRC_FILES} 48 ) -
code/trunk/src/util/CRC32.h
r2710 r3196 31 31 32 32 #include "UtilPrereqs.h" 33 #include <iostream>34 33 35 34 namespace orxonox -
code/trunk/src/util/Clipboard.cc
r2710 r3196 112 112 namespace orxonox 113 113 { 114 st d::string clipboard = ""; //!< Keeps the text of our internal clipboard114 static std::string clipboard = ""; //!< Keeps the text of our internal clipboard 115 115 116 116 /** -
code/trunk/src/util/Clipboard.h
r2171 r3196 43 43 44 44 #include "UtilPrereqs.h" 45 46 45 #include <string> 47 46 -
code/trunk/src/util/Convert.h
r2710 r3196 40 40 #include <string> 41 41 #include <sstream> 42 #include <istream>43 #include <ostream>44 42 #include <typeinfo> 45 43 … … 123 121 namespace orxonox 124 122 { 125 namespace 123 namespace detail 126 124 { 127 125 //! Little template that maps integers to entire types (Alexandrescu 2001) … … 139 137 struct ConverterFallback 140 138 { 141 static bool convert(ToType* output, const FromType& input)139 FORCEINLINE static bool convert(ToType* output, const FromType& input) 142 140 { 143 141 COUT(2) << "Could not convert value of type " << typeid(FromType).name() … … 151 149 struct ConverterFallback<FromType*, ToType*> 152 150 { 153 static bool convert(ToType** output, FromType* const input)151 FORCEINLINE static bool convert(ToType** output, FromType* const input) 154 152 { 155 153 ToType* temp = dynamic_cast<ToType*>(input); … … 174 172 struct ConverterStringStream 175 173 { 176 static bool convert(ToType* output, const FromType& input)174 FORCEINLINE static bool convert(ToType* output, const FromType& input) 177 175 { 178 176 return orxonox::ConverterFallback<FromType, ToType>::convert(output, input); … … 188 186 { 189 187 template <class FromType> 190 inlinebool operator <<(std::ostream& outstream, const FromType& input)188 FORCEINLINE bool operator <<(std::ostream& outstream, const FromType& input) 191 189 { 192 190 std::string temp; … … 205 203 struct ConverterStringStream<FromType, std::string> 206 204 { 207 static bool convert(std::string* output, const FromType& input)205 FORCEINLINE static bool convert(std::string* output, const FromType& input) 208 206 { 209 207 using namespace fallbackTemplates; … … 228 226 { 229 227 template <class ToType> 230 inlinebool operator >>(std::istream& instream, ToType& output)228 FORCEINLINE bool operator >>(std::istream& instream, ToType& output) 231 229 { 232 230 return orxonox::ConverterFallback<std::string, ToType> … … 239 237 struct ConverterStringStream<std::string, ToType> 240 238 { 241 static bool convert(ToType* output, const std::string& input)239 FORCEINLINE static bool convert(ToType* output, const std::string& input) 242 240 { 243 241 using namespace fallbackTemplates; … … 262 260 // implicit cast not possible, try stringstream conversion next 263 261 template <class FromType, class ToType> 264 inline bool convertImplicitely(ToType* output, const FromType& input, orxonox::Int2Type<false>)262 FORCEINLINE bool convertImplicitely(ToType* output, const FromType& input, detail::Int2Type<false>) 265 263 { 266 264 return ConverterStringStream<FromType, ToType>::convert(output, input); … … 269 267 // We can cast implicitely 270 268 template <class FromType, class ToType> 271 inline bool convertImplicitely(ToType* output, const FromType& input, orxonox::Int2Type<true>)269 FORCEINLINE bool convertImplicitely(ToType* output, const FromType& input, detail::Int2Type<true>) 272 270 { 273 271 (*output) = static_cast<ToType>(input); … … 284 282 struct ConverterExplicit 285 283 { 286 static bool convert(ToType* output, const FromType& input)284 FORCEINLINE static bool convert(ToType* output, const FromType& input) 287 285 { 288 286 // Try implict cast and probe first. If a simple cast is not possible, it will not compile 289 287 // We therefore have to out source it into another template function 290 288 const bool probe = ImplicitConversion<FromType, ToType>::exists; 291 return convertImplicitely(output, input, orxonox::Int2Type<probe>());289 return convertImplicitely(output, input, detail::Int2Type<probe>()); 292 290 } 293 291 }; … … 306 304 */ 307 305 template <class FromType, class ToType> 308 inlinebool convertValue(ToType* output, const FromType& input)306 FORCEINLINE bool convertValue(ToType* output, const FromType& input) 309 307 { 310 308 return ConverterExplicit<FromType, ToType>::convert(output, input); 311 }312 313 // For compatibility reasons. The same, but with capital ConvertValue314 template<class FromType, class ToType>315 inline bool ConvertValue(ToType* output, const FromType& input)316 {317 return convertValue(output, input);318 309 } 319 310 … … 331 322 */ 332 323 template<class FromType, class ToType> 333 inlinebool convertValue(ToType* output, const FromType& input, const ToType& fallback)324 FORCEINLINE bool convertValue(ToType* output, const FromType& input, const ToType& fallback) 334 325 { 335 326 if (convertValue(output, input)) … … 342 333 } 343 334 344 // for compatibility reason. (capital 'c' in ConvertValue)345 template<class FromType, class ToType>346 inline bool ConvertValue(ToType* output, const FromType& input, const ToType& fallback)347 {348 return convertValue(output, input, fallback);349 }350 351 335 // Directly returns the converted value, even if the conversion was not successful. 352 336 template<class FromType, class ToType> 353 inlineToType getConvertedValue(const FromType& input)337 FORCEINLINE ToType getConvertedValue(const FromType& input) 354 338 { 355 339 ToType output; … … 360 344 // Directly returns the converted value, but uses the fallback on failure. 361 345 template<class FromType, class ToType> 362 inlineToType getConvertedValue(const FromType& input, const ToType& fallback)346 FORCEINLINE ToType getConvertedValue(const FromType& input, const ToType& fallback) 363 347 { 364 348 ToType output; … … 370 354 // That means you can call it exactly like static_cast<ToType>(fromTypeValue). 371 355 template<class ToType, class FromType> 372 inline ToType omni_cast(const FromType& input)356 FORCEINLINE ToType multi_cast(const FromType& input) 373 357 { 374 358 ToType output; … … 379 363 // convert to string Shortcut 380 364 template <class FromType> 381 inlinestd::string convertToString(FromType value)382 { 383 return getConvertedValue<FromType, std::string>(value);365 FORCEINLINE std::string convertToString(FromType value) 366 { 367 return getConvertedValue<FromType, std::string>(value); 384 368 } 385 369 386 370 // convert from string Shortcut 387 371 template <class ToType> 388 inlineToType convertFromString(std::string str)389 { 390 return getConvertedValue<std::string, ToType>(str);372 FORCEINLINE ToType convertFromString(std::string str) 373 { 374 return getConvertedValue<std::string, ToType>(str); 391 375 } 392 376 … … 399 383 struct ConverterExplicit<const char*, ToType> 400 384 { 401 static bool convert(ToType* output, const char* input)385 FORCEINLINE static bool convert(ToType* output, const char* input) 402 386 { 403 387 return convertValue<std::string, ToType>(output, input); … … 409 393 struct ConverterExplicit<char, std::string> 410 394 { 411 static bool convert(std::string* output, const char input)395 FORCEINLINE static bool convert(std::string* output, const char input) 412 396 { 413 397 *output = std::string(1, input); … … 418 402 struct ConverterExplicit<unsigned char, std::string> 419 403 { 420 static bool convert(std::string* output, const unsigned char input)404 FORCEINLINE static bool convert(std::string* output, const unsigned char input) 421 405 { 422 406 *output = std::string(1, input); … … 427 411 struct ConverterExplicit<std::string, char> 428 412 { 429 static bool convert(char* output, const std::string input)413 FORCEINLINE static bool convert(char* output, const std::string input) 430 414 { 431 415 if (input != "") … … 439 423 struct ConverterExplicit<std::string, unsigned char> 440 424 { 441 static bool convert(unsigned char* output, const std::string input)425 FORCEINLINE static bool convert(unsigned char* output, const std::string input) 442 426 { 443 427 if (input != "") … … 454 438 struct ConverterExplicit<bool, std::string> 455 439 { 456 static bool convert(std::string* output, const bool& input)440 FORCEINLINE static bool convert(std::string* output, const bool& input) 457 441 { 458 442 if (input) -
code/trunk/src/util/Debug.h
r2171 r3196 63 63 #include "UtilPrereqs.h" 64 64 65 #include <stdio.h>66 67 65 #include "OutputHandler.h" 68 66 … … 73 71 @return The soft debug level 74 72 */ 75 staticinline int getSoftDebugLevel()73 inline int getSoftDebugLevel() 76 74 { 77 75 return OutputHandler::getSoftDebugLevel(); -
code/trunk/src/util/Exception.cc
r3068 r3196 37 37 namespace orxonox 38 38 { 39 Exception::Exception(const std::string& description, int lineNumber,39 Exception::Exception(const std::string& description, unsigned int lineNumber, 40 40 const char* filename, const char* functionName) 41 41 : description_(description) … … 52 52 { } 53 53 54 /** 55 @remarks 56 The composed full description gets stored to fullDescription_. But for compliance 57 with std::exception, this method has to be const. Hence fullDescription_ is declared 58 as mutable. 59 */ 54 60 const std::string& Exception::getFullDescription() const 55 61 { -
code/trunk/src/util/Exception.h
r3068 r3196 30 30 @file 31 31 @brief 32 Declaration of the Exception class.32 Declaration of facilities to handle exceptions. 33 33 */ 34 34 … … 38 38 #include "UtilPrereqs.h" 39 39 40 #include <exception> 41 #include <sstream> 40 42 #include <string> 41 #include <exception>42 #include <cassert>43 43 #include "Debug.h" 44 44 45 45 namespace orxonox 46 46 { 47 /** 48 @brief 49 Base class for all exceptions (derived from std::exception). 50 @details 51 This class provides support for information about the file, the line 52 and the function the error occured. 53 */ 47 54 class _UtilExport Exception : public std::exception 48 55 { 49 56 public: 50 51 Exception(const std::string& description, int lineNumber, 57 /** 58 @brief 59 Creates the exception but doesn't yet compose the full descrption (because of the virtual functions) 60 @param description 61 Exception description as string. This message is supposed to help developers! 62 */ 63 Exception(const std::string& description, unsigned int lineNumber, 52 64 const char* filename, const char* functionName); 65 //! Simplified constructor with just a description. If you need more, use the other one. 53 66 Exception(const std::string& description); 54 67 55 // / Needed for compatibility with std::exception (from Ogre::Exception)68 //! Needed for compatibility with std::exception 56 69 virtual ~Exception() throw() { } 57 70 71 //! Returns a full description with type, line, file and function 58 72 virtual const std::string& getFullDescription() const; 73 //! Returns the string name of the exception type 59 74 virtual std::string getTypeName() const = 0; 75 //! Returns the short developer written exception 60 76 virtual const std::string& getDescription() const { return this->description_; } 61 virtual const int getLineNumber() const { return this->lineNumber_; } 77 //! Returns the line number on which the exception occurred. 78 virtual const unsigned int getLineNumber() const { return this->lineNumber_; } 79 //! Returns the function in which the exception occurred. 62 80 virtual const std::string& getFunctionName() const { return this->functionName_; } 81 //! Returns the filename in which the exception occurred. 82 virtual const std::string& getFilename() const { return this->filename_; } 63 83 64 // / Override std::exception::what (from Ogre::Exception)84 //! Returns a full description of the error. 65 85 const char* what() const throw() { return getFullDescription().c_str(); } 66 86 67 87 protected: 68 std::string description_; 69 int lineNumber_;70 std::string functionName_; 71 std::string filename_; 88 std::string description_; //!< User typed text about why the exception occurred 89 unsigned int lineNumber_; //!< Line on which the exception occurred 90 std::string functionName_; //!< Function (including namespace and class) where the exception occurred 91 std::string filename_; //!< File where the exception occurred 72 92 // mutable because "what()" is a const method 73 mutable std::string fullDescription_; 93 mutable std::string fullDescription_; //!< Full description with line, file and function 74 94 }; 75 95 76 96 //! Creates a new type of exception that inherits from tracker::Exception 77 97 #define CREATE_ORXONOX_EXCEPTION(ExceptionName) \ 78 98 class ExceptionName##Exception : public Exception \ 79 99 { \ 80 100 public: \ 81 ExceptionName##Exception(const std::string& description, int lineNumber, \ 82 const char* filename, const char* functionName) \ 83 : Exception(description, lineNumber, filename, functionName) \ 101 ExceptionName##Exception(const std::string& description, \ 102 unsigned int lineNumber, const char* filename, \ 103 const char* functionName) \ 104 : Exception(description, lineNumber, filename, functionName) \ 84 105 { } \ 85 106 \ 86 107 ExceptionName##Exception(const std::string& description) \ 87 : Exception(description)\108 : Exception(description) \ 88 109 { } \ 89 110 \ … … 91 112 \ 92 113 std::string getTypeName() const { return #ExceptionName; } \ 93 } ;114 } 94 115 95 116 // Creates all possible exception types. 96 117 // If you want to add a new type, simply copy and adjust a new line here. 118 #ifndef DOXYGEN_SHOULD_SKIP_THIS 97 119 CREATE_ORXONOX_EXCEPTION(General); 98 120 CREATE_ORXONOX_EXCEPTION(FileNotFound); … … 106 128 CREATE_ORXONOX_EXCEPTION(NoGraphics); 107 129 CREATE_ORXONOX_EXCEPTION(AbortLoading); 108 } 130 #endif 109 131 110 132 /** 111 133 @brief 112 Helper function that creates an exception, displays the message, but doesn't throw it. 134 Helper function that forwards an exception and displays the message. 135 @details 136 This is necessary because only when using 'throw' the objects storage is managed. 113 137 */ 114 138 template <class T> 115 inline const T& InternalHandleException(const T& exception)139 inline const T& exceptionThrowerHelper(const T& exception) 116 140 { 117 141 // let the catcher decide whether to display the message below level 4 … … 120 144 } 121 145 122 #define ThrowException(type, description) \ 123 throw InternalHandleException(type##Exception(description, __LINE__, __FILE__, __FUNCTIONNAME__)) 146 /** 147 @brief 148 Throws an exception and logs a message beforehand. 149 @param type 150 Type of the exception as literal (General, Initialisation, etc.) 151 @param description 152 Exception description as string 153 */ 154 #define ThrowException(type, description, ...) \ 155 throw orxonox::exceptionThrowerHelper(type##Exception(static_cast<std::ostringstream&>(std::ostringstream().flush() << description).str(), __LINE__, __FILE__, __FUNCTIONNAME__)) 124 156 125 // define an assert macro that can display a message 126 #ifndef NDEBUG 127 #define OrxAssert(Assertion, ErrorMessage) \ 128 Assertion ? ((void)0) : (void)(orxonox::OutputHandler::getOutStream().setOutputLevel(ORX_ERROR) << ErrorMessage << std::endl); \ 129 assert(Assertion) 130 #else 131 #define OrxAssert(condition, errorMessage) ((void)0) 132 #endif 157 } /* namespace orxonox */ 133 158 134 159 #endif /* _Exception_H__ */ -
code/trunk/src/util/ExprParser.cc
r2171 r3196 35 35 #include <cmath> 36 36 #include <cstring> 37 #include < stdlib.h>37 #include <cstdlib> 38 38 39 39 // macros for easier if, else statements … … 247 247 return 0; 248 248 } 249 else if ( *reading_stream > 47 && *reading_stream < 59|| *reading_stream == 46)249 else if ((*reading_stream > 47 && *reading_stream < 59) || *reading_stream == 46) 250 250 { // number 251 251 value = strtod(reading_stream, const_cast<char**>(&reading_stream)); 252 252 } 253 else if ( *reading_stream > 64 && *reading_stream < 91 || *reading_stream > 96 && *reading_stream < 123|| *reading_stream == 46)253 else if ((*reading_stream > 64 && *reading_stream < 91) || (*reading_stream > 96 && *reading_stream < 123) || *reading_stream == 46) 254 254 { // variable or function 255 255 char* word = new char[256]; … … 384 384 char* word = str; 385 385 int counter = 0; 386 while ( *reading_stream > 47 && *reading_stream < 58 || *reading_stream > 64 && *reading_stream < 91 || *reading_stream > 96 && *reading_stream < 123|| *reading_stream == 46)386 while ((*reading_stream > 47 && *reading_stream < 58) || (*reading_stream > 64 && *reading_stream < 91) || (*reading_stream > 96 && *reading_stream < 123) || *reading_stream == 46) 387 387 { 388 388 *word++ = *reading_stream++; -
code/trunk/src/util/ExprParser.h
r2171 r3196 72 72 73 73 ExprParser(const std::string& str); 74 std::string& getRemains() { return this->remains_; }75 double getResult() { return this->result_; }76 bool getSuccess() { return !this->failed_; }74 const std::string& getRemains() { return this->remains_; } 75 double getResult() { return this->result_; } 76 bool getSuccess() { return !this->failed_; } 77 77 78 78 private: -
code/trunk/src/util/Math.cc
r3049 r3196 35 35 36 36 #include <OgrePlane.h> 37 37 38 #include "MathConvert.h" 38 39 #include "SubString.h" 39 40 // Do not remove this include to avoid linker errors. 40 // Do not remove this include, it avoids linker errors. 41 41 #include "mbool.h" 42 42 … … 238 238 if (tokens.size() >= 2) 239 239 { 240 if (! ConvertValue(&(output->x), tokens[0]))241 return false; 242 if (! ConvertValue(&(output->y), tokens[1]))240 if (!convertValue(&(output->x), tokens[0])) 241 return false; 242 if (!convertValue(&(output->y), tokens[1])) 243 243 return false; 244 244 … … 261 261 if (tokens.size() >= 3) 262 262 { 263 if (! ConvertValue(&(output->x), tokens[0]))264 return false; 265 if (! ConvertValue(&(output->y), tokens[1]))266 return false; 267 if (! ConvertValue(&(output->z), tokens[2]))263 if (!convertValue(&(output->x), tokens[0])) 264 return false; 265 if (!convertValue(&(output->y), tokens[1])) 266 return false; 267 if (!convertValue(&(output->z), tokens[2])) 268 268 return false; 269 269 … … 286 286 if (tokens.size() >= 4) 287 287 { 288 if (! ConvertValue(&(output->x), tokens[0]))289 return false; 290 if (! ConvertValue(&(output->y), tokens[1]))291 return false; 292 if (! ConvertValue(&(output->z), tokens[2]))293 return false; 294 if (! ConvertValue(&(output->w), tokens[3]))288 if (!convertValue(&(output->x), tokens[0])) 289 return false; 290 if (!convertValue(&(output->y), tokens[1])) 291 return false; 292 if (!convertValue(&(output->z), tokens[2])) 293 return false; 294 if (!convertValue(&(output->w), tokens[3])) 295 295 return false; 296 296 … … 309 309 if (tokens.size() >= 4) 310 310 { 311 if (! ConvertValue(&(output->w), tokens[0]))312 return false; 313 if (! ConvertValue(&(output->x), tokens[1]))314 return false; 315 if (! ConvertValue(&(output->y), tokens[2]))316 return false; 317 if (! ConvertValue(&(output->z), tokens[3]))311 if (!convertValue(&(output->w), tokens[0])) 312 return false; 313 if (!convertValue(&(output->x), tokens[1])) 314 return false; 315 if (!convertValue(&(output->y), tokens[2])) 316 return false; 317 if (!convertValue(&(output->z), tokens[3])) 318 318 return false; 319 319 … … 332 332 if (tokens.size() >= 3) 333 333 { 334 if (! ConvertValue(&(output->r), tokens[0]))335 return false; 336 if (! ConvertValue(&(output->g), tokens[1]))337 return false; 338 if (! ConvertValue(&(output->b), tokens[2]))334 if (!convertValue(&(output->r), tokens[0])) 335 return false; 336 if (!convertValue(&(output->g), tokens[1])) 337 return false; 338 if (!convertValue(&(output->b), tokens[2])) 339 339 return false; 340 340 if (tokens.size() >= 4) 341 341 { 342 if (! ConvertValue(&(output->a), tokens[3]))342 if (!convertValue(&(output->a), tokens[3])) 343 343 return false; 344 344 } -
code/trunk/src/util/Math.h
r2872 r3196 37 37 #include "UtilPrereqs.h" 38 38 39 #include <ostream>40 39 #include <string> 41 40 #include <cmath> 42 #include <boost/static_assert.hpp>43 41 44 42 #include <OgreMath.h> … … 46 44 #include <OgreVector3.h> 47 45 #include <OgreVector4.h> 48 #include <OgreMatrix3.h>49 #include <OgreMatrix4.h>50 46 #include <OgreQuaternion.h> 51 47 #include <OgreColourValue.h> … … 58 54 namespace orxonox 59 55 { 60 using Ogre::Radian;61 using Ogre::Degree;62 using Ogre::Vector2;63 using Ogre::Vector3;64 using Ogre::Vector4;65 using Ogre::Matrix3;66 using Ogre::Matrix4;67 using Ogre::Quaternion;68 using Ogre::ColourValue;69 70 // Also define our own transform space enum71 namespace TransformSpace72 {73 /**74 @brief75 Enumeration denoting the spaces which a transform can be relative to.76 */77 enum Enum78 {79 //! Transform is relative to the local space80 Local,81 //! Transform is relative to the space of the parent node82 Parent,83 //! Transform is relative to world space84 World85 };86 }87 88 56 _UtilExport std::ostream& operator<<(std::ostream& out, const orxonox::Radian& radian); 89 57 _UtilExport std::istream& operator>>(std::istream& in, orxonox::Radian& radian); … … 217 185 template <> inline orxonox::Quaternion zeroise<orxonox::Quaternion>() { return orxonox::Quaternion (0, 0, 0, 0); } 218 186 187 //! Provides zero value symbols that can be returned as reference 188 template <typename T> 189 struct NilValue 190 { 191 inline operator const T&() const 192 { 193 return value; 194 } 195 static T value; 196 }; 197 template <typename T> 198 T NilValue<T>::value = zeroise<T>(); 199 219 200 /** 220 201 @brief Interpolates between two values for a time between 0 and 1. … … 225 206 */ 226 207 template <typename T> 227 T interpolate(float time, const T& start, const T& end)208 inline T interpolate(float time, const T& start, const T& end) 228 209 { 229 210 return time * (end - start) + start; … … 238 219 */ 239 220 template <typename T> 240 T interpolateSmooth(float time, const T& start, const T& end)221 inline T interpolateSmooth(float time, const T& start, const T& end) 241 222 { 242 223 return (-2 * (end - start) * cube(time)) + (3 * (end - start) * square(time)) + start; … … 248 229 inline float rnd() 249 230 { 250 return rand() / (RAND_MAX + 1.0 );231 return rand() / (RAND_MAX + 1.0f); 251 232 } 252 233 … … 275 256 inline float rndsgn() 276 257 { 277 return ((rand() & 0x2) - 1); // rand() & 0x2 is either 2 or 0258 return static_cast<float>((rand() & 0x2) - 1); // rand() & 0x2 is either 2 or 0 278 259 } 279 260 … … 283 264 { 284 265 public: 285 IntVector2() : x(0), y(0) { }286 IntVector2(int _x, int _y) : x(_x), y(_y) { }287 int x;288 int y;266 IntVector2() : x(0), y(0) { } 267 IntVector2(int _x, int _y) : x(_x), y(_y) { } 268 int x; 269 int y; 289 270 }; 290 271 … … 292 273 { 293 274 public: 294 IntVector3() : x(0), y(0), z(0) { }295 IntVector3(int _x, int _y, int _z) : x(_x), y(_y), z(_z) { }296 int x;297 int y;298 int z;275 IntVector3() : x(0), y(0), z(0) { } 276 IntVector3(int _x, int _y, int _z) : x(_x), y(_y), z(_z) { } 277 int x; 278 int y; 279 int z; 299 280 }; 300 281 } -
code/trunk/src/util/MathConvert.h
r2171 r3196 50 50 struct ConverterExplicit<orxonox::Vector2, std::string> 51 51 { 52 static bool convert(std::string* output, const orxonox::Vector2& input)52 FORCEINLINE static bool convert(std::string* output, const orxonox::Vector2& input) 53 53 { 54 54 std::ostringstream ostream; … … 66 66 struct ConverterExplicit<orxonox::Vector3, std::string> 67 67 { 68 static bool convert(std::string* output, const orxonox::Vector3& input)68 FORCEINLINE static bool convert(std::string* output, const orxonox::Vector3& input) 69 69 { 70 70 std::ostringstream ostream; … … 82 82 struct ConverterExplicit<orxonox::Vector4, std::string> 83 83 { 84 static bool convert(std::string* output, const orxonox::Vector4& input)84 FORCEINLINE static bool convert(std::string* output, const orxonox::Vector4& input) 85 85 { 86 86 std::ostringstream ostream; … … 98 98 struct ConverterExplicit<orxonox::Quaternion, std::string> 99 99 { 100 static bool convert(std::string* output, const orxonox::Quaternion& input)100 FORCEINLINE static bool convert(std::string* output, const orxonox::Quaternion& input) 101 101 { 102 102 std::ostringstream ostream; … … 114 114 struct ConverterExplicit<orxonox::ColourValue, std::string> 115 115 { 116 static bool convert(std::string* output, const orxonox::ColourValue& input)116 FORCEINLINE static bool convert(std::string* output, const orxonox::ColourValue& input) 117 117 { 118 118 std::ostringstream ostream; … … 156 156 struct ConverterFallback<orxonox::Radian, ToType> 157 157 { 158 static bool convert(ToType* output, const orxonox::Radian& input)158 FORCEINLINE static bool convert(ToType* output, const orxonox::Radian& input) 159 159 { 160 160 return convertValue<Ogre::Real, ToType>(output, input.valueRadians()); … … 166 166 struct ConverterFallback<orxonox::Degree, ToType> 167 167 { 168 static bool convert(ToType* output, const orxonox::Degree& input)168 FORCEINLINE static bool convert(ToType* output, const orxonox::Degree& input) 169 169 { 170 170 return convertValue<Ogre::Real, ToType>(output, input.valueDegrees()); … … 176 176 struct ConverterFallback<FromType, orxonox::Radian> 177 177 { 178 static bool convert(orxonox::Radian* output, const FromType& input)178 FORCEINLINE static bool convert(orxonox::Radian* output, const FromType& input) 179 179 { 180 180 float temp; … … 193 193 struct ConverterFallback<FromType, orxonox::Degree> 194 194 { 195 static bool convert(orxonox::Degree* output, const FromType& input)195 FORCEINLINE static bool convert(orxonox::Degree* output, const FromType& input) 196 196 { 197 197 float temp; -
code/trunk/src/util/MultiType.cc
r2662 r3196 159 159 } 160 160 161 MultiType::operator char() const { return (this->value_) ? ((this->value_->type_ == MT_char ) ? ( (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_uchar ) ? ( (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_short ) ? ( (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_ushort ) ? ( (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_int ) ? ( (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_uint ) ? ( (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_long ) ? ( (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_ulong ) ? ( (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_longlong ) ? ( (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_ulonglong ) ? ( (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_float ) ? ( (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_double ) ? ( (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_longdouble ) ? ( (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_bool ) ? ( (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_void ) ? ( (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_string ) ? ( (MT_Value<std::string> *)this->value_)->value_ : (*this->value_)) : zeroise<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_vector2 ) ? ( (MT_Value<orxonox::Vector2> *)this->value_)->value_ : (*this->value_)) : zeroise<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_vector3 ) ? ( (MT_Value<orxonox::Vector3> *)this->value_)->value_ : (*this->value_)) : zeroise<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_vector4 ) ? ( (MT_Value<orxonox::Vector4> *)this->value_)->value_ : (*this->value_)) : zeroise<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_colourvalue) ? ( (MT_Value<orxonox::ColourValue>*)this->value_)->value_ : (*this->value_)) : zeroise<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_quaternion ) ? ( (MT_Value<orxonox::Quaternion> *)this->value_)->value_ : (*this->value_)) : zeroise<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_radian ) ? ( (MT_Value<orxonox::Radian> *)this->value_)->value_ : (*this->value_)) : zeroise<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_degree ) ? ( (MT_Value<orxonox::Degree> *)this->value_)->value_ : (*this->value_)) : zeroise<orxonox::Degree>(); } /** @brief Returns the current value, converted to the requested type. */161 MultiType::operator char() const { return (this->value_) ? ((this->value_->type_ == MT_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_uchar ) ? (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_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_ushort ) ? (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_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_uint ) ? (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_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_ulong ) ? (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_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_ulonglong ) ? (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_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_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_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_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_void ) ? (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_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_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_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_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_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_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_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_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 184 185 185 template <> void MultiType::createNewValueContainer(const char& value) { this->value_ = new MT_Value<char> (value, MT_char ); } /** @brief Creates a new value container for the given type. */ -
code/trunk/src/util/MultiType.h
r3084 r3196 69 69 #include "UtilPrereqs.h" 70 70 71 #include <boost/static_assert.hpp> 72 73 #include "Math.h" 71 #include <cassert> 72 #include <string> 73 #include <OgreVector2.h> 74 #include <OgreVector3.h> 75 #include <OgreVector4.h> 76 #include <OgreQuaternion.h> 77 #include <OgreColourValue.h> 74 78 75 79 namespace orxonox … … 441 445 template <typename T> inline void changeValueContainer(const T& value) { if (this->value_) { delete this->value_; } this->createNewValueContainer<T>(value); } 442 446 /** @brief Creates a new value container (works only with specialized types). */ 443 template <typename T> void createNewValueContainer(const T& value) { BOOST_STATIC_ASSERT(sizeof(T) == 0); return false; }447 template <typename T> void createNewValueContainer(const T& value) { /* STATIC ASSERT */ *****value; return false; } 444 448 445 449 MT_ValueBase* value_; //!< A pointer to the value container -
code/trunk/src/util/MultiTypeValue.h
r3084 r3196 38 38 39 39 #include "UtilPrereqs.h" 40 41 #include <cassert> 40 42 #include "MathConvert.h" 41 43 #include "MultiType.h" 42 44 #include "Serialise.h" 43 #include <cassert>44 45 45 46 namespace orxonox … … 75 76 } 76 77 77 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. */78 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. */79 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. */80 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. */81 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. */82 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. */83 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. */84 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. */85 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. */86 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. */87 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. */88 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. */89 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. */90 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. */91 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. */92 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. */93 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. */94 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. */95 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. */96 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. */97 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. */98 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. */99 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. */100 101 inline bool setValue(const char& value) { return !(bHasDefaultValue_ = ! ConvertValue<char , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */102 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. */103 inline bool setValue(const short& value) { return !(bHasDefaultValue_ = ! ConvertValue<short , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */104 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. */105 inline bool setValue(const int& value) { return !(bHasDefaultValue_ = ! ConvertValue<int , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */106 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. */107 inline bool setValue(const long& value) { return !(bHasDefaultValue_ = ! ConvertValue<long , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */108 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. */109 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. */110 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. */111 inline bool setValue(const float& value) { return !(bHasDefaultValue_ = ! ConvertValue<float , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */112 inline bool setValue(const double& value) { return !(bHasDefaultValue_ = ! ConvertValue<double , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */113 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. */114 inline bool setValue(const bool& value) { return !(bHasDefaultValue_ = ! ConvertValue<bool , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */115 inline bool setValue( void* const& value) { return !(bHasDefaultValue_ = ! ConvertValue<void* , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */116 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. */117 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. */118 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. */119 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. */120 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. */121 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. */122 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. */123 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. */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. */ 124 125 125 126 inline operator char() const { return getConvertedValue<T, char> (this->value_, 0); } /** @brief Returns the current value, converted to the requested type. */ … … 194 195 saveAndIncrease( this->value_.z, mem ); 195 196 saveAndIncrease( this->value_.w, mem ); 196 }template <> inline uint8_t MT_Value<Ogre::Quaternion>::getSize() const 197 } 198 template <> inline uint8_t MT_Value<Ogre::Quaternion>::getSize() const 197 199 { 198 200 return 4*returnSize(this->value_.x); -
code/trunk/src/util/OutputBuffer.cc
r2710 r3196 44 44 void OutputBuffer::registerListener(OutputBufferListener* listener) 45 45 { 46 this->listeners_. insert(this->listeners_.end(),listener);46 this->listeners_.push_back(listener); 47 47 } 48 48 … … 53 53 void OutputBuffer::unregisterListener(OutputBufferListener* listener) 54 54 { 55 for (std:: list<OutputBufferListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); )55 for (std::vector<OutputBufferListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ) 56 56 { 57 57 if ((*it) == listener) 58 this->listeners_.erase(it++);58 it = this->listeners_.erase(it); 59 59 else 60 60 ++it; … … 127 127 void OutputBuffer::callListeners() 128 128 { 129 for (std:: list<OutputBufferListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)129 for (std::vector<OutputBufferListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it) 130 130 (*it)->outputChanged(); 131 131 } -
code/trunk/src/util/OutputBuffer.h
r2171 r3196 43 43 #define _OutputBuffer_H__ 44 44 45 #include <list> 45 #include "UtilPrereqs.h" 46 47 #include <vector> 46 48 #include <sstream> 47 #include <iostream>48 49 #include "UtilPrereqs.h"50 49 51 50 namespace orxonox … … 167 166 void callListeners(); 168 167 169 std::stringstream stream_; //!< The stringstream that stores the assigned text170 std:: list<OutputBufferListener*> listeners_; //!< A list of all listeners168 std::stringstream stream_; //!< The stringstream that stores the assigned text 169 std::vector<OutputBufferListener*> listeners_; //!< A list of all listeners 171 170 }; 172 171 } -
code/trunk/src/util/OutputHandler.h
r2710 r3196 63 63 64 64 /** @brief Puts some text on the outstream. @param text The text */ 65 static inline std::stringlog(const std::string& text)65 static inline const std::string& log(const std::string& text) 66 66 { OutputHandler::getOutStream().setOutputLevel(0); OutputHandler::getOutStream().output(text + "\n"); return text; } 67 67 68 68 /** @brief Puts an error on the outstream. @param text The text */ 69 static inline std::stringerror(const std::string& text)69 static inline const std::string& error(const std::string& text) 70 70 { OutputHandler::getOutStream().setOutputLevel(1); OutputHandler::getOutStream().output(text + "\n"); return text; } 71 71 72 72 /** @brief Puts a warning on the outstream. @param text The text */ 73 static inline std::stringwarning(const std::string& text)73 static inline const std::string& warning(const std::string& text) 74 74 { OutputHandler::getOutStream().setOutputLevel(2); OutputHandler::getOutStream().output(text + "\n"); return text; } 75 75 76 76 /** @brief Puts an info on the outstream. @param text The text */ 77 static inline std::stringinfo(const std::string& text)77 static inline const std::string& info(const std::string& text) 78 78 { OutputHandler::getOutStream().setOutputLevel(3); OutputHandler::getOutStream().output(text + "\n"); return text; } 79 79 80 80 /** @brief Puts some debug output on the outstream. @param text The text */ 81 static inline std::stringdebug(const std::string& text)81 static inline const std::string& debug(const std::string& text) 82 82 { OutputHandler::getOutStream().setOutputLevel(4); OutputHandler::getOutStream().output(text + "\n"); return text; } 83 83 -
code/trunk/src/util/SignalHandler.cc
r3068 r3196 33 33 34 34 #include "SignalHandler.h" 35 #include "Debug.h"36 35 37 36 #include <iostream> 38 37 #include <cstdlib> 39 38 #include <cstring> 39 #include "Debug.h" 40 40 41 41 namespace orxonox … … 209 209 { 210 210 if ( 211 charsFound == 0 && byte == '('||212 charsFound == 1 && byte == 'g'||213 charsFound == 2 && byte == 'd'||214 charsFound == 3 && byte == 'b'||215 charsFound == 4 && byte == ')'||216 charsFound == 5 && byte == ' '211 (charsFound == 0 && byte == '(') || 212 (charsFound == 1 && byte == 'g') || 213 (charsFound == 2 && byte == 'd') || 214 (charsFound == 3 && byte == 'b') || 215 (charsFound == 4 && byte == ')') || 216 (charsFound == 5 && byte == ' ') 217 217 ) 218 218 charsFound++; … … 246 246 247 247 if ( 248 charsFound == 0 && byte == '('||249 charsFound == 1 && byte == 'g'||250 charsFound == 2 && byte == 'd'||251 charsFound == 3 && byte == 'b'||252 charsFound == 4 && byte == ')'||253 charsFound == 5 && byte == ' '248 (charsFound == 0 && byte == '(') || 249 (charsFound == 1 && byte == 'g') || 250 (charsFound == 2 && byte == 'd') || 251 (charsFound == 3 && byte == 'b') || 252 (charsFound == 4 && byte == ')') || 253 (charsFound == 5 && byte == ' ') 254 254 ) 255 255 charsFound++; -
code/trunk/src/util/Sleep.cc
r2774 r3196 28 28 29 29 /** 30 @file 31 @brief Implementation of three sleep functions. 30 @file 31 @brief 32 Implementation of three sleep functions. Avoids including windows.h 32 33 */ 33 34 … … 43 44 { 44 45 if (microseconds < 1000) 45 COUT(2) << "Warning: Windows can 46 COUT(2) << "Warning: Windows cannot sleep less than 1ms, ignoring" << std::endl; 46 47 Sleep(microseconds / 1000); 47 48 } -
code/trunk/src/util/Sleep.h
r2773 r3196 28 28 29 29 /** 30 31 32 Functions for using sleep() and usleep() on windows.30 @file 31 @brief 32 Functions declarations to make the current thread sleep. 33 33 */ 34 34 … … 40 40 namespace orxonox 41 41 { 42 //! Makes the thread sleep for a few @a microseconds 42 43 _UtilExport void usleep(unsigned long microseconds); 44 //! Makes the thread sleep for a few @a milliseconds 43 45 _UtilExport void msleep(unsigned long milliseconds); 46 //! Makes the thread sleep for a few @a seconds 44 47 _UtilExport void sleep (unsigned long seconds); 45 48 } -
code/trunk/src/util/String.cc
r2662 r3196 35 35 36 36 #include <cctype> 37 #include <iostream>38 39 37 #include "Convert.h" 40 38 #include "Math.h" -
code/trunk/src/util/String.h
r2171 r3196 36 36 37 37 #include "UtilPrereqs.h" 38 39 38 #include <string> 40 #include <sstream>41 39 42 40 namespace orxonox -
code/trunk/src/util/SubString.cc
r3089 r3196 39 39 40 40 #include "SubString.h" 41 #include < stdio.h>41 #include <cstdio> 42 42 43 43 namespace orxonox -
code/trunk/src/util/UtilPrereqs.h
r2710 r3196 60 60 // Forward declarations 61 61 //----------------------------------------------------------------------- 62 namespace Ogre 63 { 64 class Radian; 65 class Degree; 66 class Vector2; 67 class Vector3; 68 class Vector4; 69 class Matrix3; 70 class Matrix4; 71 class Quaternion; 72 class ColourValue; 73 } 74 62 75 namespace orxonox 63 76 { 77 using Ogre::Radian; 78 using Ogre::Degree; 79 using Ogre::Vector2; 80 using Ogre::Vector3; 81 using Ogre::Vector4; 82 using Ogre::Matrix3; 83 using Ogre::Matrix4; 84 using Ogre::Quaternion; 85 using Ogre::ColourValue; 86 64 87 class Exception; 65 88 class ExprParser; -
code/trunk/src/util/mbool.h
r2662 r3196 36 36 struct _UtilExport mbool 37 37 { 38 // friend Synchronisable::registerVariable<>()39 38 public: 40 39 inline mbool(bool value = false)
Note: See TracChangeset
for help on using the changeset viewer.