Changeset 7163 for code/trunk/src/libraries/util
- Timestamp:
- Aug 11, 2010, 8:55:13 AM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 6 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/util/CMakeLists.txt
r6503 r7163 27 27 Clipboard.cc 28 28 Clock.cc 29 Convert.cc 29 30 CRC32.cc 30 31 ExprParser.cc … … 49 50 ORXONOX_ADD_LIBRARY(util 50 51 FIND_HEADER_FILES 51 DEFINE_SYMBOL52 "UTIL_SHARED_BUILD"53 52 LINK_LIBRARIES 54 53 ${CEGUI_LIBRARY} -
code/trunk/src/libraries/util/Convert.h
r6417 r7163 64 64 65 65 Defining your own functions: 66 There are obviously 4 ways to specif iy a user defined conversion. What should Iuse?66 There are obviously 4 ways to specify a user defined conversion. What should you use? 67 67 68 68 Usually, ConverterFallback fits quite well. You won't have to deal with the conversion from … … 70 70 71 71 However if you want to overwrite an implicit conversion or an iostream operator, you really need to 72 make use of ConverterExplicit. 72 make use of ConverterExplicit. We have to do this for the Ogre classes for instance because they 73 define stream operators we don't particulary like. 73 74 */ 74 75 … … 388 389 }; 389 390 390 // Declarations to avoid StringUtils.h include391 _UtilExport std::string removeTrailingWhitespaces(const std::string& str);392 _UtilExport std::string getLowercase(const std::string& str);393 394 391 // std::string to bool 395 392 template <> 396 struct ConverterExplicit<std::string, bool> 397 { 398 static bool convert(bool* output, const std::string& input) 399 { 400 const std::string& stripped = getLowercase(removeTrailingWhitespaces(input)); 401 if (stripped == "true" || stripped == "on" || stripped == "yes") 402 { 403 *output = true; 404 return true; 405 } 406 else if (stripped == "false" || stripped == "off" || stripped == "no") 407 { 408 *output = false; 409 return true; 410 } 411 412 std::istringstream iss(input); 413 if (iss >> (*output)) 414 return true; 415 else 416 return false; 417 } 393 struct _UtilExport ConverterExplicit<std::string, bool> 394 { 395 static bool convert(bool* output, const std::string& input); 418 396 }; 419 397 } -
code/trunk/src/libraries/util/Serialise.h
r6746 r7163 38 38 39 39 #include <cstring> 40 #include <set> 40 41 #include "Math.h" 41 42 #include "mbool.h" … … 52 53 template <class T> inline bool checkEquality( const T& variable, uint8_t* mem ); 53 54 55 56 // =========== char* 57 58 inline uint32_t returnSize( char*& variable ) 59 { 60 return strlen(variable)+1; 61 } 62 63 inline void saveAndIncrease( char*& variable, uint8_t*& mem ) 64 { 65 strcpy((char*)mem, variable); 66 mem += returnSize(variable); 67 } 68 69 inline void loadAndIncrease( char*& variable, uint8_t*& mem ) 70 { 71 if( variable ) 72 delete variable; 73 uint32_t len = strlen((char*)mem)+1; 74 variable = new char[len]; 75 strcpy((char*)variable, (char*)mem); 76 mem += len; 77 } 78 79 inline bool checkEquality( char*& variable, uint8_t* mem ) 80 { 81 return strcmp(variable, (char*)mem)==0; 82 } 83 54 84 // =================== Template specialisation stuff ============= 55 85 … … 393 423 return memcmp(&temp, mem, sizeof(uint64_t))==0; 394 424 } 395 425 396 426 // =========== string 397 427 … … 635 665 return checkEquality( (unsigned char&)((mbool&)variable).getMemory(), mem ); 636 666 } 667 668 // =========== std::set 669 670 template <class T> inline uint32_t returnSize( const std::set<T>& variable ) 671 { 672 uint32_t tempsize = sizeof(uint32_t); // for the number of entries 673 for( typename std::set<T>::iterator it=((std::set<T>*)(&variable))->begin(); it!=((std::set<T>*)(&variable))->end(); ++it) 674 tempsize += returnSize( *it ); 675 return tempsize; 676 } 677 678 template <class T> inline void saveAndIncrease( const std::set<T>& variable, uint8_t*& mem ) 679 { 680 typename std::set<T>::const_iterator it = variable.begin(); 681 saveAndIncrease( (uint32_t)variable.size(), mem ); 682 for( ; it!=variable.end(); ++it ) 683 saveAndIncrease( *it, mem ); 684 } 685 686 template <class T> inline void loadAndIncrease( const std::set<T>& variable, uint8_t*& mem ) 687 { 688 uint32_t nrOfElements = 0; 689 loadAndIncrease( nrOfElements, mem ); 690 typename std::set<T>::const_iterator it = variable.begin(); 691 for( uint32_t i = 0; i<nrOfElements; ++i ) 692 { 693 T temp; 694 loadAndIncrease(temp, mem); 695 while( it!=variable.end() && *it!=temp ) 696 { 697 ((std::set<T>*)(&variable))->erase(it++); 698 ++it; 699 } 700 if( it==variable.end() ) 701 { 702 ((std::set<T>*)(&variable))->insert(temp); 703 } 704 } 705 } 706 707 template <class T> inline bool checkEquality( const std::set<T>& variable, uint8_t* mem ) 708 { 709 uint8_t* temp = mem; 710 uint32_t nrOfElements; 711 loadAndIncrease(nrOfElements, mem); 712 if( variable.size() == nrOfElements ) 713 { 714 T tempT; 715 for( uint32_t i=0; i<nrOfElements; ++i ) 716 { 717 loadAndIncrease(tempT, mem); 718 if( variable.find(tempT) == variable.end() ) 719 { 720 mem = temp; 721 return false; 722 } 723 } 724 } 725 else 726 { 727 mem = temp; 728 return false; 729 } 730 return true; 731 } 637 732 } 638 733 -
code/trunk/src/libraries/util/SignalHandler.cc
r5738 r7163 124 124 if( SignalHandler::singletonPtr_s == 0 ) 125 125 { 126 COUT(0) << "rec ieved signal " << sigName.c_str() << std::endl << "can't write backtrace because SignalHandler already destroyed" << std::endl;126 COUT(0) << "received signal " << sigName.c_str() << std::endl << "can't write backtrace because SignalHandler already destroyed" << std::endl; 127 127 exit(EXIT_FAILURE); 128 128 } … … 134 134 135 135 136 COUT(0) << "rec ieved signal " << sigName.c_str() << std::endl << "try to write backtrace to file orxonox_crash.log" << std::endl;136 COUT(0) << "received signal " << sigName.c_str() << std::endl << "try to write backtrace to file orxonox_crash.log" << std::endl; 137 137 138 138 int sigPipe[2]; -
code/trunk/src/libraries/util/Singleton.h
r6751 r7163 31 31 32 32 #include "UtilPrereqs.h" 33 33 34 #include <cassert> 35 #include <cstring> 34 36 35 37 namespace orxonox
Note: See TracChangeset
for help on using the changeset viewer.