Changeset 7284 for code/trunk/src/libraries/util
- Timestamp:
- Aug 31, 2010, 3:37:40 AM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 10 edited
- 7 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/util/CMakeLists.txt
r7226 r7284 31 31 CRC32.cc 32 32 OutputHandler.cc 33 ScopedSingletonManager.cc 34 SharedPtr.cc 33 35 SignalHandler.cc 34 36 Sleep.cc 37 SmallObjectAllocator.cc 35 38 SubString.cc 36 39 COMPILATION_END -
code/trunk/src/libraries/util/Convert.h
r7266 r7284 109 109 } 110 110 }; 111 112 //////////// 113 // upcast // 114 //////////// 115 namespace detail 116 { 117 // perform a static cast if ToType is a base of FromType 118 template<class ToType, class FromType> 119 FORCEINLINE ToType upcast(FromType input, Loki::Int2Type<true>) 120 { 121 return static_cast<ToType>(input); 122 } 123 124 // return zero if ToType is not a base of FromType 125 template<class ToType, class FromType> 126 FORCEINLINE ToType upcast(FromType input, Loki::Int2Type<false>) 127 { 128 return 0; 129 } 130 } 131 132 // performs an upcast if ToType is a base of FromType, returns zero otherwise 133 template <class ToType, class FromType> 134 FORCEINLINE ToType upcast(FromType input) 135 { 136 enum { probe = ImplicitConversion<FromType, ToType>::exists }; 137 return detail::upcast<ToType, FromType>(input, Loki::Int2Type<probe>()); 138 } 111 139 } 112 140 -
code/trunk/src/libraries/util/Math.cc
r7184 r7284 234 234 bool ConverterFallback<std::string, orxonox::Vector2>::convert(orxonox::Vector2* output, const std::string& input) 235 235 { 236 size_t opening_parenthesis, closing_parenthesis = input.find(' )');237 if ((opening_parenthesis = input.find(' (')) == std::string::npos)236 size_t opening_parenthesis, closing_parenthesis = input.find('}'); 237 if ((opening_parenthesis = input.find('{')) == std::string::npos) 238 238 opening_parenthesis = 0; 239 239 else … … 257 257 bool ConverterFallback<std::string, orxonox::Vector3>::convert(orxonox::Vector3* output, const std::string& input) 258 258 { 259 size_t opening_parenthesis, closing_parenthesis = input.find(' )');260 if ((opening_parenthesis = input.find(' (')) == std::string::npos)259 size_t opening_parenthesis, closing_parenthesis = input.find('}'); 260 if ((opening_parenthesis = input.find('{')) == std::string::npos) 261 261 opening_parenthesis = 0; 262 262 else … … 282 282 bool ConverterFallback<std::string, orxonox::Vector4>::convert(orxonox::Vector4* output, const std::string& input) 283 283 { 284 size_t opening_parenthesis, closing_parenthesis = input.find(' )');285 if ((opening_parenthesis = input.find(' (')) == std::string::npos)284 size_t opening_parenthesis, closing_parenthesis = input.find('}'); 285 if ((opening_parenthesis = input.find('{')) == std::string::npos) 286 286 opening_parenthesis = 0; 287 287 else … … 309 309 bool ConverterFallback<std::string, orxonox::Quaternion>::convert(orxonox::Quaternion* output, const std::string& input) 310 310 { 311 size_t opening_parenthesis, closing_parenthesis = input.find(')'); 312 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 311 size_t opening_parenthesis, closing_parenthesis = input.find('}'); 312 if ((opening_parenthesis = input.find('{')) == std::string::npos) 313 opening_parenthesis = 0; 314 else 315 opening_parenthesis++; 313 316 314 317 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); … … 332 335 bool ConverterFallback<std::string, orxonox::ColourValue>::convert(orxonox::ColourValue* output, const std::string& input) 333 336 { 334 size_t opening_parenthesis, closing_parenthesis = input.find(')'); 335 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 337 size_t opening_parenthesis, closing_parenthesis = input.find('}'); 338 if ((opening_parenthesis = input.find('{')) == std::string::npos) 339 opening_parenthesis = 0; 340 else 341 opening_parenthesis++; 336 342 337 343 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); -
code/trunk/src/libraries/util/MultiType.h
r7268 r7284 77 77 #include <OgreColourValue.h> 78 78 #include <loki/TypeTraits.h> 79 #include "mbool.h" 79 80 80 81 namespace orxonox … … 265 266 inline MultiType(const orxonox::Radian& value) : value_(0) { this->assignValue(value); } /** @brief Constructor: Assigns the given value and sets the type. */ 266 267 inline MultiType(const orxonox::Degree& value) : value_(0) { this->assignValue(value); } /** @brief Constructor: Assigns the given value and sets the type. */ 268 inline MultiType(const orxonox::mbool& value) : value_(0) { this->assignValue((bool)value); } /** @brief Constructor: Assigns the given mbool and converts it to bool. */ 267 269 inline MultiType(const char* value) : value_(0) { this->setValue(std::string(value)); } /** @brief Constructor: Converts the char array to a std::string, assigns the value and sets the type. */ 268 270 inline MultiType(const MultiType& other) : value_(0) { this->setValue(other); } /** @brief Copyconstructor: Assigns value and type of the other MultiType. */ … … 318 320 inline void copy(const MultiType& other) { if (this == &other) { return; } if (this->value_) { delete this->value_; } this->value_ = (other.value_) ? other.value_->clone() : 0; } 319 321 320 template <typename T> inline bool convert() { return this->setValue<T>(( T)(*this)); } /** @brief Converts the current value to type T. */322 template <typename T> inline bool convert() { return this->setValue<T>((typename Loki::TypeTraits<T>::UnqualifiedReferredType)(*this)); } /** @brief Converts the current value to type T. */ 321 323 inline bool convert(const MultiType& other) { return this->convert(other.getType()); } /** @brief Converts the current value to the type of the other MultiType. */ 322 324 bool convert(MT_Type::Value type); … … 350 352 351 353 /** @brief Checks whether the value is a default one. */ 352 bool hasDefaultValue() const { return this->value_->hasDefaultValue(); } 354 bool hasDefaultValue() const { return this->value_->hasDefaultValue(); } 355 356 /** @brief Checks if the MT contains no value. */ 357 bool null() const { return (!this->value_); } 353 358 354 359 operator char() const; … … 487 492 template <> inline bool MultiType::isType<orxonox::Degree>() const { return (this->value_ && this->value_->type_ == MT_Type::Degree); } /** @brief Returns true if the current type equals the given type. */ 488 493 494 template <> inline bool MultiType::convert<void>() { this->reset(); return true; } /** @brief Deletes the content, type becomes MT_Type::Null. */ 495 489 496 // Specialization to avoid ambiguities with the conversion operator 490 497 template <> inline bool MultiType::convert<std::string>() { return this->setValue<std::string> (this->operator std::string()); } /** @brief Converts the current value to the given type. */ -
code/trunk/src/libraries/util/OutputHandler.h
r6105 r7284 104 104 105 105 //! Writes to all output devices 106 static inline const std::string&log(const std::string& text)107 { OutputHandler::getOutStream(0).output(text) << std::endl; return text;}106 static inline void log(const std::string& text) 107 { OutputHandler::getOutStream(0).output(text) << std::endl; } 108 108 109 109 //! Writes an error message to the output 110 static inline const std::string&error(const std::string& text)111 { OutputHandler::getOutStream(1).output(text) << std::endl; return text;}110 static inline void error(const std::string& text) 111 { OutputHandler::getOutStream(1).output(text) << std::endl; } 112 112 113 113 //! Writes a warning message to the output 114 static inline const std::string&warning(const std::string& text)115 { OutputHandler::getOutStream(2).output(text) << std::endl; return text;}114 static inline void warning(const std::string& text) 115 { OutputHandler::getOutStream(2).output(text) << std::endl; } 116 116 117 117 //! Writes an informational message to the output 118 static inline const std::string&info(const std::string& text)119 { OutputHandler::getOutStream(3).output(text) << std::endl; return text;}118 static inline void info(const std::string& text) 119 { OutputHandler::getOutStream(3).output(text) << std::endl; } 120 120 121 121 //! Writes a debug message to the output 122 static inline const std::string&debug(const std::string& text)123 { OutputHandler::getOutStream(4).output(text) << std::endl; return text;}122 static inline void debug(const std::string& text) 123 { OutputHandler::getOutStream(4).output(text) << std::endl; } 124 124 125 125 //! Registers an object that receives output via a provided std::ostream -
code/trunk/src/libraries/util/StringUtils.cc
r6424 r7284 35 35 36 36 #include <cctype> 37 #include <boost/scoped_array.hpp> 37 38 #include "Convert.h" 38 39 #include "Math.h" … … 514 515 @return Number of replacements 515 516 */ 516 _UtilExportsize_t replaceCharacters(std::string& str, char target, char replacement)517 size_t replaceCharacters(std::string& str, char target, char replacement) 517 518 { 518 519 size_t j = 0; … … 527 528 return j; 528 529 } 530 531 /** 532 @brief Calculates the Levenshtein distance between two strings. 533 534 The Levenshtein distance is defined by the number of transformations needed to convert str1 535 into str2. Possible transformations are substituted, added, or removed characters. 536 */ 537 unsigned int getLevenshteinDistance(const std::string& str1, const std::string& str2) 538 { 539 size_t cols = str1.size() + 1; 540 size_t rows = str2.size() + 1; 541 boost::scoped_array<int> matrix(new int[rows * cols]); 542 543 for (size_t r = 0; r < rows; ++r) 544 for (size_t c = 0; c < cols; ++c) 545 matrix[r*cols + c] = 0; 546 547 for (size_t i = 1; i < cols; ++i) 548 matrix[0*cols + i] = i; 549 for (size_t i = 1; i < rows; ++i) 550 matrix[i*cols + 0] = i; 551 552 for (size_t r = 1; r < rows; ++r) 553 for (size_t c = 1; c < cols; ++c) 554 matrix[r*cols + c] = (str1[c-1] != str2[r-1]); 555 556 for (size_t r = 1; r < rows; ++r) 557 for (size_t c = 1; c < cols; ++c) 558 matrix[r*cols + c] = std::min(std::min(matrix[(r-1)*cols + c] + 1, 559 matrix[r*cols + c-1] + 1), 560 matrix[(r-1)*cols + c-1] + (str1[c-1] != str2[r-1])); 561 562 return matrix[(rows-1)*cols + cols-1]; 563 } 529 564 } -
code/trunk/src/libraries/util/StringUtils.h
r5738 r7284 43 43 _UtilExport std::string getUniqueNumberString(); 44 44 45 _UtilExport void strip(std::string* str);46 _UtilExport std::string getStripped(const std::string& str);45 _UtilExport void strip(std::string* str); 46 _UtilExport std::string getStripped(const std::string& str); 47 47 48 _UtilExport std::string removeTrailingWhitespaces(const std::string& str);48 _UtilExport std::string removeTrailingWhitespaces(const std::string& str); 49 49 50 _UtilExport size_t getNextQuote(const std::string& str, size_t start);51 _UtilExport bool isBetweenQuotes(const std::string& str, size_t pos);50 _UtilExport size_t getNextQuote(const std::string& str, size_t start); 51 _UtilExport bool isBetweenQuotes(const std::string& str, size_t pos); 52 52 53 _UtilExport bool hasStringBetweenQuotes(const std::string& str);54 _UtilExport std::string getStringBetweenQuotes(const std::string& str);53 _UtilExport bool hasStringBetweenQuotes(const std::string& str); 54 _UtilExport std::string getStringBetweenQuotes(const std::string& str); 55 55 56 _UtilExport std::string stripEnclosingQuotes(const std::string& str);57 _UtilExport std::string stripEnclosingBraces(const std::string& str);56 _UtilExport std::string stripEnclosingQuotes(const std::string& str); 57 _UtilExport std::string stripEnclosingBraces(const std::string& str); 58 58 59 _UtilExport bool isEmpty(const std::string& str);60 _UtilExport bool isComment(const std::string& str);61 _UtilExport bool isNumeric(const std::string& str);59 _UtilExport bool isEmpty(const std::string& str); 60 _UtilExport bool isComment(const std::string& str); 61 _UtilExport bool isNumeric(const std::string& str); 62 62 63 _UtilExport std::string addSlashes(const std::string& str);64 _UtilExport std::string removeSlashes(const std::string& str);63 _UtilExport std::string addSlashes(const std::string& str); 64 _UtilExport std::string removeSlashes(const std::string& str); 65 65 66 _UtilExport void lowercase(std::string* str);67 _UtilExport std::string getLowercase(const std::string& str);66 _UtilExport void lowercase(std::string* str); 67 _UtilExport std::string getLowercase(const std::string& str); 68 68 69 _UtilExport void uppercase(std::string* str);70 _UtilExport std::string getUppercase(const std::string& str);69 _UtilExport void uppercase(std::string* str); 70 _UtilExport std::string getUppercase(const std::string& str); 71 71 72 _UtilExport int nocaseCmp(const std::string& s1, const std::string& s2);73 _UtilExport int nocaseCmp(const std::string& s1, const std::string& s2, size_t len);72 _UtilExport int nocaseCmp(const std::string& s1, const std::string& s2); 73 _UtilExport int nocaseCmp(const std::string& s1, const std::string& s2, size_t len); 74 74 75 _UtilExport bool hasComment(const std::string& str);76 _UtilExport std::string getComment(const std::string& str);77 _UtilExport size_t getCommentPosition(const std::string& str);78 _UtilExport size_t getNextCommentPosition(const std::string& str, size_t start = 0);75 _UtilExport bool hasComment(const std::string& str); 76 _UtilExport std::string getComment(const std::string& str); 77 _UtilExport size_t getCommentPosition(const std::string& str); 78 _UtilExport size_t getNextCommentPosition(const std::string& str, size_t start = 0); 79 79 80 _UtilExport size_t replaceCharacters(std::string& str, char target, char replacement); 80 _UtilExport size_t replaceCharacters(std::string& str, char target, char replacement); 81 82 _UtilExport unsigned int getLevenshteinDistance(const std::string& str1, const std::string& str2); 81 83 } 82 84 -
code/trunk/src/libraries/util/SubString.cc
r7165 r7284 309 309 * @param line the inputLine to split 310 310 * @param delimiters a String of Delimiters (here the input will be splitted) 311 * @param delimiterNeighbours N aighbours to the Delimitter, that will be removed if they are to the left or the right of a Delimiter.311 * @param delimiterNeighbours Neighbours to the Delimiter, that will be removed if they are to the left or the right of a Delimiter. 312 312 * @param emptyEntries: if empty Strings are added to the List of Strings. 313 313 * @param escape_char: Escape carater (escapes splitters) -
code/trunk/src/libraries/util/SubString.h
r5738 r7284 81 81 SL_SAFEESCAPE, //!< In safe mode with the internal escape character, that escapes even the savemode character. 82 82 SL_COMMENT, //!< In Comment mode. 83 SL_PARENTHESES, //!< Between parentheses (usually ' (' and ')')83 SL_PARENTHESES, //!< Between parentheses (usually '{' and '}') 84 84 SL_PARENTHESESESCAPE, //!< Between parentheses with the internal escape character, that escapes even the closing paranthesis character. 85 85 } SPLIT_LINE_STATE; … … 92 92 const std::string& delimiters, const std::string& delimiterNeighbours = "", bool emptyEntries=false, 93 93 char escapeChar ='\\', bool removeEscapeChar = true, char safemode_char = '"', bool removeSafemodeChar = true, 94 char openparenthesis_char = ' (', char closeparenthesis_char = ')', bool removeParenthesisChars = true, char comment_char = '\0');94 char openparenthesis_char = '{', char closeparenthesis_char = '}', bool removeParenthesisChars = true, char comment_char = '\0'); 95 95 SubString(unsigned int argc, const char** argv); 96 96 /** @brief create a Substring as a copy of another one. @param subString the SubString to copy. */ … … 116 116 const std::string& delimiters, const std::string& delimiterNeighbours = "", bool emptyEntries = false, 117 117 char escapeChar ='\\', bool removeExcapeChar = true, char safemode_char = '"', bool removeSafemodeChar = true, 118 char openparenthesis_char = ' (', char closeparenthesis_char = ')', bool removeParenthesisChars = true, char comment_char = '\0');118 char openparenthesis_char = '{', char closeparenthesis_char = '}', bool removeParenthesisChars = true, char comment_char = '\0'); 119 119 std::string join(const std::string& delimiter = " ") const; 120 120 //////////////////////////////////////// … … 155 155 char safemode_char = '"', 156 156 bool removeSafemodeChar = true, 157 char openparenthesis_char = ' (',158 char closeparenthesis_char = ' )',157 char openparenthesis_char = '{', 158 char closeparenthesis_char = '}', 159 159 bool removeParenthesisChars = true, 160 160 char comment_char = '\0',
Note: See TracChangeset
for help on using the changeset viewer.