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 Member Functions | Protected Attributes | List of all members
IniFile Class Reference

Class for operating with ini-file which contains sections. More...

#include <IniFile.hpp>

Public Types

enum  LoadMode { Append, Overwrite, Truncate, Merge }
 

Public Member Functions

 IniFile ()
 
 IniFile (const char *path)
 
virtual ~IniFile ()
 
virtual void set_path (const char *path)
 
virtual void save () const
 
virtual void save (const char *path) const
 
virtual void load (const char *path, LoadMode mode=Overwrite, IniSection::MergeMode mmode=IniSection::AppendAll)
 
virtual void reload ()
 
virtual const IniSectionget (const char *type, const char *name="") const
 
const IniSectionoperator() (const char *type, const char *name="") const
 
virtual IniSectionfetch (const char *type, const char *name="")
 
IniSectionoperator[] (const char *type)
 
virtual IniSectionadd_section (const char *type, const char *name="")
 
virtual void remove_section (const char *type, const char *name="")
 
virtual char ** get_list_of_types (int &n) const
 
virtual char ** get_list_of_names (const char *type, int &n) const
 

Protected Member Functions

int tn2i (const char *type, const char *name) const
 

Protected Attributes

char * ini_path
 
struct stat stat_buf
 
IniSectionsAr isar
 

Detailed Description

Class for operating with ini-file which contains sections.

The ini-file has following format:

   [SectionType1 SectionName1]
    section lines
    ...
   [SectionType2 SectionName2]
    section lines
    ...

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.

Member Enumeration Documentation

Enumerator
Append 

adding only newly encountered section

Overwrite 

overwriting existing sections

Truncate 

truncating previous contents before loading

Merge 

merge existing sections with new contents

Constructor & Destructor Documentation

IniFile::IniFile ( )

Open empty ini-file without.

IniFile::IniFile ( const char *  path)

Open given ini-file and read all sections from it to local array.

virtual IniFile::~IniFile ( )
virtual

Destroy the object without flushing the contents of sections to disk file.

Member Function Documentation

virtual IniSection* IniFile::add_section ( const char *  type,
const char *  name = "" 
)
virtual

Create new section or return pointer to existent one. The last case take place only if type and name are matched exactly.

virtual IniSection& IniFile::fetch ( const char *  type,
const char *  name = "" 
)
virtual

Get the section by type and name (the last one encountered). ERROR__NOT_FOUND may be excited in case of no section is found. If name is NULL then the last one mentioned in ini-file with matched type and arbitrary name will be returned.

virtual const IniSection& IniFile::get ( const char *  type,
const char *  name = "" 
) const
virtual

Get the section by type and name (the last one encountered). ERROR__NOT_FOUND may be excited in case of no section is found. If name is NULL then the last one mentioned in ini-file with matched type and arbitrary name will be returned.

virtual char** IniFile::get_list_of_names ( const char *  type,
int &  n 
) const
virtual

Get list of names for given type and its volume n. The list may be released by strlistfree().

virtual char** IniFile::get_list_of_types ( int &  n) const
virtual

Get list of types and its volume n. The list may be released by strlistfree().

virtual void IniFile::load ( const char *  path,
LoadMode  mode = Overwrite,
IniSection::MergeMode  mmode = IniSection::AppendAll 
)
virtual

Load given ini-file to the object. Depending the flag loading may be done with truncating previous contents, overwriting existing sections, adding only newly encountered section or merging existent sections. In the last case section merging may be tuned according to special mode which allows to truncate, overwrite or append (NAME,VALUE) pairs.

const IniSection& IniFile::operator() ( const char *  type,
const char *  name = "" 
) const
inline

Synonymous to get(const char* type, const char* name).

IniSection& IniFile::operator[] ( const char *  type)
inline

Synonymous to fetch(const char* type, const char* name = "").

virtual void IniFile::reload ( )
virtual

Reload contents of original file taking care of changed on disk sections (IniFile::Overwrite).

virtual void IniFile::remove_section ( const char *  type,
const char *  name = "" 
)
virtual

Remove section. If name is NULL then the last one mentioned in ini-file with matched type and arbitrary name will be returned.

virtual void IniFile::save ( ) const
virtual

Save contents of all sections to original file. Does nothing in case of empty file path.

virtual void IniFile::save ( const char *  path) const
virtual

Save contents of all sections to given file.

virtual void IniFile::set_path ( const char *  path)
virtual

Setup new file path.

int IniFile::tn2i ( const char *  type,
const char *  name 
) const
protected

Find the index of section with given type and name. If name is NULL then the last one mentioned in ini-file with matched type and arbitrary name will be returned. Return -1 if not found.

Member Data Documentation

char* IniFile::ini_path
protected

Path to the ini-file. May be NULL in case of

IniSectionsAr IniFile::isar
protected

Array of section in file/creation order.

struct stat IniFile::stat_buf
protected

File info which allows to make smart reload in case of changed contents


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