Changeset 7474 in orxonox.OLD for trunk/src/lib/util
- Timestamp:
- May 2, 2006, 6:24:43 PM (19 years ago)
- Location:
- trunk/src/lib/util
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/util/executor/executor.h
r7419 r7474 52 52 // EXECUTE 53 53 /** executes a Command @param object the object to apply this to @param parameters the parameters the command takes */ 54 virtual void operator()(BaseObject* object, const std::string& parameters = "") const = 0;54 virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const = 0; 55 55 /** executes a Command @param object the object to apply this to @param parameters the parameters the command takes @brief here for your convenience*/ 56 56 void execute (BaseObject* object, const std::string& parameters = "") const { (*this)(object, parameters); }; … … 256 256 } fp; 257 257 258 virtual void operator()(BaseObject* object, const std::string& parameters = "") const258 virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const 259 259 { 260 SubString sub;261 sub.split(parameters, " \n\t,", '\\');262 260 //! FUNCTOR_LIST is the List of Executive Functions 263 261 #define FUNCTOR_LIST(x) ExecutorExecute ## x … … 319 317 320 318 321 virtual void operator()(BaseObject* object, const std::string& parameters = "") const319 virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const 322 320 { 323 SubString sub;324 sub.split(parameters, " \n\t,", '\\');325 321 //! FUNCTOR_LIST is the List of Executive Functions 326 322 #define FUNCTOR_LIST(x) ExecutorExecute ## x -
trunk/src/lib/util/executor/executor_specials.h
r7419 r7474 60 60 * @param loadString ignored in this case 61 61 */ 62 virtual void operator()(BaseObject* object, const std::string& = "") const62 virtual void operator()(BaseObject* object, const SubString& = SubString()) const 63 63 { 64 64 if (object != NULL && this->element != NULL) -
trunk/src/lib/util/loading/load_param.cc
r7331 r7474 67 67 { 68 68 PRINTF(4)("Loading value '%s' with Parameters '%s' onto: %s::%s\n", this->paramName.c_str(), loadString.c_str(), this->object->getClassName(), this->object->getName()); 69 (*this->executor)(this->object, loadString);69 (*this->executor)(this->object, SubString(loadString, ",", SubString::WhiteSpaces, false, '\\')); 70 70 } 71 71 delete this->executor; -
trunk/src/lib/util/substring.cc
r7398 r7474 42 42 * @brief create a SubString from 43 43 * @param string the String to Spilit 44 * @param splitter the Character at which to split string (delimiter) 45 */ 46 SubString::SubString(const std::string& string, char splitter) 47 { 48 char split[2]; 49 split[0] = splitter; 50 split[1] = '\0'; 51 SubString::splitLine(this->strings, string, split); 44 * @param delimiter the Character at which to split string (delimiter) 45 */ 46 SubString::SubString(const std::string& string, char delimiter) 47 { 48 this->split(string, delimiter); 52 49 } 53 50 … … 56 53 * @brief Splits a String into multiple splitters. 57 54 * @param string the String to split 58 * @param splitters multiple set of characters at what to split. (delimiters) 55 * @param delimiters multiple set of characters at what to split. (delimiters) 56 * @param delimiterNeighbours neighbours of the delimiters, that will be erased only when near a delimiter. 59 57 * @param escapeChar The Escape Character that overrides splitters commends and so on... 60 58 * @param safemode_char within these characters splitting won't happen 61 59 * @param comment_char the Comment character. 62 60 */ 63 SubString::SubString(const std::string& string, const std::string& splitters, char escapeChar, char safemode_char, char comment_char) 64 { 65 SubString::splitLine(this->strings, string, splitters, escapeChar, safemode_char, comment_char); 61 SubString::SubString(const std::string& string, 62 const std::string& delimiters, const std::string& delimiterNeighbours, bool emptyEntries, 63 char escapeChar, char safemode_char, char comment_char) 64 { 65 SubString::splitLine(this->strings, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, safemode_char, comment_char); 66 66 } 67 67 … … 196 196 * @brief Splits a String into multiple splitters. 197 197 * @param string the String to split 198 * @param splitters multiple set of characters at what to split. (delimiters) 198 * @param delimiters multiple set of characters at what to split. (delimiters) 199 * @param delimiterNeighbours: Neighbours to the Delimiters that will be erased too. 200 * @param emptyEntries: If empty entries are added to the List of SubStrings 199 201 * @param escapeChar The Escape Character that overrides splitters commends and so on... 200 202 * @param safemode_char within these characters splitting won't happen 201 203 * @param comment_char the Comment character. 202 204 */ 203 unsigned int SubString::split(const std::string& string, const std::string& splitters, char escapeChar,char safemode_char, char comment_char) 205 unsigned int SubString::split(const std::string& string, 206 const std::string& delimiters, const std::string& delimiterNeighbours, bool emptyEntries, 207 char escapeChar,char safemode_char, char comment_char) 204 208 { 205 209 this->strings.clear(); 206 SubString::splitLine(this->strings, string, splitters, escapeChar, safemode_char, comment_char);210 SubString::splitLine(this->strings, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, safemode_char, comment_char); 207 211 return this->strings.size(); 208 212 } … … 264 268 * @param line the inputLine to split 265 269 * @param delimiters a String of Delimiters (here the input will be splitted) 270 * @param delimiterNeighbour Naighbours to the Delimitter, that will be removed if they are to the left or the right of a Delimiter. 271 * @param emptyEntries: if empty Strings are added to the List of Strings. 266 272 * @param escape_char: Escape carater (escapes splitters) 267 273 * @param safemode_char: the beginning of the safemode is marked with this … … 274 280 * ignores special characters between safemode_char and between comment_char and linend '\n'. 275 281 * 276 */ 277 SPLIT_LINE_STATE SubString::splitLine(std::vector<std::string>& ret, 278 const std::string& line, 279 const std::string& delimiters, 280 char escape_char, 281 char safemode_char, 282 char comment_char, 283 SPLIT_LINE_STATE start_state) 282 * 283 */ 284 SubString::SPLIT_LINE_STATE 285 SubString::splitLine(std::vector<std::string>& ret, 286 const std::string& line, 287 const std::string& delimiters, 288 const std::string& delimiterNeighbours, 289 bool emptyEntries, 290 char escape_char, 291 char safemode_char, 292 char comment_char, 293 SPLIT_LINE_STATE start_state) 284 294 { 285 295 SPLIT_LINE_STATE state = start_state; 286 296 unsigned int i = 0; 297 unsigned int fallBackNeighbours = 0; 298 287 299 std::string token; 288 300 … … 297 309 switch(state) 298 310 { 299 311 case SL_NORMAL: 300 312 if(line[i] == escape_char) 301 313 { … … 308 320 else if(line[i] == comment_char) 309 321 { 322 if (fallBackNeighbours > 0) 323 token = token.substr(0, token.size() - fallBackNeighbours); 310 324 /// FINISH 311 if( token.size() > 0)325 if(emptyEntries || token.size() > 0) 312 326 { 313 327 ret.push_back(token); … … 320 334 { 321 335 // line[i] is a delimiter 336 if (fallBackNeighbours > 0) 337 token = token.substr(0, token.size() - fallBackNeighbours); 322 338 /// FINISH 323 if( token.size() > 0)339 if(emptyEntries || token.size() > 0) 324 340 { 325 341 ret.push_back(token); 326 342 token.clear(); 327 343 } 344 state = SL_NORMAL; 328 345 } 329 346 else 330 347 { 348 if (delimiterNeighbours.find(line[i]) != std::string::npos) 349 { 350 if (token.size() > 0) 351 ++fallBackNeighbours; 352 else 353 { 354 i++; 355 continue; 356 } 357 } 358 else 359 fallBackNeighbours = 0; 331 360 token += line[i]; // EAT 332 361 } 333 362 break; 334 363 case SL_ESCAPE: 335 364 if(line[i] == 'n') token += '\n'; 336 365 else if(line[i] == 't') token += '\t'; … … 344 373 state = SL_NORMAL; 345 374 break; 346 375 case SL_SAFEMODE: 347 376 if(line[i] == safemode_char) 348 377 { … … 358 387 } 359 388 break; 360 case SL_SAFEESCAPE: 389 390 case SL_SAFEESCAPE: 361 391 if(line[i] == 'n') token += '\n'; 362 392 else if(line[i] == 't') token += '\t'; … … 370 400 state = SL_SAFEMODE; 371 401 break; 372 case SL_COMMENT: 402 403 case SL_COMMENT: 373 404 if(line[i] == '\n') 374 405 { … … 386 417 } 387 418 break; 388 default: 419 420 default: 389 421 // nothing 390 422 break; … … 394 426 395 427 /// FINISH 396 if(token.size() > 0) 428 if (fallBackNeighbours > 0) 429 token = token.substr(0, token.size() - fallBackNeighbours); 430 if(emptyEntries || token.size() > 0) 397 431 { 398 432 ret.push_back(token); -
trunk/src/lib/util/substring.h
r7398 r7474 10 10 #include <string> 11 11 12 typedef enum {13 SL_NORMAL,14 SL_ESCAPE,15 SL_SAFEMODE,16 SL_SAFEESCAPE,17 SL_COMMENT,18 } SPLIT_LINE_STATE;19 12 20 13 //! A class that can load one string and split it in multipe ones … … 26 19 { 27 20 public: 21 typedef enum { 22 SL_NORMAL, 23 SL_ESCAPE, 24 SL_SAFEMODE, 25 SL_SAFEESCAPE, 26 SL_COMMENT, 27 } SPLIT_LINE_STATE; 28 29 30 public: 28 31 SubString(); 29 SubString(const std::string& string, char splitter = ','); 30 SubString(const std::string& string, const std::string& splitters, char escapeChar ='\\', char safemode_char = '"', char comment_char = '\0'); 32 SubString(const std::string& string, char delimiter = ','); 33 SubString(const std::string& string, 34 const std::string& delimiters, const std::string& delimiterNeighbours = "", bool emptyEntries=false, 35 char escapeChar ='\\', char safemode_char = '"', char comment_char = '\0'); 31 36 /** @brief create a Substring as a copy of another one. @param subString the SubString to copy. */ 32 37 SubString(const SubString& subString) { *this = subString; }; … … 47 52 ///////////////////////////////////////// 48 53 // Split and Join the any String. /////// 49 unsigned int split(const std::string& string = "", char splitter = ','); 50 unsigned int split(const std::string& string, const std::string& splitters, char escapeChar ='\\', char safemode_char = '"', char comment_char = '\0'); 54 unsigned int split(const std::string& string = "", char delimiter = ','); 55 unsigned int split(const std::string& string, 56 const std::string& delimiters, const std::string& delimiterNeighbours = "", bool emptyEntries = false, 57 char escapeChar ='\\', char safemode_char = '"', char comment_char = '\0'); 51 58 std::string join(const std::string& delimiter = " ") const; 52 59 //////////////////////////////////////// … … 62 69 inline unsigned int size() const { return this->strings.size(); }; 63 70 /** @param i the i'th String @returns the i'th string from the subset of Strings */ 64 71 const std::string& operator[](unsigned int i) const { return (i < this->strings.size()) ? this->strings[i] : emptyString;return this->getString(i); }; 65 72 /** @param i the i'th String @returns the i'th string from the subset of Strings */ 66 73 const std::string& getString(unsigned int i) const { return (*this)[i]; }; … … 70 77 const std::string& line, 71 78 const std::string& delimiters = SubString::WhiteSpaces, 79 const std::string& delimiterNeighbours = "", 80 bool emptyEntries = false, 72 81 char escape_char = '\\', 73 82 char safemode_char = '"',
Note: See TracChangeset
for help on using the changeset viewer.