Slice Tools
  • Home
  • SourceForge Page


  • libFoundation
  • Home
  • Class Hierarchy
  • Class List
  • Class Members
  • Examples


  • SourceForge.net Logo
     

    ConfigSection Class Reference

    #include <ConfigSection.hh>

    List of all members.


    Detailed Description

    Class to manage individual sections of a config file.
    Examples:

    example-configfile.cc.


    Public Member Functions

     ConfigSection (ConfigSection *parent, std::string sectionName)
     Constructor.

     ~ConfigSection ()
     Destructor.

    ConfigSectionfindSection (std::string sectionName)
     Recursively find and return proper section.

    void printSection (int indentLevel=0, std::ostream &os=std::cout)
     Dumps a section (and subsections) to an ostream.

    std::string getSectionName ()
     Simple Accessor to getSectionName.

    std::string getFullSectionName ()
     Prints out full name of section by recursively prependind parent name.

    std::string getFullVariableName (std::string variableName)
     Prepends the full section name to a variable name.

    ConfigSectiongetNextSection ()
     Returns a pointer to the next section in the section list.

    std::string getNextVariable ()
     Returns the next variable name in the variable map.

    std::string getValue (std::string variableName)
     Returns the value for a variable from the map at the current section.

    bool hasVariable (std::string variableName)
     Checks for the existence of a variable in section map.

    void resetIterators ()
     Reset the iterators to the beginning for getNextSection and getNextVariable.


    Protected Member Functions

    ConfigSectionaddNewSection (std::string sectionName)
     Creates a new section, adds it to the appropriate section lists.

    void resolveSubstitutions ()
     Resolves the variable substitutions.

    void addVariable (const char *varLine)
     Parses a string, and adds variable=value into m_valueMap.


    Static Protected Member Functions

    std::string parseSectionName (const char *sectionName)
     Extracts Section Name from raw string.


    Friends

    class ConfigFile


    Constructor & Destructor Documentation

    ConfigSection::ConfigSection ConfigSection parent,
    std::string  sectionName
     

    Constructor.

    Create new section.

    Parameters:
    parent Pointer to parent section, or NULL
    sectionName Name of section

    ConfigSection::~ConfigSection  ) 
     

    Destructor.

    Deletes all subsections as well.


    Member Function Documentation

    ConfigSection * ConfigSection::addNewSection std::string  sectionName  )  [protected]
     

    Creates a new section, adds it to the appropriate section lists.

    sectionName is full name to section as in base.child.child2, and will automatically create base and base.child if needed. Trying to add an existing section will return a pointer to that section

    Parameters:
    sectionName Name of the section to add
    Returns:
    Returns a pointer to the child class created

    void ConfigSection::addVariable const char *  varLine  )  [protected]
     

    Parses a string, and adds variable=value into m_valueMap.

    Used to extract (variable,value) pair from file. It does not do any variable substitutions, but it will strip away unneed whitespace.

    Parameters:
    varLine Raw line to parse (directly from file)
    Exceptions:
    InvalidConfigNameError On first character of line is '='

    ConfigSection * ConfigSection::findSection std::string  sectionName  ) 
     

    Recursively find and return proper section.

    Parameters:
    sectionName Section Name to search relative to current section
    Returns:
    Pointer to matching section or NULL if not found

    std::string ConfigSection::getFullSectionName  ) 
     

    Prints out full name of section by recursively prependind parent name.

    Returns:
    Full name of section in SECTION_NAME.SUB_SECTION format
    See also:
    getSectionName()
    Examples:
    example-configfile.cc.

    std::string ConfigSection::getFullVariableName std::string  variableName  ) 
     

    Prepends the full section name to a variable name.

    Parameters:
    variableName Name of variable to prepend
    Returns:
    Full name of variable in SECTION_NAME.variableName form
    Examples:
    example-configfile.cc.

    ConfigSection * ConfigSection::getNextSection  ) 
     

    Returns a pointer to the next section in the section list.

    The first time this is called, it returns the first section, after that it iterates through each section in the list.

    Returns:
    The next section in the list, or NULL when list has been exhausted
    See also:
    resetIterators
    Examples:
    example-configfile.cc.

    std::string ConfigSection::getNextVariable  ) 
     

    Returns the next variable name in the variable map.

    The first time it is called, it will return the name of the first variable in the map. Then it iterates until there are no more variables in the current section. Use getValue to access the value of this variable. A result of "" always means the list has been exhausted because no variable can be named "" in the map.

    Returns:
    The next variable name or "" when list exhausted
    See also:
    resetIterators

    getValue

    Examples:
    example-configfile.cc.

    std::string ConfigSection::getSectionName  ) 
     

    Simple Accessor to getSectionName.

    Returns:
    Short Name of current Section (no parent information)
    See also:
    getFullSectionName()

    std::string ConfigSection::getValue std::string  variableName  ) 
     

    Returns the value for a variable from the map at the current section.

    Note: Returns "" if not found which is indistinquishable from a variable having a value of "". Use hasVariable first to check for its existence.

    Parameters:
    variableName Name of variable to get value of
    See also:
    hasVariable
    Examples:
    example-configfile.cc.

    bool ConfigSection::hasVariable std::string  variableName  ) 
     

    Checks for the existence of a variable in section map.

    Only checks for existence, use getValue if this returns true to access its value.

    Parameters:
    variableName Name of variable
    Returns:
    Boolean indicating presense of variable
    See also:
    getValue
    Examples:
    example-configfile.cc.

    std::string ConfigSection::parseSectionName const char *  sectionName  )  [static, protected]
     

    Extracts Section Name from raw string.

    Takes raw string (from file) and removes brackets

    Parameters:
    sectionName Name of Section in [SECTION_NAME] format
    Returns:
    Name of Section in SECTION_NAME format
    Exceptions:
    InvalidConfigNameError If there isn't at least 1 character of section name

    void ConfigSection::printSection int  indentlevel = 0,
    std::ostream &  os = std::cout
     

    Dumps a section (and subsections) to an ostream.

    Useful for debugging.

    Parameters:
    indentlevel Number of spaces to indent
    os Stream to output to

    void ConfigSection::resetIterators  ) 
     

    Reset the iterators to the beginning for getNextSection and getNextVariable.

    See also:
    getNextSection

    getNextVariable

    void ConfigSection::resolveSubstitutions  )  [protected]
     

    Resolves the variable substitutions.

    Works bottom-up (postfix) so that children are resolved before the current level. This way default rules can be specified at top level with specifics at lower levels. However, substitutions will be done and redone rather than saved away even in cases where there would be no conflict in scope.

    Exceptions:
    CircularReferenceError On a reference than includes itself
    MalformedSubstitutionError On a substitution that closes improperly


    Friends And Related Function Documentation

    friend class ConfigFile [friend]
     


    The documentation for this class was generated from the following files: