mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
mx::app::iniFile Struct Reference

A wrapper for the ini functions.

Places results of the ini parser in an unordered map, with keys of "section=name", and value strings containing the value of the config item.

Definition at line 46 of file iniFile.hpp.

#include <app/iniFile.hpp>

Public Types

typedef std::unordered_map< std::string, std::string > nameMapT
 the unordered map type used for storing values. More...
 

Public Member Functions

int parse (const std::string &fname)
 Calls the inih parse function with this->handler. More...
 
int insert (const char *section, const char *name, const char *value)
 Insert a config value. Appends if the key already exists in the map. More...
 
size_t count (const std::string &section, const std::string &name)
 Get the number of entries for the given section and name. More...
 
int erase (const std::string &section, const std::string &name)
 Erase the entry for the given section and name. More...
 
std::string operator() (const std::string &section, const std::string &name)
 Get the value associated with this section=name pair. More...
 
std::string operator() (const std::string &name)
 Get the value associated with this name with an empty section. More...
 

Static Public Member Functions

static std::string makeKey (const std::string &section, const std::string &name)
 Return a key generated from the section and name. More...
 
static int parseKey (std::string &section, std::string &name, const std::string &key)
 Parse a key into its section and name consituents. More...
 
static int handler (void *user, const char *section, const char *name, const char *value)
 Config entry handler for the parser. More...
 

Public Attributes

nameMapT names
 The map of section=name keys to values. More...
 

Member Typedef Documentation

◆ nameMapT

typedef std::unordered_map<std::string, std::string> mx::app::iniFile::nameMapT

the unordered map type used for storing values.

Definition at line 48 of file iniFile.hpp.

Member Function Documentation

◆ count()

size_t mx::app::iniFile::count ( const std::string &  section,
const std::string &  name 
)
inline

Get the number of entries for the given section and name.

Is either 1 or 0, depending on if this cconfig key exists.

Returns
the number of entries for the section=name key.
Parameters
[in]sectionThe section for the key
[in]namethe name for the key

Definition at line 141 of file iniFile.hpp.

References makeKey(), and names.

Referenced by mx::app::appConfigurator::readConfig().

◆ erase()

int mx::app::iniFile::erase ( const std::string &  section,
const std::string &  name 
)
inline

Erase the entry for the given section and name.

Returns
0 on sucess
-1 if no section=name entry in the map.
Parameters
[in]sectionThe section for the key
[in]namethe name for the key

Definition at line 153 of file iniFile.hpp.

References makeKey(), and names.

Referenced by mx::app::appConfigurator::readConfig().

◆ handler()

static int mx::app::iniFile::handler ( void *  user,
const char *  section,
const char *  name,
const char *  value 
)
inlinestatic

Config entry handler for the parser.

Calls insert, and returns its result. Any non-zero return will cause ini_parse to report the current line number as an error.

Returns
1 on success
0 on error
Parameters
[in]usera pointer to this.
[in]sectionthe section of the config entry
[in]namethe name of the config entry
[in]valuethe value of the config entry

Definition at line 126 of file iniFile.hpp.

References insert().

Referenced by parse().

◆ insert()

int mx::app::iniFile::insert ( const char *  section,
const char *  name,
const char *  value 
)
inline

Insert a config value. Appends if the key already exists in the map.

Todo:
need error checking.
Returns
0 on success
-1 on error.
Parameters
[in]sectionThe section for the key
[in]namethe name for the key
[in]valuethe value to insert

Definition at line 105 of file iniFile.hpp.

References makeKey(), and names.

Referenced by handler().

◆ makeKey()

static std::string mx::app::iniFile::makeKey ( const std::string &  section,
const std::string &  name 
)
inlinestatic

Return a key generated from the section and name.

Constructs the key as "section=name".

Returns
the created key.
Parameters
[in]sectionThe section for the key
[in]namethe name for the key

Definition at line 57 of file iniFile.hpp.

Referenced by mx::app::appConfigurator::configUnused(), count(), erase(), insert(), and operator()().

◆ operator()() [1/2]

std::string mx::app::iniFile::operator() ( const std::string &  name)
inline

Get the value associated with this name with an empty section.

Returns
the value if the section=name key exists, with section empty
and empty string if the section=name key does not exist, with section empty.
Parameters
[in]namethe name for the key

Definition at line 186 of file iniFile.hpp.

References operator()().

◆ operator()() [2/2]

std::string mx::app::iniFile::operator() ( const std::string &  section,
const std::string &  name 
)
inline

Get the value associated with this section=name pair.

Returns
the value if the section=name key exists
and empty string if the section=name key does not exist.
Parameters
[in]sectionThe section for the key
[in]namethe name for the key

Definition at line 166 of file iniFile.hpp.

References makeKey(), and names.

Referenced by operator()().

◆ parse()

int mx::app::iniFile::parse ( const std::string &  fname)
inline

Calls the inih parse function with this->handler.

This returns the result of the ini_parse function.

Returns
0 on success
>0 is the line number of the first parsing error
-1 on file open error
-2 on memory allocation error
Parameters
[in]fnamethe full path of the file

Definition at line 94 of file iniFile.hpp.

References handler(), and ini_parse().

Referenced by mx::app::appConfigurator::readConfig().

◆ parseKey()

static int mx::app::iniFile::parseKey ( std::string &  section,
std::string &  name,
const std::string &  key 
)
inlinestatic

Parse a key into its section and name consituents.

Requires that = be present.

Returns
0 on success
-1 on error, if no = found.
Parameters
[out]sectionthe section extracted from the key
[out]namethe name extracted from the key
[in]keyth key to parse.

Definition at line 70 of file iniFile.hpp.

Referenced by mx::app::appConfigurator::readConfig().

Member Data Documentation

◆ names

nameMapT mx::app::iniFile::names

The map of section=name keys to values.

Definition at line 50 of file iniFile.hpp.

Referenced by count(), erase(), insert(), operator()(), and mx::app::appConfigurator::readConfig().


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