Inherited by YGP::INIList< T, L >, and YGP::INIMap< T, M >.
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 IAttribute * | findAttribute (const std::string &name) const |
const IAttribute * | findAttribute (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 IAttribute * | pFoundAttr |
std::vector< const IAttribute * > | attributes |
Friends | |
class | INIFile |
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).
YGP::INISection::INISection | ( | const char * | name | ) |
Constructor; name is the name of the section.
name | Name of section |
YGP::INISection::~INISection | ( | ) | [virtual] |
Destructor.
void YGP::INISection::addAttribute | ( | const IAttribute & | attribute | ) |
Adds an attribute to parse to the section.
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.
name | Name of attribute to find |
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.
name | Name of attribute to find |
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
key | Name of the found key | |
int | Unused length of the section name |
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.
section | Name of found section | |
int | Unused length of the section name |
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.
value | Value to assign to the (previously) found attribute | |
len | Length of text hold by value |
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.
name | Name 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.
stream | Extended stream to read from |
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.
stream | Extended stream to read from |
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.
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.
std::vector<const IAttribute*> YGP::INISection::attributes [protected] |
Attributes of the section.
const IAttribute* YGP::INISection::pFoundAttr [protected] |
Pointer to last parsed attribute.