Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9883 in orxonox.OLD for trunk/src/lib/parser/ini_parser


Ignore:
Timestamp:
Oct 12, 2006, 9:21:29 AM (18 years ago)
Author:
bensch
Message:

trunk: completely doxygened and finalized IniParser

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  
    1616               now the File is parsed at the initialisation,
    1717               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
    1821*/
    1922
     
    264267 * @return True on success (section was found).
    265268 */
    266 bool IniParser::Document::setSectionComment(const std::string& sectionName, const std::string& comment)
     269bool IniParser::Document::setSectionsComment(const std::string& sectionName, const std::string& comment)
    267270{
    268271  Section::iterator section = std::find(this->_sections.begin(), this->_sections.end(), sectionName);
     
    276279}
    277280
    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 */
     286const 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}
    279296
    280297/**
     
    607624}
    608625
    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 it
    617  * @param sectionName the Name of the section to add
    618  * @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 sectionName
    628  * @param entryName the Name of the Entry to add
    629  * @param value the value to assign to this entry
    630  * @param sectionName if NULL then this entry will be set to the currentSection
    631  * otherwise to the section refered to by sectionName.
    632  * If both are NULL no entry will be added
    633  * @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 exist
    642  * @param entryName the Name of the Entry to add
    643  * @param value the value to assign to this entry
    644  * @param sectionName if NULL then this entry will be set to the currentSection
    645  * otherwise to the section refered to by sectionName.
    646  * If both are NULL no entry will be added
    647  * @return true if everything is ok false on error
    648  */
    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 section
    657  * @param sectionName: the section where the entry is to be found
    658  * @param entryName: the name of the entry to find
    659  * @param defaultValue: what should be returned in case the entry cannot be found
    660  * @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) const
    663 {
    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 set
    670  * @param entryName the Name of the Entry
    671  * @param sectionName the Name of the Section
    672  */
    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 for
    680  * @param sectionName the Section to Query for
    681  * @returns the queried Comment.
    682  */
    683 const std::string& IniParser::getEntryComment(const std::string& sectionName, const std::string& entryName) const
    684 {
    685   return this->_document.getEntryComment(sectionName, entryName);
    686 }
    687626
    688627/**
  • trunk/src/lib/parser/ini_parser/ini_parser.h

    r9881 r9883  
    55 * Can be used to find a defined [Section] in an ini file and get the VarName = Value entries
    66 */
    7 
    87#ifndef _INI_PARSER_H
    98#define _INI_PARSER_H
     
    116115    Section& addSection(const std::string& sectionName, const std::string& comment = "");
    117116    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;
    119119
    120120    /** @returns list of all sections */
     
    160160  bool writeFile(const std::string& fileName = "") const;
    161161
    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); };
    163164  /** @returns comments for the File. */
    164165  const std::string& getFileComment() const { return this->_document.comment(); };
    165166
    166   /// Woring with Sections.
     167  /// Working with Sections.
    167168  Section& addSection(const std::string& sectionName);
    168169  // iterate through sections with these Functions
    169   //! see Section::getSection()
     170  //! @see Section::getSection()
    170171  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()
    174176  Section::iterator begin() { return this->_document.begin(); };
    175   //! see Section::begin()
     177  //! @see Document::begin()
    176178  Section::const_iterator begin() const { return this->_document.begin(); };
    177     //! see Section::end()
     179  //! @see Document::end()
    178180  Section::iterator end() { return this->_document.end(); };
    179     //! see Section::end()
     181  //! @see Document::end()
    180182  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); };
    184187
    185188  /// 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); };
    192204
    193205  // maintenance.
Note: See TracChangeset for help on using the changeset viewer.