Changeset 9883 in orxonox.OLD for trunk/src/lib/parser/ini_parser
- Timestamp:
- Oct 12, 2006, 9:21:29 AM (18 years ago)
- Location:
- trunk/src/lib/parser/ini_parser
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/parser/ini_parser/ini_parser.cc
r9881 r9883 16 16 now the File is parsed at the initialisation, 17 17 and informations is gathered there. 18 2006-10-10: Complete reimplementation again :) 19 New STL-like style. The Parser has no state itself 20 Elements as Nodes 18 21 */ 19 22 … … 264 267 * @return True on success (section was found). 265 268 */ 266 bool IniParser::Document::setSection Comment(const std::string& sectionName, const std::string& comment)269 bool IniParser::Document::setSectionsComment(const std::string& sectionName, const std::string& comment) 267 270 { 268 271 Section::iterator section = std::find(this->_sections.begin(), this->_sections.end(), sectionName); … … 276 279 } 277 280 278 281 /** 282 * @brief Retrieves the comment for a specified section 283 * @param sectionName The name of the section 284 * @returns The Comment of the section. 285 */ 286 const std::string& IniParser::Document::getSectionsComment(const std::string& sectionName) const 287 { 288 Section::const_iterator section = std::find(this->_sections.begin(), this->_sections.end(), sectionName); 289 if (section != this->_sections.end()) 290 { 291 return (*section).comment(); 292 } 293 else 294 return IniParser::_emptyString; 295 } 279 296 280 297 /** … … 607 624 } 608 625 609 void IniParser::setFileComment(const std::string& fileComment)610 {611 this->_document.setComment(fileComment);612 }613 614 /**615 * @brief adds a section to the list of Sections,616 * if no Section list is availiable, it will create it617 * @param sectionName the Name of the section to add618 * @return true on success... there is only success or segfault :)619 */620 IniParser::Section& IniParser::addSection(const std::string& sectionName)621 {622 return this->_document.addSection(sectionName);623 }624 625 626 /**627 * @brief adds a new Entry to either the currentSection or the section called by sectionName628 * @param entryName the Name of the Entry to add629 * @param value the value to assign to this entry630 * @param sectionName if NULL then this entry will be set to the currentSection631 * otherwise to the section refered to by sectionName.632 * If both are NULL no entry will be added633 * @return The Entry, that was added.634 */635 bool IniParser::addEntry(const std::string& sectionName, const std::string& entryName, const std::string& value, const std::string& comment)636 {637 return this->_document.addEntry(sectionName, entryName, value, comment);638 }639 640 /**641 * @brief edits the entry speciefied by entryName in sectionName/currentSection or creates it if it doesn't exist642 * @param entryName the Name of the Entry to add643 * @param value the value to assign to this entry644 * @param sectionName if NULL then this entry will be set to the currentSection645 * otherwise to the section refered to by sectionName.646 * If both are NULL no entry will be added647 * @return true if everything is ok false on error648 */649 bool IniParser::editEntry(const std::string& sectionName, const std::string& entryName, const std::string& value, bool createMissing)650 {651 return this->_document.editEntry(sectionName, entryName, value, createMissing);652 }653 654 655 /**656 * @brief directly acesses an entry in a section657 * @param sectionName: the section where the entry is to be found658 * @param entryName: the name of the entry to find659 * @param defaultValue: what should be returned in case the entry cannot be found660 * @return The Value of the Entry.661 */662 const std::string& IniParser::getValue(const std::string& sectionName, const std::string& entryName, const std::string& defaultValue) const663 {664 return this->_document.getValue(sectionName, entryName, defaultValue);665 }666 667 /**668 * Set the Comment of a specified Entry.669 * @param comment the Comment to set670 * @param entryName the Name of the Entry671 * @param sectionName the Name of the Section672 */673 void IniParser::setEntryComment(const std::string& sectionName, const std::string& entryName, const std::string& comment)674 {675 this->_document.setEntryComment(sectionName, entryName, comment);676 }677 678 /**679 * @param entryName the Entry to query for680 * @param sectionName the Section to Query for681 * @returns the queried Comment.682 */683 const std::string& IniParser::getEntryComment(const std::string& sectionName, const std::string& entryName) const684 {685 return this->_document.getEntryComment(sectionName, entryName);686 }687 626 688 627 /** -
trunk/src/lib/parser/ini_parser/ini_parser.h
r9881 r9883 5 5 * Can be used to find a defined [Section] in an ini file and get the VarName = Value entries 6 6 */ 7 8 7 #ifndef _INI_PARSER_H 9 8 #define _INI_PARSER_H … … 116 115 Section& addSection(const std::string& sectionName, const std::string& comment = ""); 117 116 bool removeSection(const std::string& sectionName); 118 bool setSectionComment(const std::string& sectionName, const std::string& comment); 117 bool setSectionsComment(const std::string& sectionName, const std::string& comment); 118 const std::string& getSectionsComment(const std::string& sectionName) const; 119 119 120 120 /** @returns list of all sections */ … … 160 160 bool writeFile(const std::string& fileName = "") const; 161 161 162 void setFileComment(const std::string& fileComment); 162 //! @param fileComment the comment of the Document */ 163 void setFileComment(const std::string& fileComment) { this->_document.setComment(fileComment); }; 163 164 /** @returns comments for the File. */ 164 165 const std::string& getFileComment() const { return this->_document.comment(); }; 165 166 166 /// Wor ing with Sections.167 /// Working with Sections. 167 168 Section& addSection(const std::string& sectionName); 168 169 // iterate through sections with these Functions 169 //! see Section::getSection()170 //! @see Section::getSection() 170 171 Section* getSection(const std::string& sectionName) { return this->_document.getSection(sectionName); }; 171 Section::const_iterator getSectionIt(const std::string& sectionName) const; 172 173 //! see Section::begin() 172 //! @see Document::getSectionIt() 173 Section::const_iterator getSectionIt(const std::string& sectionName) const { return this->_document.getSectionIt(sectionName); }; 174 175 //! @see Document::begin() 174 176 Section::iterator begin() { return this->_document.begin(); }; 175 //! see Section::begin()177 //! @see Document::begin() 176 178 Section::const_iterator begin() const { return this->_document.begin(); }; 177 //! see Section::end()179 //! @see Document::end() 178 180 Section::iterator end() { return this->_document.end(); }; 179 //! see Section::end()181 //! @see Document::end() 180 182 Section::const_iterator end() const { return this->_document.end(); }; 181 182 void setSectionComment(const std::string& sectionName, const std::string& comment); 183 const std::string& getSectionsComment(const std::string& sectionNane) const; 183 //! @see Document::setSectionComment() 184 void setSectionsComment(const std::string& sectionName, const std::string& comment) { this->_document.setSectionsComment(sectionName, comment); }; 185 //! @see Document::getSectionsComment() 186 const std::string& getSectionsComment(const std::string& sectionName) const { return this->_document.getSectionsComment(sectionName); }; 184 187 185 188 /// Working on Entries. (globally) 186 bool addEntry(const std::string& sectionName, const std::string& entryName, const std::string& value, const std::string& comment); 187 const std::string& getValue(const std::string& sectionNmae, const std::string& entryName, const std::string& defaultValue = "") const; 188 bool editEntry(const std::string& sectionName, const std::string& entryName, const std::string& value, bool createMissing = true); 189 190 void setEntryComment(const std::string& sectionName, const std::string& entryName, const std::string& comment); 191 const std::string& getEntryComment(const std::string& sectionName, const std::string& entryName) const; 189 //! @see Document::addEntry() 190 bool addEntry(const std::string& sectionName, const std::string& entryName, const std::string& value, const std::string& comment) 191 { return this->_document.addEntry(sectionName, entryName, value, comment); }; 192 //! @see Document::getValue() 193 const std::string& getValue(const std::string& sectionName, const std::string& entryName, const std::string& defaultValue = "") const 194 { return this->_document.getValue(sectionName, entryName, defaultValue); }; 195 //! @see Document::editEntry() 196 bool editEntry(const std::string& sectionName, const std::string& entryName, const std::string& value, bool createMissing = true) 197 { return this->_document.editEntry(sectionName, entryName, value, createMissing); }; 198 //! @see Document::setEntryComment() 199 void setEntryComment(const std::string& sectionName, const std::string& entryName, const std::string& comment) 200 { this->_document.setEntryComment(sectionName, entryName, comment); }; 201 //! @see Document::getEntryComment() 202 const std::string& getEntryComment(const std::string& sectionName, const std::string& entryName) const 203 { return this->_document.getEntryComment(sectionName, entryName); }; 192 204 193 205 // maintenance.
Note: See TracChangeset
for help on using the changeset viewer.