|
Core Library
1.7.0.0
Library containing core utilities and tools for threading, networking, logging, INI and CSV file management etc.
|
Ini file class. More...
#include <IniFile.h>
Public Member Functions | |
| IniFile ()=default | |
| Default constructor. | |
| IniFile (const IniFile &)=default | |
| Copy constructor. | |
| IniFile (const std::string &iniFilePath) | |
| INI path based constructor. More... | |
| ~IniFile ()=default | |
| Destructor. | |
| IniFile & | operator= (const IniFile &)=default |
| Copy assignment operator. | |
| IniFile (IniFile &&)=default | |
| Move constructor. | |
| IniFile & | operator= (IniFile &&)=default |
| Move assignment operator. | |
| void | LoadFile (const std::string &iniFilePath) |
| Load an INI file. More... | |
| void | UpdateFile (const std::string &overridePath="") const |
| Update the file. More... | |
| std::list< std::string > | GetSections () const |
| Get sections. More... | |
| keys_list | GetSection (const std::string §ion) const |
| Get section's key-value pairs. More... | |
| bool | SectionExists (const std::string §ion) const |
| Check if a section exists. More... | |
| bool | KeyExists (const std::string §ion, const std::string &key) const |
| Check if a key exists for a section. More... | |
| bool | ReadBool (const std::string §ion, const std::string &key, bool defaultValue=false) const |
| Read boolean value. More... | |
| int32_t | ReadInt32 (const std::string §ion, const std::string &key, int32_t defaultValue=0) const |
| Read 32 bit integer value. More... | |
| int64_t | ReadInt64 (const std::string §ion, const std::string &key, int64_t defaultValue=0L) const |
| Read 64 bit integer value. More... | |
| double | ReadDouble (const std::string §ion, const std::string &key, double defaultValue=0.0) const |
| Read double value. More... | |
| long double | ReadLongDouble (const std::string §ion, const std::string &key, long double defaultValue=0.0L) const |
| Read long double value. More... | |
| std::string | ReadString (const std::string §ion, const std::string &key, const std::string &defaultValue="") const |
| Read string value. More... | |
| void | WriteBool (const std::string §ion, const std::string &key, bool value) |
| Write boolean value. More... | |
| void | WriteInt32 (const std::string §ion, const std::string &key, int32_t value) |
| Write 32 bit integer value. More... | |
| void | WriteInt64 (const std::string §ion, const std::string &key, int64_t value) |
| Write 64 bit integer value. More... | |
| void | WriteDouble (const std::string §ion, const std::string &key, double value) |
| Write double value. More... | |
| void | WriteLongDouble (const std::string §ion, const std::string &key, long double value) |
| Write long double value. More... | |
| void | WriteString (const std::string §ion, const std::string &key, const std::string &value) |
| Write string value. More... | |
| void | EraseSection (const std::string §ion) |
| Erase a whole section. More... | |
| void | EraseSections () |
| Erase all the sections. More... | |
| void | EraseKey (const std::string §ion, const std::string &key) |
| Erase a key within a section. More... | |
| void | EraseKeys (const std::string §ion) |
| Erase all keys in a section. More... | |
Private Types | |
| using | section_map = std::map< std::string, if_private::SectionDetails > |
| Section map typedef. | |
| using | section_iter = section_map::iterator |
| Section map iterator typedef. | |
| using | section_citer = section_map::const_iterator |
| Section map const iterator typedef. | |
Private Member Functions | |
| std::string | ReadValueString (const std::string §ion, const std::string &key, const std::string &defaultValue) const |
| Read value from INI file. More... | |
| void | WriteValueString (const std::string §ion, const std::string &key, const std::string &value) |
| Write value to INI file. More... | |
Private Attributes | |
| bool | m_changesMade {false} |
| Changes made flag. | |
| std::string | m_iniFilePath {"config.ini"} |
| INI file path. | |
| section_map | m_sectionMap |
| Sectin map. | |
| if_private::line_list | m_lines |
| Line list. | |
Ini file class.
Here is an example of what an INI file could look like:
; I am an opening comment. [Section1] ; I am a comment in a section. Section1_Key1=Section1_Value1 Section1_Key2=Section1_Value2 Section1_Key3 = Section1_Value3 [Section2] Section2_Key1=Section2_Value1 Section2_Key2 = Section2_Value2 ; I am also a comment in a section. Section2_Key3=Section2_Value3 ; I am yet another comment in a section.
Please note that the supported comment delimiter is ';'. Also note that comments are preserved when loading an ini file. However, unnecessary whitespace in sections, key or value items is removed.
Only flat heirarchy INI files are supported; nested sections are not supported.
|
explicit |
INI path based constructor.
| [in] | iniFilePath | - Path to INI file. |
Create an INI file object from an INI file path.
| void core_lib::ini_file::IniFile::EraseKey | ( | const std::string & | section, |
| const std::string & | key | ||
| ) |
Erase a key within a section.
| [in] | section | - Section name. |
| [in] | key | - Section name. |
If section has no keys left after calling this functoin the section will also be removed. If removing the section removes the final section then all remaining comments and blank lines are also removed.
| void core_lib::ini_file::IniFile::EraseKeys | ( | const std::string & | section | ) |
Erase all keys in a section.
| [in] | section | - Section name. |
The section will also be removed. If removing the section removes the final section then all remaining comments and blank lines are also removed.
| void core_lib::ini_file::IniFile::EraseSection | ( | const std::string & | section | ) |
Erase a whole section.
| [in] | section | - Section name. |
If calling this removes the last section then all comments and blank lines will also be removed.
| void core_lib::ini_file::IniFile::EraseSections | ( | ) |
Erase all the sections.
This removes all comments and blank lines.
| keys_list core_lib::ini_file::IniFile::GetSection | ( | const std::string & | section | ) | const |
Get section's key-value pairs.
| [in] | section | - section Parameter_Description |
| auto core_lib::ini_file::IniFile::GetSections | ( | ) | const |
Get sections.
| bool core_lib::ini_file::IniFile::KeyExists | ( | const std::string & | section, |
| const std::string & | key | ||
| ) | const |
Check if a key exists for a section.
| [in] | section | - Section name. |
| [in] | key | - Key name. |
| void core_lib::ini_file::IniFile::LoadFile | ( | const std::string & | iniFilePath | ) |
Load an INI file.
| [in] | iniFilePath | - Path to an INI file. |
Load from an INI file path.
| bool core_lib::ini_file::IniFile::ReadBool | ( | const std::string & | section, |
| const std::string & | key, | ||
| bool | defaultValue = false |
||
| ) | const |
Read boolean value.
| [in] | section | - Section name. |
| [in] | key | - Key name. |
| [in] | defaultValue | - Default value if key not found. |
| double core_lib::ini_file::IniFile::ReadDouble | ( | const std::string & | section, |
| const std::string & | key, | ||
| double | defaultValue = 0.0 |
||
| ) | const |
Read double value.
| [in] | section | - Section name. |
| [in] | key | - Key name. |
| [in] | defaultValue | - Default value if key not found. |
| int32_t core_lib::ini_file::IniFile::ReadInt32 | ( | const std::string & | section, |
| const std::string & | key, | ||
| int32_t | defaultValue = 0 |
||
| ) | const |
Read 32 bit integer value.
| [in] | section | - Section name. |
| [in] | key | - Key name. |
| [in] | defaultValue | - Default value if key not found. |
| int64_t core_lib::ini_file::IniFile::ReadInt64 | ( | const std::string & | section, |
| const std::string & | key, | ||
| int64_t | defaultValue = 0L |
||
| ) | const |
Read 64 bit integer value.
| [in] | section | - Section name. |
| [in] | key | - Key name. |
| [in] | defaultValue | - Default value if key not found. |
| long double core_lib::ini_file::IniFile::ReadLongDouble | ( | const std::string & | section, |
| const std::string & | key, | ||
| long double | defaultValue = 0.0L |
||
| ) | const |
Read long double value.
| [in] | section | - Section name. |
| [in] | key | - Key name. |
| [in] | defaultValue | - Default value if key not found. |
| std::string core_lib::ini_file::IniFile::ReadString | ( | const std::string & | section, |
| const std::string & | key, | ||
| const std::string & | defaultValue = "" |
||
| ) | const |
Read string value.
| [in] | section | - Section name. |
| [in] | key | - Key name. |
| [in] | defaultValue | - Default value if key not found. |
|
private |
Read value from INI file.
| [in] | section | - The section. |
| [in] | key | - The key. |
| [in] | defaultValue | - Default value if key not found as const reference. |
| bool core_lib::ini_file::IniFile::SectionExists | ( | const std::string & | section | ) | const |
Check if a section exists.
| [in] | section | - Section name. |
| void core_lib::ini_file::IniFile::UpdateFile | ( | const std::string & | overridePath = "" | ) | const |
Update the file.
| [in] | overridePath | - Optional override path to save to alternative location. |
Write settings back to file on disk.
| void core_lib::ini_file::IniFile::WriteBool | ( | const std::string & | section, |
| const std::string & | key, | ||
| bool | value | ||
| ) |
Write boolean value.
| [in] | section | - Section name. |
| [in] | key | - Key name. |
| [in] | value | - Value to write to file. |
| void core_lib::ini_file::IniFile::WriteDouble | ( | const std::string & | section, |
| const std::string & | key, | ||
| double | value | ||
| ) |
Write double value.
| [in] | section | - Section name. |
| [in] | key | - Key name. |
| [in] | value | - Value to write to file. |
| void core_lib::ini_file::IniFile::WriteInt32 | ( | const std::string & | section, |
| const std::string & | key, | ||
| int32_t | value | ||
| ) |
Write 32 bit integer value.
| [in] | section | - Section name. |
| [in] | key | - Key name. |
| [in] | value | - Value to write to file. |
| void core_lib::ini_file::IniFile::WriteInt64 | ( | const std::string & | section, |
| const std::string & | key, | ||
| int64_t | value | ||
| ) |
Write 64 bit integer value.
| [in] | section | - Section name. |
| [in] | key | - Key name. |
| [in] | value | - Value to write to file. |
| void core_lib::ini_file::IniFile::WriteLongDouble | ( | const std::string & | section, |
| const std::string & | key, | ||
| long double | value | ||
| ) |
Write long double value.
| [in] | section | - Section name. |
| [in] | key | - Key name. |
| [in] | value | - Value to write to file. |
| void core_lib::ini_file::IniFile::WriteString | ( | const std::string & | section, |
| const std::string & | key, | ||
| const std::string & | value | ||
| ) |
Write string value.
| [in] | section | - Section name. |
| [in] | key | - Key name. |
| [in] | value | - Value to write to file. |
|
private |
Write value to INI file.
| [in] | section | - The section. |
| [in] | key | - The key. |
| [in] | value | - Value to write as const reference. |