UNIVERS
15.3
UNIVERS base processing software API
|
Class for operating with one section of ini-file. More...
#include <IniSection.hpp>
Public Types | |
enum | MergeMode { AppendAll, AppendNew, Overwrite, Replace } |
Public Member Functions | |
IniSection (const char *szSectionType, const char *szSectionName) | |
IniSection (const char *szTextBlock) | |
IniSection (const IniSection &ini_sect) | |
virtual | ~IniSection () |
const char * | get_section_type () const |
const char * | get_section_name () const |
void | set_section_name (const char *name) |
virtual char * | make_text () const |
virtual void | parse_text (const char *text, int **err_lines=NULL) |
virtual int | count () const |
virtual const OptionItem * | get (int i) const |
const OptionItem & | operator() (int i) const |
virtual OptionItem * | fetch (int i) |
OptionItem & | operator[] (int i) |
virtual int | n2i (const char *name, int start_index=0) const |
virtual void | remove (int i) |
virtual const char * | get_value (const char *name) const |
int | get_int_value (const char *name, int def_value=0) const |
double | get_double_value (const char *name, double def_value=0.0) const |
const char * | operator() (const char *name) const |
virtual char * | fetch_value (const char *name) |
char * | operator[] (const char *name) |
virtual OptionItem ** | match (const char *word) |
virtual void | add (const char *name, const char *value) |
void | add (const char *name, int v) |
void | add (const char *name, double v) |
virtual void | put (const char *name, const char *value) |
void | put (const char *name, int v) |
void | put (const char *name, double v) |
void | merge (const IniSection &ini_sect, MergeMode mode=AppendAll) |
Protected Attributes | |
OptionBase | ob |
char * | section_type |
char * | section_name |
Class for operating with one section of ini-file.
The section in ini-file has next format:
[SectionType SectionName] Name1 = Value1 Name2 = Value2 ... NameN = ValueN
The last line of the section is the last line of file or the line before start of next section.
SectionName is optional. In case of it is not empty it allows to distinguish several sections of the same type in the same ini-file.
Each text line is represented by pair (NAME, VALUE). There can be many lines with the same NAME and even with the same NAME and VALUE.
There are three ways of accessing section contents:
Putting new (NAME, VALUE) pairs can be performed in two ways:
IniSection::IniSection | ( | const char * | szSectionType, |
const char * | szSectionName | ||
) |
Create empty section of given type and name.
IniSection::IniSection | ( | const char * | szTextBlock | ) |
Create section from the raw block of text starting with section header [SectionType SectionName], parsing it and creating list of (NAME, VALUE) pairs.
IniSection::IniSection | ( | const IniSection & | ini_sect | ) |
Create copy of given section.
|
virtual |
Destroy the contents of section.
|
virtual |
Add the pair to the end of section.
void IniSection::add | ( | const char * | name, |
int | v | ||
) |
Add the integer value.
void IniSection::add | ( | const char * | name, |
double | v | ||
) |
Add the double precision value.
|
virtual |
Get total number of pairs in the object.
|
virtual |
Fetch the pair by its index. Returns NULL if index is out of allowed range.
|
virtual |
Fetch the value by its name. Returns NULL if name is not found.
|
virtual |
Get the pair by its index. Returns NULL if index is out of allowed range.
double IniSection::get_double_value | ( | const char * | name, |
double | def_value = 0.0 |
||
) | const |
Return double precision representation of the value. Return default value in case of the name is not found in the section.
int IniSection::get_int_value | ( | const char * | name, |
int | def_value = 0 |
||
) | const |
Return integer representation of the value. Return default value in case of the name is not found in the section.
const char* IniSection::get_section_name | ( | ) | const |
Get the name of the section ("" means anonymous section).
const char* IniSection::get_section_type | ( | ) | const |
Get the type of the section.
|
virtual |
Get the value by its name. Returns NULL if name is not found.
|
virtual |
Compose text representation of current contents of the section. Returned string consists of lines separated by EOL and is ended by EOS ('\0'). Result can be released by free().
|
virtual |
Match all pairs (NAME, VALUE) where NAME started with given word. Returned list of items finished by NULL pointer and must be released by free().
void IniSection::merge | ( | const IniSection & | ini_sect, |
MergeMode | mode = AppendAll |
||
) |
Merge (NAME,VALUE) pairs from given section to this one.
|
virtual |
Find index of the name or return -1 in case of not found. Search is performed from start_index (inclusive). The first encounterd name is referred!
|
inline |
Get the pair by its index. Synonymous to get(). ERROR__OUT_OF_RANGE may be excited in case of bad index.
|
inline |
Get the value by its name. Synonymous to get_value().
|
inline |
Fetch the pair by its index. ERROR__OUT_OF_RANGE may be excited in case of bad index. Synonymous to fetch().
|
inline |
Fetch the value by its name. Synonymous to fetch_value().
|
virtual |
Parse text block and add all encountered pairs (NAME, VALUE) to internal structures. Stop parsing at EOS ('\0'). Optionally may return dynamically allocated list if lines which can't be interpreted as (NAME, VALUE) pairs. The last err_line has 0 number.
|
virtual |
Add the pair to the end of section if name is not found in it or replace value by this one if name exists insection.
void IniSection::put | ( | const char * | name, |
int | v | ||
) |
Add the integer value or replace existent one.
void IniSection::put | ( | const char * | name, |
double | v | ||
) |
Add the double precision value or replace existent one.
|
virtual |
Remove item with given index. In case of not found ERROR__OUT_OF_RANGE will be excited.
void IniSection::set_section_name | ( | const char * | name | ) |
Set the name of the section ("" makes anonymous section). Previous name becomes lost.
|
protected |
Data container for pairs (NAME, VALUE).
|
protected |
Name of the section.
|
protected |
Type of the section.