Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5945 in orxonox.OLD for trunk/src


Ignore:
Timestamp:
Dec 6, 2005, 11:39:05 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: small rearangements

Location:
trunk/src/lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/gui/gtk_gui/gui_keys.cc

    r5766 r5945  
    119119        pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_LEFT, "LEFT"));
    120120        pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_RIGHT, "RIGHT"));
    121         pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_FIRE, "MOUSE_LEFT"));
     121        pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_FIRE, "BUTTON_LEFT"));
    122122        pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_NEXT_WEAPON, "m"));
    123123        pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_PREV_WEAPON, "n"));
  • trunk/src/lib/parser/ini_parser/ini_parser.cc

    r5944 r5945  
    4343{
    4444  this->fileName = NULL;
    45 
     45  this->comment = NULL;
    4646
    4747  if (fileName != NULL)
     
    117117{
    118118  FILE*    stream;           //< The stream we use to read the file.
     119  int      lineCount = 0;    //< The Count of lines.
     120
    119121
    120122  if (this->fileName != NULL)
     
    142144    while( fgets (lineBuffer, PARSELINELENGHT, stream))
    143145    {
     146//      if (lineCount == 0)
     147
    144148      lineBegin = lineBuffer;
    145149      // remove newline char, and \0-terminate
     
    183187
    184188        this->addVar(lineBegin, valueBegin);
     189
     190        lineCount++;
    185191      }
    186192    }
     
    203209{
    204210  FILE*    stream;           //!< The stream we use to read the file.
    205   if( fileName == NULL)
     211  if( fileName == NULL && (fileName = this->fileName) == NULL )
    206212    return false;
    207213
     
    224230  }
    225231  fclose(stream);
     232}
     233
     234void IniParser::setFileComment(const char* fileComment)
     235{
     236
    226237}
    227238
     
    267278
    268279
     280void IniParser::setSectionComment(const char* comment, const char* sectionName)
     281{
     282
     283}
     284
     285
     286const char* IniParser::getSectionComment(const char* sectionName) const
     287{
     288
     289}
     290
     291
    269292/**
    270293 * @brief moves to the first section
     
    296319  else
    297320    return NULL;
    298 }
    299 
    300 
    301 /**
    302  * @brief moves to the first Variable of the current Section
    303  */
    304 void IniParser::firstVar()
    305 {
    306   if (!this->sections.empty() &&
    307       this->currentSection != this->sections.end())
    308     this->currentEntry = (*this->currentSection).entries.begin();
    309 }
    310 
    311 
    312 /**
    313  * @brief gets the next VarName = VarValue pair from the parsing stream
    314  * @return true on success, false otherwise (in the latter case name and value will be NULL)
    315  */
    316 bool IniParser::nextVar()
    317 {
    318   if ( this->sections.empty()
    319        || this->currentSection == this->sections.end()
    320        || this->currentEntry == (*this->currentSection).entries.end())
    321     return false;
    322 
    323   this->currentEntry++;
    324 
    325   if (this->currentEntry == (*this->currentSection).entries.end())
    326     return false;
    327   else
    328     return true;
    329321}
    330322
     
    351343  else
    352344    section = this->currentSection;
     345
    353346  if (section == this->sections.end())
    354347    return false;
     
    367360    strcpy((*section).entries.back().value, value);
    368361    PRINTF(5)("Added Entry %s with Value '%s' to Section %s\n",
    369               (*section).entries.back().name,
    370               (*section).entries.back().value,
    371               (*section).name);
     362              (*section).entries.back().name,
     363              (*section).entries.back().value,
     364              (*section).name);
    372365    return true;
    373366  }
     
    387380const char* IniParser::getVar(const char* entryName, const char* sectionName, const char* defaultValue) const
    388381{
    389   if (fileName != NULL)
    390   {
    391     std::list<IniSection>::const_iterator section;
    392     if (sectionName != NULL)
    393       {
    394         for (section = this->sections.begin(); section != this->sections.end(); section++)
    395           {
    396             if (!strcmp((*section).name, sectionName))
    397               {
    398                 break;
    399               }
    400           }
    401       }
    402     else
    403       section = this->currentSection;
    404 
    405    if (section == this->sections.end())
    406      {
    407        PRINTF(2)("Section %s that should be containing %s not found.\n", sectionName, entryName);
    408        return (defaultValue);
    409      }
     382  if (this->fileName != NULL)
     383  {
     384    std::list<IniSection>::const_iterator section = this->getSectionIT(sectionName);
     385
     386  if (section == this->sections.end())
     387    {
     388      PRINTF(2)("Section %s that should be containing %s not found.\n", sectionName, entryName);
     389      return (defaultValue);
     390    }
    410391
    411392    std::list<IniEntry>::const_iterator entry;
    412393    for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++)
    413394      if (!strcmp((*entry).name, entryName))
    414         return (*entry).value;
     395        return (*entry).value;
    415396    PRINTF(2)("Entry '%s' in section '%s' not found.\n", entryName, sectionName);
    416397
     
    422403
    423404}
     405
     406
     407const char* IniParser::setEntryComment(const char* comment, const char* entryName, const char* sectionName)
     408{
     409
     410
     411}
     412
     413
     414const char* IniParser::getEntryComment(const char* entryName, const char* sectionName) const
     415{
     416
     417
     418}
     419
     420
     421/**
     422 * @brief moves to the first Variable of the current Section
     423 */
     424void IniParser::firstVar()
     425{
     426  if (!this->sections.empty() &&
     427       this->currentSection != this->sections.end())
     428    this->currentEntry = (*this->currentSection).entries.begin();
     429}
     430
     431
     432/**
     433 * @brief gets the next VarName = VarValue pair from the parsing stream
     434 * @return true on success, false otherwise (in the latter case name and value will be NULL)
     435 */
     436bool IniParser::nextVar()
     437{
     438  if ( this->sections.empty()
     439       || this->currentSection == this->sections.end()
     440       || this->currentEntry == (*this->currentSection).entries.end())
     441    return false;
     442
     443  this->currentEntry++;
     444
     445  if (this->currentEntry == (*this->currentSection).entries.end())
     446    return false;
     447  else
     448    return true;
     449}
     450
    424451
    425452
     
    464491
    465492
     493std::list<IniParser::IniSection>::const_iterator IniParser::getSectionIT(const char* sectionName) const
     494{
     495  std::list<IniSection>::const_iterator section;
     496  if (sectionName != NULL)
     497  {
     498    for (section = this->sections.begin(); section != this->sections.end(); section++)
     499    {
     500      if (!strcmp((*section).name, sectionName))
     501      {
     502        break;
     503      }
     504    }
     505  }
     506  else
     507    section = this->currentSection;
     508
     509  return section;
     510}
     511
     512
     513std::list<IniParser::IniEntry>::const_iterator IniParser::getEntryIT(const char* entryName, const char* sectionName) const
     514{
     515  if (entryName == NULL)
     516    return this->currentEntry;
     517
     518}
     519
     520
     521
    466522/**
    467523 * @brief output the whole tree in a nice and easy way.
  • trunk/src/lib/parser/ini_parser/ini_parser.h

    r5944 r5945  
    2727    struct IniEntry
    2828    {
    29       char*              name;     //!< name of a given Entry
    30       char*              value;    //!< value of a given Entry
     29      char*               comment;  //!< A Comment that is appendet to the Top of this Entry.
     30      char*               name;     //!< name of a given Entry
     31      char*               value;    //!< value of a given Entry
    3132    };
     33
    3234    //! a struct for Sections in the Parser's file
    3335    struct IniSection
    3436    {
    35       char*               name;    //!< name of a given section
    36       std::list<IniEntry> entries; //!< a list of entries for this section
     37      char*               comment;  //!< A Comment that is appendet to the Top of this Section.
     38      char*               name;     //!< name of a given section
     39      std::list<IniEntry> entries;  //!< a list of entries for this section
    3740    };
    3841    ////////////////////////////////////
     
    4245    ~IniParser ();
    4346
     47    /** @returns true if the file is opened, false otherwise*/
     48    bool isOpen() const { return (this->fileName != NULL)? true : false; };
     49    /** @returns the fileName we have opened. */
     50    const char* getFileName() const { return this->fileName; };
     51
    4452    bool readFile(const char* fileName);
    4553    bool writeFile(const char* fileName) const;
    4654
     55    void setFileComment(const char* fileComment);
     56    const char* getFileComment() const { return this->comment; };
     57
    4758    bool addSection(const char* sectionName);
    4859    bool getSection(const char* sectionName);
     60    void setSectionComment(const char* comment, const char* sectionName);
     61    const char* getSectionComment(const char* sectionNane) const;
    4962
    50     /** @returns true if the file is opened, false otherwise*/
    51     bool isOpen() const { return (this->fileName != NULL)? true : false; };
    52 
     63    // iterate through sections with these Functions
    5364    void firstSection();
    5465    const char* nextSection();
    5566
    56     /** @returns the fileName we have opened. */
    57     const char* getFileName() const { return this->fileName; };
    5867
    5968    bool addVar(const char* entryName, const char* value, const char* sectionName = NULL);
    6069    const char* getVar(const char* entryName, const char* sectionName, const char* defaultValue = "") const;
     70    const char* setEntryComment(const char* comment, const char* entryName, const char* sectionName);
     71    const char* getEntryComment(const char* entryName, const char* sectionName) const;
    6172
     73    // iterate Through Variables with these Functions.
    6274    void firstVar();
    6375    bool nextVar();
    6476
     77
     78    // retrieving functions when iterating.
    6579    const char* getCurrentSection() const;
    6680    const char* getCurrentName() const;
    6781    const char* getCurrentValue() const;
    6882
     83
     84    // maintenance.
    6985    void debug() const;
    7086
     
    7490    void setFileName(const char* fileName);
    7591
     92    std::list<IniSection>::const_iterator getSectionIT(const char* sectionName) const;
     93    std::list<IniEntry>::const_iterator getEntryIT(const char* entryName, const char* sectionName = NULL) const;
     94
    7695  private:
    7796    char*                            fileName;        //!< The name of the File that was parsed.
     97    char*                            comment;         //!< A Comment for the header of this File.
    7898    std::list<IniSection>            sections;        //!< a list of all stored Sections of the Parser
    7999    std::list<IniSection>::iterator  currentSection;  //!< the current selected Section
    80100    std::list<IniEntry>::iterator    currentEntry;    //!< the current selected entry (in currentSection)
     101
     102    std::list<char*>                 commentList;     //!< A list of Comments. (this is for temporary saving of Comments, that are inserted in front of Sections/Entries.)
    81103};
    82104
Note: See TracChangeset for help on using the changeset viewer.