Changeset 9047
- Timestamp:
- Mar 18, 2012, 6:43:24 PM (13 years ago)
- Location:
- code/branches/testing/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/testing/src/libraries/core/command/ConsoleCommand.h
r8858 r9047 222 222 #include <stack> 223 223 #include <vector> 224 #include <boost/preprocessor/cat.hpp>225 #include <boost/preprocessor/facilities/expand.hpp>226 224 227 225 #include "util/VA_NARGS.h" -
code/branches/testing/src/libraries/util/SubString.cc
r8858 r9047 87 87 @param other The other SubString 88 88 @param begin The beginning of the subset 89 90 The subset ranges from the token with index @a begin to the end of the tokens. 91 If @a begin is greater than the greatest index, the new SubString will be empty. 92 */ 93 SubString::SubString(const SubString& other, unsigned int begin) 94 { 95 for (unsigned int i = begin; i < other.size(); ++i) 96 { 97 this->tokens_.push_back(other[i]); 98 this->bTokenInSafemode_.push_back(other.isInSafemode(i)); 99 } 100 } 101 102 /** 103 @brief creates a new SubString based on a subset of an other SubString. 104 @param other The other SubString 105 @param begin The beginning of the subset 106 @param end The end of the subset 107 108 The subset ranges from the token with index @a begin until (but not including) the token with index @a end. 109 If @a begin or @a end are beyond the allowed index, the resulting SubString will be empty. 110 */ 111 SubString::SubString(const SubString& other, unsigned int begin, unsigned int end) 112 { 113 for (unsigned int i = begin; i < std::min(other.size(), end); ++i) 114 { 115 this->tokens_.push_back(other[i]); 116 this->bTokenInSafemode_.push_back(other.isInSafemode(i)); 89 @param length The length of the subset 90 91 The subset ranges from the token with index @a begin and contains @a length elements. 92 */ 93 SubString::SubString(const SubString& other, size_t begin, size_t length) 94 { 95 for (size_t i = 0; i < length; ++i) 96 { 97 if (begin + i >= other.size()) 98 break; 99 100 this->tokens_.push_back(other[begin + i]); 101 this->bTokenInSafemode_.push_back(other.isInSafemode(begin + i)); 117 102 } 118 103 } … … 123 108 @param argv An array of pointers to the arguments 124 109 */ 125 SubString::SubString( unsigned int argc, const char** argv)126 { 127 for (unsigned int i = 0; i < argc; ++i)110 SubString::SubString(size_t argc, const char** argv) 111 { 112 for (size_t i = 0; i < argc; ++i) 128 113 { 129 114 this->tokens_.push_back(std::string(argv[i])); … … 158 143 159 144 /** 160 @copydoc operator==161 */162 bool SubString::compare(const SubString& other) const163 {164 return (*this == other);165 }166 167 /**168 145 @brief Compares this SubString to another SubString and returns true if the first @a length values match. 169 146 @param other The other SubString 170 147 @param length How many tokens to compare 171 148 */ 172 bool SubString::compare(const SubString& other, unsigned int length) const173 { 174 if ( length > this->size() || length > other.size())149 bool SubString::compare(const SubString& other, size_t length) const 150 { 151 if (std::min(length, this->size()) != std::min(length, other.size())) 175 152 return false; 176 153 177 for ( unsigned int i = 0; i < length; ++i)154 for (size_t i = 0; i < std::min(length, this->size()); ++i) 178 155 if ((this->tokens_[i] != other.tokens_[i]) || (this->bTokenInSafemode_[i] != other.bTokenInSafemode_[i])) 179 156 return false; 157 180 158 return true; 181 159 } … … 196 174 SubString& SubString::operator+=(const SubString& other) 197 175 { 198 for ( unsigned int i = 0; i < other.size(); ++i)176 for (size_t i = 0; i < other.size(); ++i) 199 177 { 200 178 this->tokens_.push_back(other[i]); … … 207 185 @copydoc SubString(const std::string&,const std::string&,const std::string&,bool,char,bool,char,bool,char,char,bool,char) 208 186 */ 209 unsigned int SubString::split(const std::string& line,210 211 212 187 size_t SubString::split(const std::string& line, 188 const std::string& delimiters, const std::string& delimiterNeighbours, bool bAllowEmptyEntries, 189 char escapeChar, bool bRemoveEscapeChar, char safemodeChar, bool bRemoveSafemodeChar, 190 char openparenthesisChar, char closeparenthesisChar, bool bRemoveParenthesisChars, char commentChar) 213 191 { 214 192 this->tokens_.clear(); … … 228 206 { 229 207 std::string retVal = this->tokens_[0]; 230 for ( unsigned int i = 1; i < this->tokens_.size(); ++i)208 for (size_t i = 1; i < this->tokens_.size(); ++i) 231 209 retVal += delimiter + this->tokens_[i]; 232 210 return retVal; … … 239 217 @brief Creates a subset of this SubString. 240 218 @param begin The beginning of the subset 219 @param length The length of the subset 241 220 @return A new SubString containing the defined subset. 242 221 243 The subset ranges from the token with index @a begin to the end of the tokens. 244 If @a begin is greater than the greatest index, the new SubString will be empty. 222 The subset ranges from the token with index @a begin and contains @a length elements. 245 223 246 224 This function is added for your convenience, and does the same as 247 SubString::SubString(const SubString& other, unsigned int begin) 248 */ 249 SubString SubString::subSet(unsigned int begin) const 250 { 251 return SubString(*this, begin); 252 } 253 254 /** 255 @brief Creates a subset of this SubString. 256 @param begin The beginning of the subset 257 @param end The ending of the subset 258 @return A new SubString containing the defined subset. 259 260 The subset ranges from the token with index @a begin until (but not including) the token with index @a end. 261 If @a begin or @a end are beyond the allowed index, the resulting SubString will be empty. 262 263 This function is added for your convenience, and does the same as 264 SubString::SubString(const SubString& other, unsigned int begin, unsigned int end) 265 */ 266 SubString SubString::subSet(unsigned int begin, unsigned int end) const 267 { 268 return SubString(*this, begin, end); 225 SubString::SubString(const SubString& other, size_t begin, size_t length) 226 */ 227 SubString SubString::subSet(size_t begin, size_t length) const 228 { 229 return SubString(*this, begin, length); 269 230 } 270 231 … … 298 259 { 299 260 SPLIT_LINE_STATE state = start_state; 300 unsigned int i = 0;301 unsigned int fallBackNeighbours = 0;261 size_t i = 0; 262 size_t fallBackNeighbours = 0; 302 263 303 264 std::string token; … … 514 475 { 515 476 orxout(debug_output) << "Substring-information::count=" << this->tokens_.size() << " ::"; 516 for ( unsigned int i = 0; i < this->tokens_.size(); ++i)477 for (size_t i = 0; i < this->tokens_.size(); ++i) 517 478 orxout(debug_output) << "s" << i << "='" << this->tokens_[i].c_str() << "'::"; 518 479 orxout(debug_output) << endl; -
code/branches/testing/src/libraries/util/SubString.h
r8858 r9047 58 58 SubString tokens(text, SubString::WhiteSpaces, "", false, '\\', true, '"', true, '{', '}', true, '\0'); 59 59 60 for ( unsigned int i = 0; i < tokens.size(); ++i)60 for (size_t i = 0; i < tokens.size(); ++i) 61 61 orxout() << i << ": " << tokens[i] << endl; 62 62 @endcode … … 127 127 bool bRemoveParenthesisChars = true, 128 128 char commentChar = '\0'); 129 SubString(unsigned int argc, const char** argv); 130 SubString(const SubString& other, unsigned int begin); 131 SubString(const SubString& other, unsigned int begin, unsigned int end); 129 SubString(size_t argc, const char** argv); 130 SubString(const SubString& other, size_t begin, size_t length = std::string::npos); 132 131 ~SubString(); 133 132 … … 135 134 SubString& operator=(const SubString& other); 136 135 bool operator==(const SubString& other) const; 137 bool compare(const SubString& other) const; 138 bool compare(const SubString& other, unsigned int length) const; 136 bool compare(const SubString& other, size_t length = std::string::npos) const; 139 137 SubString operator+(const SubString& other) const; 140 138 SubString& operator+=(const SubString& other); … … 144 142 ///////////////////////////////////////// 145 143 // Split and Join the any String. /////// 146 unsigned int split(const std::string& line,147 148 149 150 151 152 153 154 155 156 157 144 size_t split(const std::string& line, 145 const std::string& delimiters = SubString::WhiteSpaces, 146 const std::string& delimiterNeighbours = "", 147 bool bAllowEmptyEntries = false, 148 char escapeChar ='\\', 149 bool bRemoveEscapeChar = true, 150 char safemodeChar = '"', 151 bool bRemoveSafemodeChar = true, 152 char openparenthesisChar = '{', 153 char closeparenthesisChar = '}', 154 bool bRemoveParenthesisChars = true, 155 char commentChar = '\0'); 158 156 159 157 std::string join(const std::string& delimiter = " ") const; … … 161 159 162 160 // retrieve a SubSet from the String 163 SubString subSet(unsigned int begin) const; 164 SubString subSet(unsigned int begin, unsigned int end) const; 161 SubString subSet(size_t begin, size_t length = std::string::npos) const; 165 162 166 163 // retrieve Information from within … … 168 165 inline bool empty() const { return this->tokens_.empty(); } 169 166 /// Returns the number of tokens stored in this SubString 170 inline unsigned int size() const { return this->tokens_.size(); }167 inline size_t size() const { return this->tokens_.size(); } 171 168 /// Returns the i'th token from the subset of strings @param index The index of the requested token 172 inline const std::string& operator[]( unsigned int index) const { return this->tokens_[index]; }169 inline const std::string& operator[](size_t index) const { return this->tokens_[index]; } 173 170 /// Returns the i'th token from the subset of strings @param index The index of the requested token 174 inline const std::string& getString( unsigned int index) const { return (*this)[index]; }171 inline const std::string& getString(size_t index) const { return (*this)[index]; } 175 172 /// Returns all tokens as std::vector 176 173 inline const std::vector<std::string>& getAllStrings() const { return this->tokens_; } 177 174 /// Returns true if the token is in safemode. @param index The index of the token 178 inline bool isInSafemode( unsigned int index) const { return this->bTokenInSafemode_[index]; }175 inline bool isInSafemode(size_t index) const { return this->bTokenInSafemode_[index]; } 179 176 /// Returns the front of the list of tokens. 180 177 inline const std::string& front() const { return this->tokens_.front(); } -
code/branches/testing/src/libraries/util/VA_NARGS.h
r7401 r9047 36 36 type aware, but for different numbers of arguments is still very powerful). 37 37 38 Important: The macro can not be overloaded for 0 arguments: ORXONOX_VA_NARGS() returns 1! 39 38 40 Example: A macro to call functions 39 41 @code … … 64 66 */ 65 67 68 #include <boost/preprocessor/cat.hpp> 66 69 #include <boost/preprocessor/facilities/expand.hpp> 67 70 -
code/branches/testing/src/modules/notifications/dispatchers/CommandNotification.cc
r7489 r9047 117 117 const std::string& CommandNotification::bindingNiceifyer(const std::string& binding) 118 118 { 119 SubString s tring = SubString(binding, ".");119 SubString substring = SubString(binding, "."); 120 120 std::string name; 121 121 std::string group; 122 switch(s tring.size())122 switch(substring.size()) 123 123 { 124 124 case 0: … … 127 127 return binding; 128 128 case 2: 129 group = s tring[0];129 group = substring[0]; 130 130 default: 131 name = s tring.subSet(1, string.size()).join(".");131 name = substring.subSet(1).join("."); 132 132 } 133 133 … … 148 148 return *(new std::string(stream.str())); 149 149 } 150 150 151 151 }
Note: See TracChangeset
for help on using the changeset viewer.