Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5014 in orxonox.OLD for orxonox/trunk/src/lib/util/ini_parser.h


Ignore:
Timestamp:
Aug 14, 2005, 4:29:29 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: implemented a new kind of ini-parser
this parser first reads the file, and then one can search through without accessing the file anymore

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/util/ini_parser.h

    r4836 r5014  
    11/*!
    2     \file ini_parser.h
    3   * A small ini file parser
    4 
    5     Can be used to find a defined [Section] in an ini file and get the VarName=Value entries
    6 */
     2 * @file ini_parser.h
     3 * A small ini file parser
     4 *
     5 * Can be used to find a defined [Section] in an ini file and get the VarName = Value entries
     6 */
    77
    88#ifndef _INI_PARSER_H
    99#define _INI_PARSER_H
    1010
    11 #include <stdio.h>
    12 #include <string.h>
    13 #include <stdlib.h>
     11#define PARSELINELENGHT     512       //!< how many chars to read at once
     12
    1413#include "base_object.h"
    1514
    16 #define PARSELINELENGHT     512       //!< how many chars to read at once
     15// FORWARD DEFINITION //
     16template<class T> class tList;
    1717
    1818//! ini-file parser
    1919/**
    20        This class can be used to load an initializer file and parse it's contents for variablename=value pairs.
    21 */
     20 * This class can be used to load an initializer file and parse it's contents for variablename=value pairs.
     21 */
    2222class IniParser : public BaseObject
    2323{
    24  public:
    25   IniParser (const char* filename);
    26   ~IniParser ();
     24  private:
     25    ////////////////////////////////////
     26    struct IniEntry
     27    {
     28      char*              name;
     29      char*              value;
     30    };
    2731
    28   const char* getVar(const char* name, const char* section, const char* defvalue);
    29   int openFile(const char* name);
    30   int getSection( const char* section);
    31   int nextVar( const char* name, const char* value);
     32    struct IniSection
     33    {
     34      char*               name;
     35      tList<IniEntry>*    entries;
     36    };
     37    ////////////////////////////////////
    3238
    33  private:
    34   FILE*         stream;                       //!< A FileStream to be loaded
    35   bool          bInSection;                   //!< if the requested parameter is in the section.
    36   char          internbuf[PARSELINELENGHT];   //!< a buffer
     39  public:
     40    IniParser (const char* filename = NULL);
     41    ~IniParser ();
    3742
     43    bool openFile(const char* name);
    3844
     45    bool getSection( const char* sectionName);
     46    const char* nextSection();
     47
     48    bool isOpen() const { return (sections != NULL)?true:false; };
     49
     50    const char* getVar(const char* entryName, const char* sectionName, const char* defaultValue = "") const;
     51    bool nextVar();
     52
     53    const char* getCurrentName() const { return (currentEntry!=NULL)?currentEntry->name:NULL; };
     54    const char* getCurrentValue() const { return (currentEntry!=NULL)?currentEntry->value:NULL; };
     55
     56    void debug() const;
     57
     58  private:
     59    void deleteSections();
     60
     61  private:
     62    tList<IniSection>*    sections;
     63    IniSection*           currentSection;
     64    IniEntry*             currentEntry;
    3965};
    4066
Note: See TracChangeset for help on using the changeset viewer.