Changeset 8351 for code/trunk/src/libraries/util
- Timestamp:
- Apr 28, 2011, 7:15:14 AM (14 years ago)
- Location:
- code/trunk/src/libraries/util
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/libraries/util/CMakeLists.txt
r7449 r8351 19 19 20 20 SET_SOURCE_FILES(UTIL_SRC_FILES 21 Clock.cc22 Exception.cc23 ExprParser.cc24 Math.cc25 MultiType.cc26 Scope.cc27 StringUtils.cc28 21 COMPILATION_BEGIN StableCompilation.cc 29 22 Clipboard.cc 23 Clock.cc 30 24 Convert.cc 31 25 CRC32.cc 26 ExprParser.cc 32 27 OutputHandler.cc 28 Scope.cc 33 29 ScopedSingletonManager.cc 34 30 SharedPtr.cc 35 SignalHandler.cc36 31 Sleep.cc 37 32 SmallObjectAllocator.cc 38 33 SubString.cc 39 34 COMPILATION_END 35 36 MultiType.cc 37 Exception.cc 38 Math.cc 39 SignalHandler.cc 40 StringUtils.cc 40 41 ) 41 42 42 IF(GCC_NO_SYSTEM_HEADER_SUPPORT)43 # Get around displaying a few hundred lines of warning code44 SET_SOURCE_FILES_PROPERTIES(MultiType.cc PROPERTIES COMPILE_FLAGS "-w")45 ENDIF()46 43 IF(MSVC) 47 44 # Simply using #pragma warning(disable:4244) doesn't really disable it -
code/trunk/src/libraries/util/Convert.h
r7401 r8351 143 143 struct ConverterFallback 144 144 { 145 FORCEINLINE static bool convert(ToType* output, const FromType& input)145 ORX_FORCEINLINE static bool convert(ToType* output, const FromType& input) 146 146 { 147 147 COUT(2) << "Could not convert value of type " << typeid(FromType).name() … … 155 155 struct ConverterFallback<FromType*, ToType*> 156 156 { 157 FORCEINLINE static bool convert(ToType** output, FromType* const input)157 ORX_FORCEINLINE static bool convert(ToType** output, FromType* const input) 158 158 { 159 159 ToType* temp = dynamic_cast<ToType*>(input); … … 182 182 struct ConverterStringStream 183 183 { 184 FORCEINLINE static bool convert(ToType* output, const FromType& input)184 ORX_FORCEINLINE static bool convert(ToType* output, const FromType& input) 185 185 { 186 186 return orxonox::ConverterFallback<FromType, ToType>::convert(output, input); … … 198 198 /// Fallback operator <<() (delegates to orxonox::ConverterFallback) 199 199 template <class FromType> 200 FORCEINLINE bool operator <<(std::ostream& outstream, const FromType& input)200 ORX_FORCEINLINE bool operator <<(std::ostream& outstream, const FromType& input) 201 201 { 202 202 std::string temp; … … 215 215 struct ConverterStringStream<FromType, std::string> 216 216 { 217 FORCEINLINE static bool convert(std::string* output, const FromType& input)217 ORX_FORCEINLINE static bool convert(std::string* output, const FromType& input) 218 218 { 219 219 using namespace fallbackTemplates; … … 241 241 /// Fallback operator >>() (delegates to orxonox::ConverterFallback) 242 242 template <class ToType> 243 FORCEINLINE bool operator >>(std::istream& instream, ToType& output)243 ORX_FORCEINLINE bool operator >>(std::istream& instream, ToType& output) 244 244 { 245 245 std::string input(static_cast<std::istringstream&>(instream).str()); … … 252 252 struct ConverterStringStream<std::string, ToType> 253 253 { 254 FORCEINLINE static bool convert(ToType* output, const std::string& input)254 ORX_FORCEINLINE static bool convert(ToType* output, const std::string& input) 255 255 { 256 256 using namespace fallbackTemplates; … … 276 276 /// %Template delegates to ::ConverterStringStream 277 277 template <class FromType, class ToType> 278 FORCEINLINE bool convertImplicitely(ToType* output, const FromType& input, Loki::Int2Type<false>)278 ORX_FORCEINLINE bool convertImplicitely(ToType* output, const FromType& input, Loki::Int2Type<false>) 279 279 { 280 280 return ConverterStringStream<FromType, ToType>::convert(output, input); … … 283 283 /// Makes an implicit cast from \a FromType to \a ToType 284 284 template <class FromType, class ToType> 285 FORCEINLINE bool convertImplicitely(ToType* output, const FromType& input, Loki::Int2Type<true>)285 ORX_FORCEINLINE bool convertImplicitely(ToType* output, const FromType& input, Loki::Int2Type<true>) 286 286 { 287 287 (*output) = static_cast<ToType>(input); … … 303 303 { 304 304 enum { probe = ImplicitConversion<FromType, ToType>::exists }; 305 FORCEINLINE static bool convert(ToType* output, const FromType& input)305 ORX_FORCEINLINE static bool convert(ToType* output, const FromType& input) 306 306 { 307 307 // Use the probe's value to delegate to the right function … … 327 327 */ 328 328 template <class FromType, class ToType> 329 FORCEINLINE bool convertValue(ToType* output, const FromType& input)329 ORX_FORCEINLINE bool convertValue(ToType* output, const FromType& input) 330 330 { 331 331 return ConverterExplicit<FromType, ToType>::convert(output, input); … … 348 348 */ 349 349 template<class FromType, class ToType> 350 FORCEINLINE bool convertValue(ToType* output, const FromType& input, const ToType& fallback)350 ORX_FORCEINLINE bool convertValue(ToType* output, const FromType& input, const ToType& fallback) 351 351 { 352 352 if (convertValue(output, input)) … … 361 361 /// Directly returns the converted value, but uses the fallback on failure. @see convertValue 362 362 template<class FromType, class ToType> 363 FORCEINLINE ToType getConvertedValue(const FromType& input, const ToType& fallback)363 ORX_FORCEINLINE ToType getConvertedValue(const FromType& input, const ToType& fallback) 364 364 { 365 365 ToType output; … … 380 380 */ 381 381 template<class ToType, class FromType> 382 FORCEINLINE ToType multi_cast(const FromType& input)382 ORX_FORCEINLINE ToType multi_cast(const FromType& input) 383 383 { 384 384 ToType output; … … 395 395 struct ConverterExplicit<const char*, ToType> 396 396 { 397 FORCEINLINE static bool convert(ToType* output, const char* input)397 ORX_FORCEINLINE static bool convert(ToType* output, const char* input) 398 398 { 399 399 return convertValue<std::string, ToType>(output, input); … … 405 405 struct ConverterExplicit<char, std::string> 406 406 { 407 FORCEINLINE static bool convert(std::string* output, const char input)407 ORX_FORCEINLINE static bool convert(std::string* output, const char input) 408 408 { 409 409 *output = input; … … 415 415 struct ConverterExplicit<unsigned char, std::string> 416 416 { 417 FORCEINLINE static bool convert(std::string* output, const unsigned char input)417 ORX_FORCEINLINE static bool convert(std::string* output, const unsigned char input) 418 418 { 419 419 *output = input; … … 425 425 struct ConverterExplicit<std::string, char> 426 426 { 427 FORCEINLINE static bool convert(char* output, const std::string& input)427 ORX_FORCEINLINE static bool convert(char* output, const std::string& input) 428 428 { 429 429 if (!input.empty()) … … 438 438 struct ConverterExplicit<std::string, unsigned char> 439 439 { 440 FORCEINLINE static bool convert(unsigned char* output, const std::string& input)440 ORX_FORCEINLINE static bool convert(unsigned char* output, const std::string& input) 441 441 { 442 442 if (!input.empty()) … … 453 453 struct ConverterExplicit<bool, std::string> 454 454 { 455 FORCEINLINE static bool convert(std::string* output, const bool& input)455 ORX_FORCEINLINE static bool convert(std::string* output, const bool& input) 456 456 { 457 457 if (input) -
code/trunk/src/libraries/util/Exception.cc
r7401 r8351 35 35 #include "Exception.h" 36 36 37 #include <cstddef> 37 38 #include <CEGUIExceptions.h> 38 39 #include "Debug.h" … … 95 96 throw; 96 97 } 98 catch (const CEGUI::Exception& ex) 99 { 100 return GeneralException(ex.getMessage().c_str(), ex.getLine(), 101 ex.getFileName().c_str(), ex.getName().c_str()).getDescription(); 102 } 97 103 catch (const std::exception& ex) 98 104 { 99 105 return ex.what(); 100 }101 catch (const CEGUI::Exception& ex)102 {103 #if CEGUI_VERSION_MAJOR == 0 && CEGUI_VERSION_MINOR < 6104 return GeneralException(ex.getMessage().c_str()).getDescription();105 #else106 return GeneralException(ex.getMessage().c_str(), ex.getLine(),107 ex.getFileName().c_str(), ex.getName().c_str()).getDescription();108 #endif109 106 } 110 107 catch (...) -
code/trunk/src/libraries/util/ExprParser.cc
r7184 r8351 52 52 { 53 53 this->failed_ = false; 54 this->variables_["pi"] = math::pi _d;55 this->variables_["e"] = math::e _d;56 } 57 58 void ExprParser::setVariable(const std::string& varname, doublevalue)54 this->variables_["pi"] = math::pi; 55 this->variables_["e"] = math::e; 56 } 57 58 void ExprParser::setVariable(const std::string& varname, float value) 59 59 { 60 60 this->variables_[varname] = value; … … 78 78 //Private functions: 79 79 /******************/ 80 doubleExprParser::parse_argument()81 { 82 doublevalue = parse_expr_8();80 float ExprParser::parse_argument() 81 { 82 float value = parse_expr_8(); 83 83 if (*reading_stream == ',') 84 84 { … … 93 93 } 94 94 95 doubleExprParser::parse_last_argument()96 { 97 doublevalue = parse_expr_8();95 float ExprParser::parse_last_argument() 96 { 97 float value = parse_expr_8(); 98 98 if (*reading_stream == ')') 99 99 { … … 108 108 } 109 109 110 doubleExprParser::parse_expr_8()111 { 112 doublevalue = parse_expr_7();110 float ExprParser::parse_expr_8() 111 { 112 float value = parse_expr_7(); 113 113 for(;;) 114 114 { … … 124 124 125 125 126 doubleExprParser::parse_expr_7()127 { 128 doublevalue = parse_expr_6();126 float ExprParser::parse_expr_7() 127 { 128 float value = parse_expr_6(); 129 129 for(;;) 130 130 { … … 139 139 } 140 140 141 doubleExprParser::parse_expr_6()142 { 143 doublevalue = parse_expr_5();141 float ExprParser::parse_expr_6() 142 { 143 float value = parse_expr_5(); 144 144 for(;;) 145 145 { … … 158 158 } 159 159 160 doubleExprParser::parse_expr_5()161 { 162 doublevalue = parse_expr_4();160 float ExprParser::parse_expr_5() 161 { 162 float value = parse_expr_4(); 163 163 for(;;) 164 164 { … … 183 183 } 184 184 185 doubleExprParser::parse_expr_4()186 { 187 doublevalue = parse_expr_3();185 float ExprParser::parse_expr_4() 186 { 187 float value = parse_expr_3(); 188 188 for(;;) 189 189 { … … 202 202 } 203 203 204 doubleExprParser::parse_expr_3()205 { 206 doublevalue = parse_expr_2();204 float ExprParser::parse_expr_3() 205 { 206 float value = parse_expr_2(); 207 207 for(;;) 208 208 { … … 217 217 case modulo: 218 218 { 219 doubletemp = parse_expr_2();219 float temp = parse_expr_2(); 220 220 value = value - floor(value/temp)*temp; 221 221 break; … … 227 227 } 228 228 229 doubleExprParser::parse_expr_2()230 { 231 doublevalue = parse_expr_1();229 float ExprParser::parse_expr_2() 230 { 231 float value = parse_expr_1(); 232 232 while (*reading_stream != '\0') 233 233 { … … 246 246 } 247 247 248 doubleExprParser::parse_expr_1()248 float ExprParser::parse_expr_1() 249 249 { 250 250 PARSE_BLANKS; 251 doublevalue;251 float value; 252 252 253 253 unary_operator op = parse_unary_operator(); … … 262 262 else if ((*reading_stream > 47 && *reading_stream < 59) || *reading_stream == 46) 263 263 { // number 264 value = strtod(reading_stream, const_cast<char**>(&reading_stream));264 value = (float)strtod(reading_stream, const_cast<char**>(&reading_stream)); 265 265 } 266 266 else if ((*reading_stream > 64 && *reading_stream < 91) || (*reading_stream > 96 && *reading_stream < 123) || *reading_stream == 46) … … 306 306 { 307 307 value = parse_last_argument(); 308 value = 0.5 *log((value + 1)/(value - 1));308 value = 0.5f*log((value + 1.0f)/(value - 1.0f)); 309 309 } 310 310 CASE("int") … … 325 325 { 326 326 value = parse_last_argument(); 327 value = (value>0 ? 1 : (value<0 ? -1 : 0));327 value = (value>0.0f ? 1.0f : (value<0.0f ? -1.0f : 0.0f)); 328 328 } 329 329 CASE("sqrt") 330 330 value = sqrt(parse_last_argument()); 331 331 CASE("degrees") 332 value = parse_last_argument()*180 /math::pi_d;332 value = parse_last_argument()*180.0f/math::pi; 333 333 CASE("radians") 334 value = parse_last_argument()*math::pi _d/180;334 value = parse_last_argument()*math::pi/180.0f; 335 335 CASE("mod") 336 336 { 337 337 value = parse_argument(); 338 doublevalue2 = parse_last_argument();338 float value2 = parse_last_argument(); 339 339 value = value - floor(value/value2)*value2; 340 340 } … … 356 356 else 357 357 { 358 std::map<std::string, double>::const_iterator it = this->variables_.find(word);358 std::map<std::string, float>::const_iterator it = this->variables_.find(word); 359 359 if (it != this->variables_.end()) 360 360 value = it->second; -
code/trunk/src/libraries/util/ExprParser.h
r7401 r8351 57 57 COUT(2) << "Warning: Expression could not be parsed to the end! Remains: '" << expr.getRemains() << '\'' << std::endl; 58 58 } 59 doubleresult = expr.getResult();59 float result = expr.getResult(); 60 60 } 61 61 else … … 125 125 void parse(const std::string& str); 126 126 const std::string& getRemains() { return this->remains_; } 127 doublegetResult() { return this->result_; }127 float getResult() { return this->result_; } 128 128 bool getSuccess() { return !this->failed_; } 129 129 130 void setVariable(const std::string& varname, doublevalue);130 void setVariable(const std::string& varname, float value); 131 131 132 132 private: 133 doubleparse_expr_1();134 doubleparse_expr_2();135 doubleparse_expr_3();136 doubleparse_expr_4();137 doubleparse_expr_5();138 doubleparse_expr_6();139 doubleparse_expr_7();140 doubleparse_expr_8();133 float parse_expr_1(); 134 float parse_expr_2(); 135 float parse_expr_3(); 136 float parse_expr_4(); 137 float parse_expr_5(); 138 float parse_expr_6(); 139 float parse_expr_7(); 140 float parse_expr_8(); 141 141 char* parse_word(char* str); 142 142 binary_operator parse_binary_operator(); 143 143 unary_operator parse_unary_operator(); 144 144 145 doubleparse_argument();146 doubleparse_last_argument();145 float parse_argument(); 146 float parse_last_argument(); 147 147 148 148 binary_operator op; 149 149 const char* reading_stream; 150 150 bool failed_; 151 doubleresult_;151 float result_; 152 152 std::string remains_; 153 std::map<std::string, double> variables_;153 std::map<std::string, float> variables_; 154 154 }; 155 155 156 156 //Endzeichen für float expression: ')', '}', ']', ',', ';' 157 _UtilExport bool parse_float(char* const, char**, double*);157 _UtilExport bool parse_float(char* const, char**, float*); 158 158 //Endzeichen angegeben 159 _UtilExport bool parse_float(char* const, char**, char, double*);159 _UtilExport bool parse_float(char* const, char**, char, float*); 160 160 //Letzter Teil-float eines Vektors parsen (keine Vergleichs- und Logikoperationen) 161 _UtilExport bool parse_vector_float(char* const, char**, bool, double*);161 _UtilExport bool parse_vector_float(char* const, char**, bool, float*); 162 162 } 163 163 -
code/trunk/src/libraries/util/Math.h
r7427 r8351 66 66 namespace orxonox 67 67 { 68 // C++ doesn't define any constants for pi, e, etc. 68 /** Often used numerical constants because C++ doesn't define any. 69 @note 70 The values here are decimal representations of the approximate floating 71 point value as it is stored according to the IEEE 754 standard. 72 */ 69 73 namespace math 70 74 { 71 const float pi = 3.14159265f; ///< PI 72 const float pi_2 = 1.57079633f; ///< PI / 2 73 const float pi_4 = 7.85398163e-1f; ///< PI / 4 74 const float e = 2.71828183f; ///< e 75 const float sqrt2 = 1.41421356f; ///< sqrt(2) 76 const float sqrt2_2 = 7.07106781e-1f; ///< sqrt(2) / 2 77 78 const double pi_d = 3.14159265358979324; ///< PI (double) 79 const double pi_2_d = 1.57079632679489662; ///< PI / 2 (double) 80 const double pi_4_d = 7.85398163397448310e-1; ///< PI / 4 (double) 81 const double e_d = 2.71828182845904524; ///< e (double) 82 const double sqrt2_d = 1.41421356237309505; ///< sqrt(2) (double) 83 const double sqrt2_2_d = 7.07106781186547524e-1; ///< sqrt(2) / 2 (double) 75 const float twoPi = 6.283185482025146484375f; ///< PI * 2 76 const float pi = 3.1415927410125732421875f; ///< PI 77 const float pi_2 = 1.57079637050628662109375f; ///< PI / 2 78 const float pi_4 = 0.785398185253143310546875f; ///< PI / 4 79 const float e = 2.718281269073486328125f; ///< e 80 const float sqrt2 = 1.41421353816986083984375f; ///< sqrt(2) 81 const float sqrt2_2 = 0.707106769084930419921875f; ///< sqrt(2) / 2 84 82 } 85 83 -
code/trunk/src/libraries/util/MathConvert.h
r7401 r8351 51 51 struct ConverterExplicit<orxonox::Vector2, std::string> 52 52 { 53 FORCEINLINE static bool convert(std::string* output, const orxonox::Vector2& input)53 ORX_FORCEINLINE static bool convert(std::string* output, const orxonox::Vector2& input) 54 54 { 55 55 std::ostringstream ostream; … … 67 67 struct ConverterExplicit<orxonox::Vector3, std::string> 68 68 { 69 FORCEINLINE static bool convert(std::string* output, const orxonox::Vector3& input)69 ORX_FORCEINLINE static bool convert(std::string* output, const orxonox::Vector3& input) 70 70 { 71 71 std::ostringstream ostream; … … 83 83 struct ConverterExplicit<orxonox::Vector4, std::string> 84 84 { 85 FORCEINLINE static bool convert(std::string* output, const orxonox::Vector4& input)85 ORX_FORCEINLINE static bool convert(std::string* output, const orxonox::Vector4& input) 86 86 { 87 87 std::ostringstream ostream; … … 99 99 struct ConverterExplicit<orxonox::Quaternion, std::string> 100 100 { 101 FORCEINLINE static bool convert(std::string* output, const orxonox::Quaternion& input)101 ORX_FORCEINLINE static bool convert(std::string* output, const orxonox::Quaternion& input) 102 102 { 103 103 std::ostringstream ostream; … … 115 115 struct ConverterExplicit<orxonox::ColourValue, std::string> 116 116 { 117 FORCEINLINE static bool convert(std::string* output, const orxonox::ColourValue& input)117 ORX_FORCEINLINE static bool convert(std::string* output, const orxonox::ColourValue& input) 118 118 { 119 119 std::ostringstream ostream; … … 157 157 struct ConverterFallback<orxonox::Radian, ToType> 158 158 { 159 FORCEINLINE static bool convert(ToType* output, const orxonox::Radian& input)159 ORX_FORCEINLINE static bool convert(ToType* output, const orxonox::Radian& input) 160 160 { 161 161 return convertValue<Ogre::Real, ToType>(output, input.valueRadians()); … … 167 167 struct ConverterFallback<orxonox::Degree, ToType> 168 168 { 169 FORCEINLINE static bool convert(ToType* output, const orxonox::Degree& input)169 ORX_FORCEINLINE static bool convert(ToType* output, const orxonox::Degree& input) 170 170 { 171 171 return convertValue<Ogre::Real, ToType>(output, input.valueDegrees()); … … 177 177 struct ConverterFallback<FromType, orxonox::Radian> 178 178 { 179 FORCEINLINE static bool convert(orxonox::Radian* output, const FromType& input)179 ORX_FORCEINLINE static bool convert(orxonox::Radian* output, const FromType& input) 180 180 { 181 181 float temp; … … 194 194 struct ConverterFallback<FromType, orxonox::Degree> 195 195 { 196 FORCEINLINE static bool convert(orxonox::Degree* output, const FromType& input)196 ORX_FORCEINLINE static bool convert(orxonox::Degree* output, const FromType& input) 197 197 { 198 198 float temp; -
code/trunk/src/libraries/util/SharedPtr.h
r7401 r8351 163 163 public: 164 164 SharedCounter() : count_(1) {} 165 virtual ~SharedCounter() {} 165 166 virtual void destroy() = 0; 166 167 … … 186 187 _UtilExport SmallObjectAllocator& createSharedCounterPool(); 187 188 188 FORCEINLINE SmallObjectAllocator& getSharedCounterPool()189 ORX_FORCEINLINE SmallObjectAllocator& getSharedCounterPool() 189 190 { 190 191 static SmallObjectAllocator& instance = createSharedCounterPool(); -
code/trunk/src/libraries/util/SignalHandler.cc
r7801 r8351 37 37 #include <cstdlib> 38 38 #include <cstring> 39 #include <cstdio> 39 40 40 41 #include "Debug.h" -
code/trunk/src/libraries/util/SignalHandler.h
r7457 r8351 70 70 71 71 /// The SignalHandler is used to catch signals like SIGSEGV and write a backtrace to the logfile. 72 class SignalHandler : public Singleton<SignalHandler>72 class _UtilExport SignalHandler : public Singleton<SignalHandler> 73 73 { 74 74 friend class Singleton<SignalHandler>; -
code/trunk/src/libraries/util/UtilPrereqs.h
r6417 r8351 52 52 # endif 53 53 # endif 54 #elif defined ( ORXONOX_GCC_VISIBILITY ) 54 # define _UtilPrivate 55 #elif defined (ORXONOX_GCC_VISIBILITY) 55 56 # define _UtilExport __attribute__ ((visibility("default"))) 57 # define _UtilPrivate __attribute__ ((visibility("hidden"))) 56 58 #else 57 59 # define _UtilExport 60 # define _UtilPrivate 58 61 #endif 59 62
Note: See TracChangeset
for help on using the changeset viewer.