ini-cpp
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
inih::INIReader Class Reference

Public Member Functions

 INIReader (std::string filename)
 Construct an INIReader object from a file name. More...
 
 INIReader (FILE *file)
 Construct an INIReader object from a file pointer. More...
 
int ParseError () const
 
const std::set< std::string > Sections () const
 Return the list of sections found in ini file. More...
 
const std::set< std::string > Keys (std::string section) const
 Return the list of keys in the given section. More...
 
const std::unordered_map< std::string, std::string > Get (std::string section) const
 Get the map representing the values in a section of the INI file. More...
 
template<typename T = std::string>
Get (const std::string &section, const std::string &name) const
 Return the value of the given key in the given section. More...
 
template<typename T >
Get (const std::string &section, const std::string &name, T &&default_v) const
 Return the value of the given key in the given section, return default if not found. More...
 
template<typename T = std::string>
std::vector< T > GetVector (const std::string &section, const std::string &name) const
 Return the value array of the given key in the given section. More...
 
template<typename T >
std::vector< T > GetVector (const std::string &section, const std::string &name, const std::vector< T > &default_v) const
 Return the value array of the given key in the given section, return default if not found. More...
 
template<typename T = std::string>
void InsertEntry (const std::string &section, const std::string &name, const T &v)
 Insert a key-value pair into the INI file. More...
 
template<typename T = std::string>
void InsertEntry (const std::string &section, const std::string &name, const std::vector< T > &vs)
 Insert a vector of values into the INI file. More...
 
template<typename T = std::string>
void UpdateEntry (const std::string &section, const std::string &name, const T &v)
 Update a key-value pair in the INI file. More...
 
template<typename T = std::string>
void UpdateEntry (const std::string &section, const std::string &name, const std::vector< T > &vs)
 Update a vector of values in the INI file. More...
 

Protected Member Functions

template<typename T >
Converter (const std::string &s) const
 
const bool BoolConverter (std::string s) const
 
template<typename T >
std::string V2String (const T &v) const
 
template<typename T >
std::string Vec2String (const std::vector< T > &v) const
 

Static Protected Member Functions

static int ValueHandler (void *user, const char *section, const char *name, const char *value)
 

Protected Attributes

int _error
 
std::unordered_map< std::string, std::unordered_map< std::string, std::string > > _values
 

Constructor & Destructor Documentation

◆ INIReader() [1/2]

inih::INIReader::INIReader ( std::string  filename)
inline

Construct an INIReader object from a file name.

Parameters
filenameThe name of the INI file to parse
Exceptions
std::runtime_errorif there is an error parsing the INI file

◆ INIReader() [2/2]

inih::INIReader::INIReader ( FILE *  file)
inline

Construct an INIReader object from a file pointer.

Parameters
fileA pointer to the INI file to parse
Exceptions
std::runtime_errorif there is an error parsing the INI file

Member Function Documentation

◆ Get() [1/3]

template<typename T >
T inih::INIReader::Get ( const std::string &  section,
const std::string &  name 
) const
inline

Return the value of the given key in the given section.

Parameters
sectionThe section name
nameThe key name
Returns
The value of the given key in the given section

◆ Get() [2/3]

template<typename T >
T inih::INIReader::Get ( const std::string &  section,
const std::string &  name,
T &&  default_v 
) const
inline

Return the value of the given key in the given section, return default if not found.

Parameters
sectionThe section name
nameThe key name
default_vThe default value
Returns
The value of the given key in the given section, return default if not found

◆ Get() [3/3]

const std::unordered_map< std::string, std::string > inih::INIReader::Get ( std::string  section) const
inline

Get the map representing the values in a section of the INI file.

Parameters
sectionThe name of the section to retrieve
Returns
The map representing the values in the given section
Exceptions
std::runtime_errorif the section is not found

◆ GetVector() [1/2]

template<typename T >
std::vector< T > inih::INIReader::GetVector ( const std::string &  section,
const std::string &  name 
) const
inline

Return the value array of the given key in the given section.

Parameters
sectionThe section name
nameThe key name
Returns
The value array of the given key in the given section.

For example:

[section]
key = 1 2 3 4
const auto vs = ini.GetVector<std::vector<int>>("section", "key");
// vs = {1, 2, 3, 4}

◆ GetVector() [2/2]

template<typename T >
std::vector< T > inih::INIReader::GetVector ( const std::string &  section,
const std::string &  name,
const std::vector< T > &  default_v 
) const
inline

Return the value array of the given key in the given section, return default if not found.

Parameters
sectionThe section name
nameThe key name
default_vThe default value
Returns
The value array of the given key in the given section, return default if not found
See also
INIReader::GetVector

◆ InsertEntry() [1/2]

template<typename T >
void inih::INIReader::InsertEntry ( const std::string &  section,
const std::string &  name,
const std::vector< T > &  vs 
)
inline

Insert a vector of values into the INI file.

Parameters
sectionThe section name
nameThe key name
vsThe vector of values to insert
Exceptions
std::runtime_errorif the key already exists in the section

◆ InsertEntry() [2/2]

template<typename T >
void inih::INIReader::InsertEntry ( const std::string &  section,
const std::string &  name,
const T &  v 
)
inline

Insert a key-value pair into the INI file.

Parameters
sectionThe section name
nameThe key name
vThe value to insert
Exceptions
std::runtime_errorif the key already exists in the section

◆ Keys()

const std::set< std::string > inih::INIReader::Keys ( std::string  section) const
inline

Return the list of keys in the given section.

Parameters
sectionThe section name
Returns
The list of keys in the given section

◆ Sections()

const std::set< std::string > inih::INIReader::Sections ( ) const
inline

Return the list of sections found in ini file.

Returns
The list of sections found in ini file

◆ UpdateEntry() [1/2]

template<typename T >
void inih::INIReader::UpdateEntry ( const std::string &  section,
const std::string &  name,
const std::vector< T > &  vs 
)
inline

Update a vector of values in the INI file.

Parameters
sectionThe section name
nameThe key name
vsThe new vector of values to set
Exceptions
std::runtime_errorif the key does not exist in the section

◆ UpdateEntry() [2/2]

template<typename T >
void inih::INIReader::UpdateEntry ( const std::string &  section,
const std::string &  name,
const T &  v 
)
inline

Update a key-value pair in the INI file.

Parameters
sectionThe section name
nameThe key name
vThe new value to set
Exceptions
std::runtime_errorif the key does not exist in the section

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