OpenM++ runtime library (libopenm)
openm::IniFileReader Class Reference

ini-file reader: load all entries in memory and provide search methods. More...

#include <iniReader.h>

Public Member Functions

 IniFileReader (const char *i_filePath, const char *i_codePageName=nullptr)
 load all ini-file entries in memory and convert into UTF-8. More...
 
bool isLoaded (void) const noexcept
 return true if ini-file loaded correctly or false on error
 
bool isExist (const char *i_section, const char *i_key) const noexcept
 return true if section and key found in ini-file using case-neutral search. More...
 
bool isExist (const char *i_sectionKey) const noexcept
 return true if section.key found in ini-file using case-neutral search. More...
 
const string strValue (const char *i_section, const char *i_key, const string &i_default="") const noexcept
 return string value by section and key using case-neutral search, or default value if not found. More...
 
const string strValue (const char *i_sectionKey, const string &i_default="") const noexcept
 return string value by section.key using case-neutral search, or default value if not found.
 
const IniEntryVec & rowsCRef (void) const
 return const reference to ini-file entries.
 
const NoCaseSet sectionSet (void) const noexcept
 return names of ini-file sections as case-neutral set of strings.
 
const NoCaseMap getSection (const char *i_section) const noexcept
 return section by name as case-neutral map of (key,value).
 

Static Public Member Functions

static void loadMessages (const char *i_iniMsgPath, const string &i_language="", const char *i_codePageName=nullptr) noexcept
 read language specific messages from path/to/theExe.message.ini and pass it to the log
 
static list< pair< string, unordered_map< string, string > > > loadAllMessages (const char *i_iniMsgPath, const char *i_codePageName=nullptr) noexcept
 read language specific messages from path/to/theExe.message.ini for all languages More...
 

Detailed Description

ini-file reader: load all entries in memory and provide search methods.

Constructor & Destructor Documentation

◆ IniFileReader()

IniFileReader::IniFileReader ( const char *  i_filePath,
const char *  i_codePageName = nullptr 
)

load all ini-file entries in memory and convert into UTF-8.

Parameters
[in]i_filePathpath to ini-file.
[in]i_codePageName(optional) name of encoding or Windows code page, ie: English_US.1252
[in]i_filePathpath to ini-file.
[in]i_codePageName(optional) name of encoding or Windows code page, ie: English_US.1252

Ini file example:

[section] ; section is required, global entries are not allowed

this is also a comment

rem = ; comment only and empty value ; next line is empty value without comment non = val = no comments dsn = "DSN='server'; UID='user'; PWD='secret';" ; comment: database connection string lst = "the # quick" brown 'fox # jumps ; over' # use "quote" and 'apostrophe' to escape characters and keep spaces unb = "unbalanced quote ; this is not a comment: it is a value started from " quote

trim = Aname,Bname, \ ; comment: multi-line value joined with spaces trimmed Cname,DName ; comment: result is: Aname,Bname,Cname,DName

abcd = Aname,Bname, \ ; multi-line value ended with empty line Cname,DName \ ; result is: ; Aname,Bname,Cname,DName

; multi-line value started with " quote or ' apostrophe ; right spaces before \ is not trimmed, result is: ; Multi line text with spaces ; keep = "Multi line \ text with spaces" ; multi-line value started with " quote or ' apostrophe ; result is the same as above: ; Multi line text with spaces ; same = "\ Multi line \ text with spaces\ "

Member Function Documentation

◆ isExist() [1/2]

bool IniFileReader::isExist ( const char *  i_section,
const char *  i_key 
) const
noexcept

return true if section and key found in ini-file using case-neutral search.

return true if section and key exist in ini-file.

◆ isExist() [2/2]

bool IniFileReader::isExist ( const char *  i_sectionKey) const
noexcept

return true if section.key found in ini-file using case-neutral search.

return true if section.key exist in ini-file.

◆ loadAllMessages()

list< pair< string, unordered_map< string, string > > > IniFileReader::loadAllMessages ( const char *  i_iniMsgPath,
const char *  i_codePageName = nullptr 
)
staticnoexcept

read language specific messages from path/to/theExe.message.ini for all languages

Parameters
[in]i_iniMsgPathpath to message ini-file, usually: path/to/theExe.message.ini

◆ strValue()

const string IniFileReader::strValue ( const char *  i_section,
const char *  i_key,
const string &  i_default = "" 
) const
noexcept

return string value by section and key using case-neutral search, or default value if not found.

return string value by section and .key using case-neutral search, or default value if not found.


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