Changeset 6417 for code/trunk/src/libraries/util
- Timestamp:
- Dec 25, 2009, 10:23:58 PM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 1 deleted
- 22 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/util/Clipboard.cc
r5958 r6417 78 78 { 79 79 COUT(1) << "Error: Unable to copy the following text to the clipboard:" << std::endl; 80 COUT(1) << " \"" << text << "\""<< std::endl;80 COUT(1) << " \"" << text << '"' << std::endl; 81 81 } 82 82 return false; … … 96 96 if (hData == NULL) 97 97 return ""; 98 std::string output = static_cast<char*>(GlobalLock(hData));98 std::string output(static_cast<char*>(GlobalLock(hData))); 99 99 GlobalUnlock(hData); 100 100 CloseClipboard(); … … 119 119 namespace orxonox 120 120 { 121 static std::string clipboard = ""; //!< Keeps the text of our internal clipboard121 static std::string clipboard; //!< Keeps the text of our internal clipboard 122 122 123 123 /** -
code/trunk/src/libraries/util/Clock.cc
r5929 r6417 34 34 Clock::Clock() 35 35 : timer_(new Ogre::Timer()) 36 , storedTime_(0)37 36 , tickTime_(0) 38 37 , tickDt_(0) 39 38 , tickDtFloat_(0.0f) 40 , lastTimersTime_(0)41 39 { 42 40 } … … 46 44 delete timer_; 47 45 } 48 46 47 /** 48 @remarks 49 Mind the types! Ogre::Timer::getMicroseconds() will return an unsigned 50 long, which will eventually overflow. But if you use the subtraction of 51 the current time minus the last time the timer gave us and sum these up to 52 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 long 54 as well because (unsigned long)tickTime_ will do exactly that. 55 */ 49 56 void Clock::capture() 50 57 { 51 unsigned long timersTime = timer_->getMicroseconds(); 52 tickTime_ = storedTime_ + timersTime; 53 tickDt_ = timersTime - lastTimersTime_; 58 tickDt_ = timer_->getMicroseconds() - (unsigned long)tickTime_; 59 tickTime_ += tickDt_; 54 60 tickDtFloat_ = static_cast<float>(tickDt_) / 1000000.0f; 55 56 if (timersTime > 0xFFFFFFFF/4)57 {58 // Ogre timer will overflow at 2^32 microseconds if unsigned long is 32 bit59 storedTime_ += timersTime;60 lastTimersTime_ = 0;61 timer_->reset();62 }63 else64 {65 lastTimersTime_ = timersTime;66 }67 61 } 68 62 69 63 unsigned long long Clock::getRealMicroseconds() const 70 64 { 71 return t his->timer_->getMicroseconds() + this->storedTime_;65 return tickTime_ + (timer_->getMicroseconds() - (unsigned long)tickTime_); 72 66 } 73 67 } -
code/trunk/src/libraries/util/Clock.h
r5929 r6417 57 57 58 58 Ogre::Timer* timer_; 59 unsigned long long storedTime_;60 59 unsigned long long tickTime_; 61 60 long tickDt_; 62 61 float tickDtFloat_; 63 unsigned long lastTimersTime_;64 62 }; 65 63 } -
code/trunk/src/libraries/util/Convert.h
r5738 r6417 43 43 44 44 #include "Debug.h" 45 #include "StringUtils.h"46 45 #include "TemplateUtils.h" 47 46 … … 336 335 FORCEINLINE static bool convert(std::string* output, const char input) 337 336 { 338 *output = std::string(1, input);337 *output = input; 339 338 return true; 340 339 } … … 345 344 FORCEINLINE static bool convert(std::string* output, const unsigned char input) 346 345 { 347 *output = std::string(1, input);346 *output = input; 348 347 return true; 349 348 } … … 352 351 struct ConverterExplicit<std::string, char> 353 352 { 354 FORCEINLINE static bool convert(char* output, const std::string input)355 { 356 if ( input != "")353 FORCEINLINE static bool convert(char* output, const std::string& input) 354 { 355 if (!input.empty()) 357 356 *output = input[0]; 358 357 else … … 364 363 struct ConverterExplicit<std::string, unsigned char> 365 364 { 366 FORCEINLINE static bool convert(unsigned char* output, const std::string input)367 { 368 if ( input != "")365 FORCEINLINE static bool convert(unsigned char* output, const std::string& input) 366 { 367 if (!input.empty()) 369 368 *output = input[0]; 370 369 else … … 389 388 }; 390 389 390 // Declarations to avoid StringUtils.h include 391 _UtilExport std::string removeTrailingWhitespaces(const std::string& str); 392 _UtilExport std::string getLowercase(const std::string& str); 393 391 394 // std::string to bool 392 395 template <> … … 395 398 static bool convert(bool* output, const std::string& input) 396 399 { 397 std::stringstripped = getLowercase(removeTrailingWhitespaces(input));400 const std::string& stripped = getLowercase(removeTrailingWhitespaces(input)); 398 401 if (stripped == "true" || stripped == "on" || stripped == "yes") 399 402 { 400 *output = true;401 return true;403 *output = true; 404 return true; 402 405 } 403 406 else if (stripped == "false" || stripped == "off" || stripped == "no") 404 407 { 405 *output = false;406 return true;408 *output = false; 409 return true; 407 410 } 408 411 -
code/trunk/src/libraries/util/Debug.h
r6105 r6417 71 71 using std::endl; 72 72 73 //! Adjust to discard certain output with level > hardDebugLevel at compile time 73 // Adjust this to discard certain output with level > hardDebugLevel at compile time already 74 #ifdef ORXONOX_RELEASE 75 const int hardDebugLevel = OutputLevel::Verbose 76 #elif defined(NDEBUG) 74 77 const int hardDebugLevel = OutputLevel::Verbose; 78 #else 79 //! Maximum level for debug output that should be even processed at run time 80 const int hardDebugLevel = OutputLevel::Ultra; 81 #endif 82 83 //! This function simply returns 0 and helps to suppress the "statement has no effect" compiler warning 84 inline int debugDummyFunction() 85 { 86 return 0; 87 } 75 88 } 76 89 … … 79 92 Logs text output: use exactly like std::cout, but specify an output 80 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 97 this macro magic can possibly even work ;) 81 98 @example 82 99 COUT(3) << "Some info" << std::endl; … … 88 105 #define COUT(level) \ 89 106 /*if*/ (level > orxonox::hardDebugLevel) ? \ 90 0\107 orxonox::debugDummyFunction() \ 91 108 /*else*/ : \ 92 109 /*if*/ (level > orxonox::OutputHandler::getSoftDebugLevel()) ? \ 93 0\110 orxonox::debugDummyFunction() \ 94 111 /*else*/ : \ 95 112 orxonox::OutputHandler::getOutStream(level) -
code/trunk/src/libraries/util/Exception.cc
r5781 r6417 49 49 : description_(description) 50 50 , lineNumber_(0) 51 , functionName_("")52 , filename_("")53 51 { } 54 52 … … 61 59 const std::string& Exception::getFullDescription() const 62 60 { 63 if (fullDescription_ == "")61 if (fullDescription_.empty()) 64 62 { 65 63 std::ostringstream fullDesc; … … 67 65 fullDesc << this->getTypeName() << "Exception"; 68 66 69 if ( this->filename_ != "")67 if (!this->filename_.empty()) 70 68 { 71 69 fullDesc << " in " << this->filename_; 72 70 if (this->lineNumber_) 73 fullDesc << "(" << this->lineNumber_ << ")";71 fullDesc << '(' << this->lineNumber_ << ')'; 74 72 } 75 73 76 if ( this->functionName_ != "")77 fullDesc << " in function '" << this->functionName_ << "'";74 if (!this->functionName_.empty()) 75 fullDesc << " in function '" << this->functionName_ << '\''; 78 76 79 77 fullDesc << ": "; 80 if ( this->description_ != "")78 if (!this->description_.empty()) 81 79 fullDesc << this->description_; 82 80 else 83 81 fullDesc << "No description available."; 84 82 85 this->fullDescription_ = std::string(fullDesc.str());83 this->fullDescription_ = fullDesc.str(); 86 84 } 87 85 -
code/trunk/src/libraries/util/Exception.h
r5747 r6417 131 131 CREATE_ORXONOX_EXCEPTION(PluginsNotFound); 132 132 CREATE_ORXONOX_EXCEPTION(InitialisationFailed); 133 CREATE_ORXONOX_EXCEPTION(InitialisationAborted); 133 134 CREATE_ORXONOX_EXCEPTION(NotImplemented); 134 135 CREATE_ORXONOX_EXCEPTION(GameState); -
code/trunk/src/libraries/util/ExprParser.cc
r5738 r6417 47 47 namespace orxonox 48 48 { 49 ExprParser::ExprParser( const std::string& str)49 ExprParser::ExprParser() 50 50 { 51 51 this->failed_ = false; 52 this->variables_["pi"] = 3.1415926535897932; 53 this->variables_["e"] = 2.7182818284590452; 54 } 55 56 void ExprParser::setVariable(const std::string& varname, double value) 57 { 58 this->variables_[varname] = value; 59 } 60 61 void ExprParser::parse(const std::string& str) 62 { 52 63 this->reading_stream = str.c_str(); 53 64 if (str.size() == 0 || *reading_stream == '\0') … … 343 354 else 344 355 { 345 #define SWITCH word 346 CASE_1("pi") 347 value = 3.1415926535897932; 348 CASE("e") 349 value = 2.7182818284590452; 350 CASE_ELSE 356 std::map<std::string, double>::const_iterator it = this->variables_.find(word); 357 if (it != this->variables_.end()) 358 value = it->second; 359 else 351 360 { 352 361 this->failed_ = true; … … 358 367 } 359 368 else if (*reading_stream == 40) 360 { // expres ion in paranthesis369 { // expression in parenthesis 361 370 ++reading_stream; 362 371 value = parse_last_argument(); -
code/trunk/src/libraries/util/ExprParser.h
r5738 r6417 36 36 37 37 #include "UtilPrereqs.h" 38 39 #include <map> 38 40 #include <string> 39 41 … … 71 73 72 74 73 ExprParser(const std::string& str); 75 ExprParser(); 76 void parse(const std::string& str); 74 77 const std::string& getRemains() { return this->remains_; } 75 78 double getResult() { return this->result_; } 76 79 bool getSuccess() { return !this->failed_; } 80 81 void setVariable(const std::string& varname, double value); 77 82 78 83 private: … … 97 102 double result_; 98 103 std::string remains_; 99 104 std::map<std::string, double> variables_; 100 105 }; 101 106 -
code/trunk/src/libraries/util/Math.cc
r5738 r6417 43 43 namespace orxonox 44 44 { 45 #if OGRE_VERSION < 0x010603 45 46 /** 46 47 @brief Function for writing a Radian to a stream. … … 51 52 return out; 52 53 } 54 55 /** 56 @brief Function for writing a Degree to a stream. 57 */ 58 std::ostream& operator<<(std::ostream& out, const orxonox::Degree& degree) 59 { 60 out << degree.valueDegrees(); 61 return out; 62 } 63 #endif 53 64 54 65 /** … … 61 72 radian = temp; 62 73 return in; 63 }64 65 /**66 @brief Function for writing a Degree to a stream.67 */68 std::ostream& operator<<(std::ostream& out, const orxonox::Degree& degree)69 {70 out << degree.valueDegrees();71 return out;72 74 } 73 75 … … 136 138 return orxonox::Vector2(0, 1); 137 139 } 138 140 139 141 float cos_value = clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1); 140 142 float sin_value = sqrt( 1 - cos_value*cos_value ); 141 143 142 144 if ((mydirection.crossProduct(myorthonormal)).dotProduct(distance) > 0) 143 145 return orxonox::Vector2( sin_value, cos_value ); … … 177 179 } 178 180 //float angle = acos(clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1)); 179 181 180 182 float cos_value = clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1); 181 183 float sin_value = sqrt( 1 - cos_value*cos_value ); -
code/trunk/src/libraries/util/Math.h
r5738 r6417 59 59 namespace orxonox 60 60 { 61 #if OGRE_VERSION < 0x010603 61 62 _UtilExport std::ostream& operator<<(std::ostream& out, const orxonox::Radian& radian); 63 _UtilExport std::ostream& operator<<(std::ostream& out, const orxonox::Degree& degree); 64 #endif 62 65 _UtilExport std::istream& operator>>(std::istream& in, orxonox::Radian& radian); 63 _UtilExport std::ostream& operator<<(std::ostream& out, const orxonox::Degree& degree);64 66 _UtilExport std::istream& operator>>(std::istream& in, orxonox::Degree& degree); 65 67 … … 163 165 template <> inline bool zeroise<bool>() { return 0; } 164 166 template <> inline void* zeroise<void*>() { return 0; } 165 template <> inline std::string zeroise<std::string>() { return ""; }167 template <> inline std::string zeroise<std::string>() { return std::string(); } 166 168 template <> inline orxonox::Radian zeroise<orxonox::Radian>() { return orxonox::Radian(0.0f); } 167 169 template <> inline orxonox::Degree zeroise<orxonox::Degree>() { return orxonox::Degree(0.0f); } -
code/trunk/src/libraries/util/MathConvert.h
r5738 r6417 53 53 { 54 54 std::ostringstream ostream; 55 if (ostream << input.x << ","<< input.y)55 if (ostream << input.x << ',' << input.y) 56 56 { 57 57 (*output) = ostream.str(); … … 69 69 { 70 70 std::ostringstream ostream; 71 if (ostream << input.x << "," << input.y << ","<< input.z)71 if (ostream << input.x << ',' << input.y << ',' << input.z) 72 72 { 73 73 (*output) = ostream.str(); … … 85 85 { 86 86 std::ostringstream ostream; 87 if (ostream << input.x << "," << input.y << "," << input.z << ","<< input.w)87 if (ostream << input.x << ',' << input.y << ',' << input.z << ',' << input.w) 88 88 { 89 89 (*output) = ostream.str(); … … 101 101 { 102 102 std::ostringstream ostream; 103 if (ostream << input.w << "," << input.x << "," << input.y << ","<< input.z)103 if (ostream << input.w << ',' << input.x << ',' << input.y << ',' << input.z) 104 104 { 105 105 (*output) = ostream.str(); … … 117 117 { 118 118 std::ostringstream ostream; 119 if (ostream << input.r << "," << input.g << "," << input.b << ","<< input.a)119 if (ostream << input.r << ',' << input.g << ',' << input.b << ',' << input.a) 120 120 { 121 121 (*output) = ostream.str(); -
code/trunk/src/libraries/util/MultiType.h
r5738 r6417 232 232 233 233 virtual void toString(std::ostream& outstream) const = 0; 234 234 235 235 virtual void importData( uint8_t*& mem )=0; 236 236 virtual void exportData( uint8_t*& mem ) const=0; … … 339 339 template <typename T> inline bool isType() const { return false; } // Only works for specialized values - see below 340 340 std::string getTypename() const; 341 341 342 342 /** @brief Saves the value of the MT to a bytestream (pointed at by mem) and increases mem pointer by size of MT */ 343 343 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); } -
code/trunk/src/libraries/util/MultiTypeValue.h
r5738 r6417 150 150 /** @brief Puts the current value on the stream */ 151 151 inline void toString(std::ostream& outstream) const { outstream << this->value_; } 152 152 153 153 /** @brief loads data from the bytestream (mem) into the MT and increases the bytestream pointer by the size of the data */ 154 154 inline void importData( uint8_t*& mem ) { loadAndIncrease( /*(const T&)*/this->value_, mem ); } … … 160 160 T value_; //!< The stored value 161 161 }; 162 162 163 163 // Import / Export specialisation 164 164 // ColourValue -
code/trunk/src/libraries/util/OutputHandler.cc
r6105 r6417 39 39 #include <cstdlib> 40 40 #include <fstream> 41 #include <iostream> 41 42 #include <sstream> 42 43 … … 76 77 #ifdef ORXONOX_PLATFORM_WINDOWS 77 78 char* pTempDir = getenv("TEMP"); 78 this->logFilename_ = std::string(pTempDir) + "/"+ logFileBaseName_g;79 this->logFilename_ = std::string(pTempDir) + '/' + logFileBaseName_g; 79 80 #else 80 81 this->logFilename_ = std::string("/tmp/") + logFileBaseName_g; … … 174 175 void outputChanged(int level) 175 176 { 176 // Read ostringstream and store it 177 this->output_.push_back(std::make_pair(level, this->buffer_.str())); 178 // Clear content and flags 179 this->buffer_.str(std::string()); 177 if (!this->buffer_.str().empty()) 178 { 179 // Read ostringstream and store it 180 this->output_.push_back(std::make_pair(level, this->buffer_.str())); 181 // Clear content and flags 182 this->buffer_.str(std::string()); 183 } 180 184 this->buffer_.clear(); 181 185 } … … 214 218 this->registerOutputListener(this->consoleWriter_); 215 219 216 this->output_ 220 this->output_ = new MemoryLogWriter(); 217 221 // We capture as much input as the listener with the highest level 218 222 this->output_->softDebugLevel_ = getSoftDebugLevel(); … … 224 228 { 225 229 delete this->logFile_; 230 delete this->consoleWriter_; 226 231 delete this->output_; 227 232 } -
code/trunk/src/libraries/util/Serialise.h
r5738 r6417 37 37 #include <cstring> 38 38 #include "util/Math.h" 39 #include "util/mbool.h" 39 40 40 41 namespace orxonox{ 41 42 // general template declaration 43 42 44 43 /** @brief returns the size of the variable in a datastream */ 45 template <class T> inline uint32_t returnSize( const T& );44 template <class T> inline uint32_t returnSize( const T& variable ); 46 45 /** @brief loads the value of a variable out of the bytestream and increases the mem pointer */ 47 template <class T> inline void loadAndIncrease( const T& , uint8_t*&);46 template <class T> inline void loadAndIncrease( const T& variable, uint8_t*& mem ); 48 47 /** @brief saves the value of a variable into the bytestream and increases the mem pointer */ 49 template <class T> inline void saveAndIncrease( const T& , uint8_t*&);48 template <class T> inline void saveAndIncrease( const T& variable, uint8_t*& mem ); 50 49 /** @brief checks whether the variable of type T is the same as in the bytestream */ 51 template <class T> inline bool checkEquality( const T&, uint8_t*);50 template <class T> inline bool checkEquality( const T& variable, uint8_t* mem ); 52 51 53 52 // =================== Template specialisation stuff ============= … … 203 202 return sizeof(uint32_t); 204 203 } 205 204 206 205 template <> inline void loadAndIncrease( const unsigned int& variable, uint8_t*& mem ) 207 206 { … … 376 375 double temp; 377 376 memcpy(&temp, mem, sizeof(uint64_t)); 378 *(long double*)( &variable ) = static_cast< constlong double>(temp);377 *(long double*)( &variable ) = static_cast<long double>(temp); 379 378 mem += returnSize( variable ); 380 379 } … … 471 470 return variable==Degree(*r); 472 471 } 473 474 472 473 // =========== Vector2 474 475 template <> inline uint32_t returnSize( const Vector2& variable ) 476 { 477 return returnSize( variable.x )+returnSize( variable.y ); 478 } 479 480 template <> inline void saveAndIncrease( const Vector2& variable, uint8_t*& mem ) 481 { 482 saveAndIncrease( variable.x, mem ); 483 saveAndIncrease( variable.y, mem ); 484 } 485 486 template <> inline void loadAndIncrease( const Vector2& variable, uint8_t*& mem ) 487 { 488 loadAndIncrease( variable.x, mem ); 489 loadAndIncrease( variable.y, mem ); 490 } 491 492 template <> inline bool checkEquality( const Vector2& variable, uint8_t* mem ) 493 { 494 return checkEquality(variable.x, mem) && checkEquality(variable.y, mem+returnSize(variable.x)); 495 } 496 497 // =========== Vector3 498 499 template <> inline uint32_t returnSize( const Vector3& variable ) 500 { 501 return returnSize( variable.x )+returnSize( variable.y )+returnSize( variable.z ); 502 } 503 504 template <> inline void saveAndIncrease( const Vector3& variable, uint8_t*& mem ) 505 { 506 saveAndIncrease( variable.x, mem ); 507 saveAndIncrease( variable.y, mem ); 508 saveAndIncrease( variable.z, mem ); 509 } 510 511 template <> inline void loadAndIncrease( const Vector3& variable, uint8_t*& mem ) 512 { 513 loadAndIncrease( variable.x, mem ); 514 loadAndIncrease( variable.y, mem ); 515 loadAndIncrease( variable.z, mem ); 516 } 517 518 template <> inline bool checkEquality( const Vector3& variable, uint8_t* mem ) 519 { 520 return checkEquality(variable.x, mem) && checkEquality(variable.y, mem+returnSize(variable.x)) && 521 checkEquality(variable.z, mem+returnSize(variable.x)+returnSize(variable.y)); 522 } 523 524 // =========== Vector4 525 526 template <> inline uint32_t returnSize( const Vector4& variable ) 527 { 528 return returnSize( variable.w )+returnSize( variable.x )+returnSize( variable.y )+returnSize( variable.z ); 529 } 530 531 template <> inline void saveAndIncrease( const Vector4& variable, uint8_t*& mem ) 532 { 533 saveAndIncrease( variable.w, mem ); 534 saveAndIncrease( variable.x, mem ); 535 saveAndIncrease( variable.y, mem ); 536 saveAndIncrease( variable.z, mem ); 537 } 538 539 template <> inline void loadAndIncrease( const Vector4& variable, uint8_t*& mem ) 540 { 541 loadAndIncrease( variable.w, mem ); 542 loadAndIncrease( variable.x, mem ); 543 loadAndIncrease( variable.y, mem ); 544 loadAndIncrease( variable.z, mem ); 545 } 546 547 template <> inline bool checkEquality( const Vector4& variable, uint8_t* mem ) 548 { 549 return checkEquality(variable.w, mem) && checkEquality(variable.x, mem+returnSize(variable.w)) && 550 checkEquality(variable.y, mem+returnSize(variable.w)+returnSize(variable.x)) && 551 checkEquality(variable.z, mem+returnSize(variable.w)+returnSize(variable.x)+returnSize(variable.y)); 552 } 553 554 // =========== Quaternion 555 556 template <> inline uint32_t returnSize( const Quaternion& variable ) 557 { 558 return returnSize( variable.w )+returnSize( variable.x )+returnSize( variable.y )+returnSize( variable.z ); 559 } 560 561 template <> inline void saveAndIncrease( const Quaternion& variable, uint8_t*& mem ) 562 { 563 saveAndIncrease( variable.w, mem ); 564 saveAndIncrease( variable.x, mem ); 565 saveAndIncrease( variable.y, mem ); 566 saveAndIncrease( variable.z, mem ); 567 } 568 569 template <> inline void loadAndIncrease( const Quaternion& variable, uint8_t*& mem ) 570 { 571 loadAndIncrease( variable.w, mem ); 572 loadAndIncrease( variable.x, mem ); 573 loadAndIncrease( variable.y, mem ); 574 loadAndIncrease( variable.z, mem ); 575 } 576 577 template <> inline bool checkEquality( const Quaternion& variable, uint8_t* mem ) 578 { 579 return checkEquality(variable.w, mem) && checkEquality(variable.x, mem+returnSize(variable.w)) && 580 checkEquality(variable.y, mem+returnSize(variable.w)+returnSize(variable.x)) && 581 checkEquality(variable.z, mem+returnSize(variable.w)+returnSize(variable.x)+returnSize(variable.y)); 582 } 583 584 // =========== ColourValue 585 586 template <> inline uint32_t returnSize( const ColourValue& variable ) 587 { 588 return returnSize( variable.r )+returnSize( variable.g )+returnSize( variable.b )+returnSize( variable.a ); 589 } 590 591 template <> inline void saveAndIncrease( const ColourValue& variable, uint8_t*& mem ) 592 { 593 saveAndIncrease( variable.r, mem ); 594 saveAndIncrease( variable.g, mem ); 595 saveAndIncrease( variable.b, mem ); 596 saveAndIncrease( variable.a, mem ); 597 } 598 599 template <> inline void loadAndIncrease( const ColourValue& variable, uint8_t*& mem ) 600 { 601 loadAndIncrease( variable.r, mem ); 602 loadAndIncrease( variable.g, mem ); 603 loadAndIncrease( variable.b, mem ); 604 loadAndIncrease( variable.a, mem ); 605 } 606 607 template <> inline bool checkEquality( const ColourValue& variable, uint8_t* mem ) 608 { 609 return checkEquality(variable.r, mem) && checkEquality(variable.g, mem+returnSize(variable.r)) && 610 checkEquality(variable.b, mem+returnSize(variable.r)+returnSize(variable.g)) && 611 checkEquality(variable.a, mem+returnSize(variable.r)+returnSize(variable.g)+returnSize(variable.b)); 612 } 613 614 // =========== mbool 615 616 template <> inline uint32_t returnSize( const mbool& variable ) 617 { 618 return returnSize( (unsigned char&)((mbool&)variable).getMemory() ); 619 } 620 621 template <> inline void saveAndIncrease( const mbool& variable, uint8_t*& mem ) 622 { 623 saveAndIncrease( (unsigned char&)((mbool&)variable).getMemory(), mem ); 624 } 625 626 template <> inline void loadAndIncrease( const mbool& variable, uint8_t*& mem ) 627 { 628 loadAndIncrease( (unsigned char&)((mbool&)variable).getMemory(), mem ); 629 } 630 631 template <> inline bool checkEquality( const mbool& variable, uint8_t* mem ) 632 { 633 return checkEquality( (unsigned char&)((mbool&)variable).getMemory(), mem ); 634 } 475 635 } 476 636 -
code/trunk/src/libraries/util/Singleton.h
r5929 r6417 56 56 57 57 //! Update method called by ClassSingletonManager (if used) 58 void updateSingleton(const Clock& time) { static_cast<T*>(T::singletonPtr_s)->update(time); }58 void preUpdateSingleton(const Clock& time) { static_cast<T*>(T::singletonPtr_s)->preUpdate(time); } 59 59 //! Empty update method for the static polymorphism 60 void update(const Clock& time) { } 60 void preUpdate(const Clock& time) { } 61 //! Update method called by ClassSingletonManager (if used) 62 void postUpdateSingleton(const Clock& time) { static_cast<T*>(T::singletonPtr_s)->postUpdate(time); } 63 //! Empty update method for the static polymorphism 64 void postUpdate(const Clock& time) { } 61 65 62 66 protected: -
code/trunk/src/libraries/util/StringUtils.cc
r5738 r6417 40 40 namespace orxonox 41 41 { 42 std::string BLANKSTRING ("");42 std::string BLANKSTRING; 43 43 44 44 std::string getUniqueNumberString() … … 54 54 { 55 55 size_t pos; 56 while ((pos = (*str).find(" ")) < (*str).length())57 (*str).erase(pos, 1);58 while ((pos = (*str).find("\t")) < (*str).length())59 (*str).erase(pos, 1);60 while ((pos = (*str).find("\n")) < (*str).length())61 (*str).erase(pos, 1);56 while ((pos = str->find(' ')) < str->length()) 57 str->erase(pos, 1); 58 while ((pos = str->find('\t')) < str->length()) 59 str->erase(pos, 1); 60 while ((pos = str->find('\n')) < str->length()) 61 str->erase(pos, 1); 62 62 } 63 63 … … 69 69 std::string getStripped(const std::string& str) 70 70 { 71 std::string output = std::string(str);71 std::string output(str); 72 72 strip(&output); 73 73 return output; … … 98 98 size_t quote = start - 1; 99 99 100 while ((quote = str.find(' \"', quote + 1)) != std::string::npos)100 while ((quote = str.find('"', quote + 1)) != std::string::npos) 101 101 { 102 102 size_t backslash = quote; … … 231 231 { 232 232 // Strip the line, whitespaces are disturbing 233 std::stringteststring = getStripped(str);233 const std::string& teststring = getStripped(str); 234 234 235 235 // There are four possible comment-symbols: … … 259 259 bool isEmpty(const std::string& str) 260 260 { 261 std::string temp = getStripped(str); 262 return ((temp == "") || (temp.size() == 0)); 261 return getStripped(str).empty(); 263 262 } 264 263 … … 303 302 for (size_t pos = 0; (pos = output.find('\f', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\f"); } 304 303 for (size_t pos = 0; (pos = output.find('\a', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\a"); } 305 for (size_t pos = 0; (pos = output.find('"' , pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\\""); }304 for (size_t pos = 0; (pos = output.find('"' , pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\\""); } 306 305 for (size_t pos = 0; (pos = output.find('\0', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\0"); } 307 306 … … 319 318 return str; 320 319 321 std::string output = "";320 std::string output; 322 321 for (size_t pos = 0; pos < str.size() - 1; ) 323 322 { … … 363 362 std::string getLowercase(const std::string& str) 364 363 { 365 std::string output = std::string(str);364 std::string output(str); 366 365 lowercase(&output); 367 366 return output; … … 387 386 std::string getUppercase(const std::string& str) 388 387 { 389 std::string output = std::string(str);388 std::string output(str); 390 389 uppercase(&output); 391 390 return output; -
code/trunk/src/libraries/util/SubString.cc
r6061 r6417 270 270 } 271 271 else 272 { 273 static std::string empty; 274 return empty; 275 } 272 return ""; 276 273 } 277 274 -
code/trunk/src/libraries/util/UtilPrereqs.h
r6105 r6417 131 131 } 132 132 133 // Just so you don't have to include StringUtils.h everywhere just for this 134 namespace orxonox 135 { 136 extern _UtilExport std::string BLANKSTRING; 137 } 138 139 133 140 #endif /* _UtilPrereqs_H__ */ -
code/trunk/src/libraries/util/mbool.h
r5738 r6417 67 67 inline bool operator!() const 68 68 { return (!this->value_.bool_); } 69 69 70 70 inline unsigned char& getMemory(){ return value_.memory_; } 71 71
Note: See TracChangeset
for help on using the changeset viewer.