YGP::INISection Class Reference

Class to handle the information stored in a section of an INI-file (see INIFile for more details). More...

Inherited by YGP::INIList< T, L >, and YGP::INIMap< T, M >.

List of all members.

Classes

class  ISectionParser
 Class to parse a section header; the found name (if any) is reported via the callback set in the constructor.
class  TSectionParser
 Templated SectionParser; to inform the caller about the found section.

Public Member Functions

 INISection (const char *name)
virtual ~INISection ()
const IAttributefindAttribute (const std::string &name) const
const IAttributefindAttribute (const char *name) const
void addAttribute (const IAttribute &attribute)
int readFromStream (Xistream &stream) throw (YGP::ParseError)
int readAttributes (Xistream &stream) throw (YGP::ParseError)
const char * getName () const
bool matches (const char *name) const
void writeHeader (std::ostream &stream)

Static Public Member Functions

static void skipComments (Xistream &stream)
static void writeHeader (std::ostream &stream, const char *section)

Protected Member Functions

virtual int foundSection (const char *section, unsigned int)
virtual int foundKey (const char *key, unsigned int)
virtual int foundValue (const char *value, unsigned int)

Protected Attributes

const IAttributepFoundAttr
std::vector< const IAttribute * > attributes

Friends

class INIFile


Detailed Description

Class to handle the information stored in a section of an INI-file (see INIFile for more details).

Usually this class is just used to bundle the attributes of a section together; none of their members is called directly. The only exception is for INI-files without any section, only with attributes. In that case the readAttributes()-member can be used to parse those values (regardless of any header-information).


Constructor & Destructor Documentation

YGP::INISection::INISection ( const char *  name  ) 

Constructor; name is the name of the section.

Parameters:
name Name of section
Remarks:
name must be a valid ASCIIZ-string (not NULL)

YGP::INISection::~INISection (  )  [virtual]

Destructor.


Member Function Documentation

void YGP::INISection::addAttribute ( const IAttribute attribute  ) 

Adds an attribute to parse to the section.

Parameters:
attribute Attribute to add

const IAttribute * YGP::INISection::findAttribute ( const char *  name  )  const

Searches for an attribute matching the passed name.

If such an attribute is not found, NULL is returned.

Parameters:
name Name of attribute to find
Returns:
IAttribute* Pointer to attribute or NULL (if not found)
Remarks:
name must not be a NULL pointer

const IAttribute * YGP::INISection::findAttribute ( const std::string &  name  )  const

TriesSearches for an attribute matching the passed name.

If such an attribute is not found, NULL is returned.

Parameters:
name Name of attribute to find
Returns:
IAttribute* Pointer to attribute or NULL (if not found)

int YGP::INISection::foundKey ( const char *  key,
unsigned  int 
) [protected, virtual]

Callback if a key of an attribute has been found.

Every attribute of the section is compared with the passed key. If they match the value of the key is assigned to the attribute

Parameters:
key Name of the found key
int Unused length of the section name
Returns:
int PARSE_OK, if key is found; else ParseObject::PARSE_CB_ABORT.

Reimplemented in YGP::INIList< T, L >, and YGP::INIMap< T, M >.

int YGP::INISection::foundSection ( const char *  section,
unsigned  int 
) [protected, virtual]

Callback when the name of a section was found.

Parameters:
section Name of found section
int Unused length of the section name
Returns:
int PARSE_OK, if name of section is OK

int YGP::INISection::foundValue ( const char *  value,
unsigned int  len 
) [protected, virtual]

Callback if a value of an attribute has been found.

This value is assigned using the assign-member of IAttribute.

Parameters:
value Value to assign to the (previously) found attribute
len Length of text hold by value
Returns:
int PARSE_OK, if value could be assigned successfully; else ParseObject::PARSE_CB_ABORT

Reimplemented in YGP::INIList< T, L >, and YGP::INIMap< T, M >.

const char* YGP::INISection::getName (  )  const [inline]

Returns the name of the section.

bool YGP::INISection::matches ( const char *  name  )  const [inline]

Returns if the name of the section matches the passed text.

Parameters:
name Name of the section
Returns:
bool True, if the passed name matches that of the section

int YGP::INISection::readAttributes ( Xistream stream  )  throw (YGP::ParseError)

Tries to read the attributes of a section from the INI-file.

Every key=value pair is inspected and - if key matches the name of an attribute in the section - assigned to the connected variable. The function returns ParseObject::PARSE_OK, if EOF or a new section-header (to be exact: Anything which is not a key) is reached. Errors are returned (or execeptions are thrown) if the attribute is either not found inside the class or the value can not be assigned.

Parameters:
stream Extended stream to read from
Returns:
int ParseObject::OK if a know key is found and it's value can be assigned Remarks The exact behaviour depends on the type of the attribute!
Exceptions:
YGP::ParseError With text describing error if an unrecoverable error occurs

int YGP::INISection::readFromStream ( Xistream stream  )  throw (YGP::ParseError)

Tries to reads the (whole) section from the INI-file.

First the section header is parsed. Note that the name of the section in the INI-file must match those of the class. If the header can be parsed successfully, every following key=value pair is inspected and - if key matches the name of an attribute in the section - assigned to the connected variable. The function returns ParseObject::PARSE_OK, if EOF or a new section-header (to be exact: Anything which is not a key) is reached. Errors are returned (or execeptions are thrown) if the attribute is either not found inside the class or the value can not be assigned.

Parameters:
stream Extended stream to read from
Returns:
int ParseObject::OK if a know key is found and it's value can be assigned Remarks The exact behaviour depends on the type of the attribute!
Exceptions:
YGP::ParseError With text describing error if an unrecoverable error occurs

void YGP::INISection::skipComments ( Xistream stream  )  [static]

Skips over comments (the text following a semi-colon (;) til the end of the line.

Parameters:
stream Stream to read from

static void YGP::INISection::writeHeader ( std::ostream &  stream,
const char *  section 
) [inline, static]

Writes the passed name as header of a section to the passed stream.

void YGP::INISection::writeHeader ( std::ostream &  stream  )  [inline]

Writes a header for the section to the passed stream.


Member Data Documentation

std::vector<const IAttribute*> YGP::INISection::attributes [protected]

Attributes of the section.

Pointer to last parsed attribute.


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

YGP Version 0.9.31 - Generated on Wed Nov 18 11:25:27 2009 by doxygen 1.5.8