UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Types | Public Member Functions | Protected Attributes | List of all members
IniSection Class Reference

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 OptionItemget (int i) const
 
const OptionItemoperator() (int i) const
 
virtual OptionItemfetch (int i)
 
OptionItemoperator[] (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
 

Detailed Description

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:

Member Enumeration Documentation

Enumerator
AppendAll 

adding all names

AppendNew 

adding only newly encountered names

Overwrite 

overwriting existing names

Replace 

replace contents of this section by given one

Constructor & Destructor Documentation

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 IniSection::~IniSection ( )
virtual

Destroy the contents of section.

Member Function Documentation

virtual void IniSection::add ( const char *  name,
const char *  value 
)
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 int IniSection::count ( ) const
virtual

Get total number of pairs in the object.

virtual OptionItem* IniSection::fetch ( int  i)
virtual

Fetch the pair by its index. Returns NULL if index is out of allowed range.

virtual char* IniSection::fetch_value ( const char *  name)
virtual

Fetch the value by its name. Returns NULL if name is not found.

virtual const OptionItem* IniSection::get ( int  i) const
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 const char* IniSection::get_value ( const char *  name) const
virtual

Get the value by its name. Returns NULL if name is not found.

virtual char* IniSection::make_text ( ) const
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 OptionItem** IniSection::match ( const char *  word)
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 int IniSection::n2i ( const char *  name,
int  start_index = 0 
) const
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!

const OptionItem & IniSection::operator() ( int  i) const
inline

Get the pair by its index. Synonymous to get(). ERROR__OUT_OF_RANGE may be excited in case of bad index.

const char * IniSection::operator() ( const char *  name) const
inline

Get the value by its name. Synonymous to get_value().

OptionItem & IniSection::operator[] ( int  i)
inline

Fetch the pair by its index. ERROR__OUT_OF_RANGE may be excited in case of bad index. Synonymous to fetch().

char * IniSection::operator[] ( const char *  name)
inline

Fetch the value by its name. Synonymous to fetch_value().

virtual void IniSection::parse_text ( const char *  text,
int **  err_lines = NULL 
)
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 void IniSection::put ( const char *  name,
const char *  value 
)
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 void IniSection::remove ( int  i)
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.

Member Data Documentation

OptionBase IniSection::ob
protected

Data container for pairs (NAME, VALUE).

char* IniSection::section_name
protected

Name of the section.

char* IniSection::section_type
protected

Type of the section.


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