Changeset 9881 in orxonox.OLD for trunk/src/lib/parser/ini_parser/ini_parser.cc
- Timestamp:
- Oct 10, 2006, 4:23:28 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/parser/ini_parser/ini_parser.cc
r9880 r9881 21 21 #include "ini_parser.h" 22 22 23 #if HAVE_CONFIG_H24 #include <config.h>25 #endif26 27 23 #include <cassert> 28 24 #include <algorithm> 29 25 30 #ifdef DEBUG_LEVEL 31 #include "../../../lib/util/debug.h" 32 #else 33 #define PRINTF(x) printf 34 #define PRINT(x) printf 35 #endif 26 #define PARSELINELENGHT 1024 //!< how many chars to read at once 36 27 37 28 … … 39 30 /// INI-PARSER NODE /// 40 31 /// /// /// /// /// /// 32 /** 33 * @brief Constructs a Node 34 * @param name The name of the Node 35 * @param comment The comment of the Node. 36 */ 41 37 IniParser::Node::Node(const std::string& name, const std::string& comment) 42 38 { … … 48 44 /// INI-PARSER ENTRY /// 49 45 /// /// /// /// /// //// 46 /** 47 * @brief Constructs a new Entry 48 * @param name the Name of the Entry 49 * @param value The name of the Value 50 * @param comment The Comment used for the Entry 51 */ 50 52 IniParser::Entry::Entry(const std::string& name, const std::string& value, const std::string& comment) 51 53 : IniParser::Node(name, comment), _value(value) 52 54 {} 53 55 56 /** 57 * @brief Displays some nice debug info. 58 */ 54 59 void IniParser::Entry::debug() const 55 60 { … … 61 66 /// INI-PARSER SECTION /// 62 67 /// /// /// /// /// /// /// 68 /** 69 * @brief constructs a new Section 70 * @param sectionName The name of the Section 71 * @param comment The Comment for this section 72 */ 63 73 IniParser::Section::Section(const std::string& sectionName, const std::string& comment) 64 74 : IniParser::Node(sectionName, comment) 65 75 {} 66 76 77 /** 78 * @brief Adds a new Entry to this Section 79 * @param entryName The name of the Entry 80 * @param value The Value of the Section 81 * @param comment The Comment 82 * @returns Reference to the Entry added. 83 * @see IniParser::Entry::Entry 84 */ 67 85 IniParser::Entry& IniParser::Section::addEntry(const std::string& entryName, const std::string& value, const std::string& comment) 68 86 { … … 76 94 } 77 95 96 /** 97 * @brief edits an Entry's Value 98 * @param entryName The Entry to edit 99 * @param value The Value to change 100 * @param createMissing If the Entry is missing it is created if true. 101 * @return true on success. 102 */ 78 103 bool IniParser::Section::editEntry(const std::string& entryName, const std::string& value, bool createMissing) 79 104 { … … 93 118 } 94 119 120 /** 121 * @param entryName The name of the entry to search for 122 * @param defaultValue The returned value, if the entry is not found 123 * @return The Value of the Entry, or defaultValue, if not found. 124 */ 95 125 const std::string& IniParser::Section::getValue(const std::string& entryName, const std::string& defaultValue) const 96 126 { … … 102 132 } 103 133 134 /** 135 * @brief sets a Comment to an Entry 136 * @param entryName The Name of the Entry to set the comment to. 137 * @param comment the Comment. 138 * @return true on success (entry found and setup). 139 */ 104 140 bool IniParser::Section::setEntryComment(const std::string& entryName, const std::string& comment) 105 141 { … … 113 149 } 114 150 151 /** 152 * @brief retrieves a Comment of an Entry 153 * @param entryName The Entry to get the comment of. 154 * @return The Comment, or "" if the Entry was not found. 155 */ 115 156 const std::string& IniParser::Section::getEntryComment(const std::string& entryName) const 116 157 { … … 124 165 125 166 167 /** 168 * @brief retrieves a pointer to an Entry 169 * @param entryName The Name of the Entry. 170 * @return the located Entry or NULL! 171 * @note beware of NULL! 172 */ 126 173 IniParser::Entry* IniParser::Section::getEntry(const std::string& entryName) 127 174 { … … 133 180 } 134 181 182 /** 183 * @brief retrieves an Iterator to an Entry called entryName within this section 184 * @param entryName the name of the Entry 185 * @return The iterator to the position, or end(); 186 * @see Section::end(); 187 */ 135 188 IniParser::Entry::const_iterator IniParser::Section::getEntryIt(const std::string& entryName) const 136 189 { … … 138 191 } 139 192 193 /** 194 * @brief clears the Section's entries (flushes them) 195 */ 140 196 void IniParser::Section::clear() 141 197 { … … 143 199 } 144 200 201 /** 202 * @brief print out some debug info 203 */ 145 204 void IniParser::Section::debug() const 146 205 { … … 155 214 /// INI-PARSER DOCUMENT /// 156 215 /// /// /// /// /// /// /// 216 /** 217 * @brief Constructs a new Document 218 * @param fileName The Name of the Document. 219 * @param comment Some Comment 220 */ 157 221 IniParser::Document::Document(const std::string& fileName, const std::string& comment) 158 222 : IniParser::Node(fileName, comment) 159 223 {} 160 224 225 /** 226 * @brief Adds a new Section to the Document 227 * @param sectionName The Name of the Section to add 228 * @param comment A comment for the section. 229 * @return A Reference to the newly added section. 230 */ 161 231 IniParser::Section& IniParser::Document::addSection(const std::string& sectionName, const std::string& comment) 162 232 { … … 171 241 } 172 242 243 /** 244 * @brief removes a Section from the Document. 245 * @param sectionName The section to remove 246 * @return true on success (section was found). 247 */ 173 248 bool IniParser::Document::removeSection(const std::string& sectionName) 174 249 { … … 183 258 } 184 259 260 /** 261 * @brief Sets a comment to a section 262 * @param sectionName The name of the section 263 * @param comment The Comment. 264 * @return True on success (section was found). 265 */ 185 266 bool IniParser::Document::setSectionComment(const std::string& sectionName, const std::string& comment) 186 267 { … … 197 278 198 279 280 /** 281 * @brief Queries for a Section within the document returning a Pointer to it 282 * @param sectionName The Section to search for. 283 * @return A pointer to the section, of NULL if not found. 284 * @brief beware of the NULL-pointer! 285 */ 199 286 IniParser::Section* IniParser::Document::getSection(const std::string& sectionName) 200 287 { … … 208 295 } 209 296 297 /** 298 * @brief Queries for a Section within the document returning a Pointer to it 299 * @param sectionName The Section to search for. 300 * @return An iterator to the Section, or end() 301 * @see Section::end(). 302 */ 210 303 IniParser::Section::const_iterator IniParser::Document::getSectionIt(const std::string& sectionName) const 211 304 { … … 214 307 } 215 308 309 /** 310 * @brief adds a new Entry to a designated section. 311 * @param sectionName The name of the Section 312 * @param entryName The Name of the Entry to add 313 * @param value The Value to set for the entry 314 * @param comment optionally a comment. 315 * @return true on success (always true) 316 * 317 * @note the section will also be created on the go, if it did not exists so far! 318 */ 216 319 bool IniParser::Document::addEntry(const std::string& sectionName, const std::string& entryName, const std::string& value, const std::string& comment) 217 320 { … … 229 332 } 230 333 334 /** 335 * @brief edits an Entry, and possibly creating it. 336 * @param sectionName The Section's name to edit the entry in. 337 * @param entryName The Name of the Entry to edit the value from 338 * @param value The new value for the Entry. 339 * @param createMissing if true, the Entry, (and the section) will be created. 340 * @return true on success, false otherwise. 341 */ 231 342 bool IniParser::Document::editEntry(const std::string& sectionName, const std::string& entryName, const std::string& value, bool createMissing) 232 343 { … … 248 359 } 249 360 361 /** 362 * @brief Retrieve a value from an Entry. 363 * @param sectionName The Name of the Section the enrty is in 364 * @param entryName The Name of the entry 365 * @param defaultValue A default value, if the entry is not found 366 * @return A string containing the value, or defaultValue, if the Section->Entry was not found. 367 */ 250 368 const std::string& IniParser::Document::getValue(const std::string& sectionName, const std::string& entryName, const std::string& defaultValue) const 251 369 { … … 257 375 } 258 376 377 /** 378 * @brief Sets a Comment to an Entry. 379 * @param sectionName The name of the Section. 380 * @param entryName The name of the Entry. 381 * @param comment The comment to set to this Entry 382 * @return true on success (Section->Entry found). 383 */ 259 384 bool IniParser::Document::setEntryComment(const std::string& sectionName, const std::string& entryName, const std::string& comment) 260 385 { … … 267 392 } 268 393 394 /** 395 * @brief retrieved the comment of an Entry. 396 * @param sectionName The section. 397 * @param entryName The Entry to get the comment from 398 * @return the Comment of the Entry. 399 */ 269 400 const std::string& IniParser::Document::getEntryComment(const std::string& sectionName, const std::string& entryName) const 270 401 { … … 276 407 } 277 408 409 /** 410 * @brief clears all sections. 411 */ 278 412 void IniParser::Document::clear() 279 413 { … … 281 415 } 282 416 417 /** 418 * @brief Print some nice debug output. 419 */ 283 420 void IniParser::Document::debug() const 284 421 { … … 334 471 if( (stream = fopen (fileName.c_str(), "r")) == NULL) 335 472 { 336 PRINTF(1)("IniParser could not open %s for reading\n", fileName.c_str());473 printf("ERROR:: IniParser could not open %s for reading\n", fileName.c_str()); 337 474 return false; 338 475 } … … 393 530 if (currentSection == NULL) 394 531 { 395 PRINTF(2)("Not in a Section yet for %s\n", lineBegin);532 printf("WARNING:: Not in a Section yet for %s\n", lineBegin); 396 533 lineCount++; 397 534 continue; … … 427 564 428 565 /** 429 * @brief opens a file and writes to it 430 * @param fileName: path and name of the new file to write to 566 * @brief opens a file and writes to it. 567 * @param fileName: path and name of the new file to write to. If empty the internal value is used. 431 568 * @return true on success false otherwise 432 569 */ 433 570 bool IniParser::writeFile(const std::string& fileName) const 434 571 { 572 std::string parseFile; 435 573 FILE* stream; //!< The stream we use to read the file. 436 574 if( fileName.empty()) 437 return false; 438 439 if( (stream = fopen (fileName.c_str(), "w")) == NULL) 440 { 441 PRINTF(1)("IniParser could not open %s for writing\n", fileName.c_str()); 575 parseFile = _fileName; 576 else 577 parseFile = fileName; 578 579 if( (stream = fopen (parseFile.c_str(), "w")) == NULL) 580 { 581 printf("ERROR:: IniParser could not open %s for writing\n", parseFile.c_str()); 442 582 return false; 443 583 } … … 551 691 void IniParser::debug() const 552 692 { 553 PRINT(0)("Iniparser '%s' - debug\n", this->_fileName.c_str());693 printf("Iniparser '%s' - debug\n", this->_fileName.c_str()); 554 694 if (!this->_document.comment().empty()) 555 PRINT(0)("FileComment:\n '%s'\n\n", this->_document.comment().c_str());695 printf("FileComment:\n '%s'\n\n", this->_document.comment().c_str()); 556 696 557 697 if (!this->_document.sections().empty()) 558 698 this->_document.debug(); 559 699 else 560 PRINTF(0)("no Sections Defined in this ini-file (%s).\n", _fileName.c_str()); 561 } 562 563 564 /** 565 * takes lines together to form one NodeComment, ereasing the commentList 700 printf("no Sections Defined in this ini-file (%s).\n", _fileName.c_str()); 701 } 702 703 704 /** 705 * @brief takes lines together to form one NodeComment, ereasing the commentList 706 * @param node the Node to apply the Comment to. 707 * @param comments the CommentList to append. 566 708 */ 567 709 void IniParser::setNodeComment(Node* node, std::list<std::string>* comments)
Note: See TracChangeset
for help on using the changeset viewer.