Core Library 1.7.0.0 Library containing core utilities and tools for threading, networking, logging, INI and CSV file management etc.

Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
core_lib::ini_file::IniFile Class Referencefinal

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 &section) const
| Get section's key-value pairs. More...
bool | SectionExists (const std::string &section) const
| Check if a section exists. More...
bool | KeyExists (const std::string &section, const std::string &key) const
| Check if a key exists for a section. More...
bool | ReadBool (const std::string &section, const std::string &key, bool defaultValue=false) const
| Read boolean value. More...
int32_t | ReadInt32 (const std::string &section, const std::string &key, int32_t defaultValue=0) const
| Read 32 bit integer value. More...
int64_t | ReadInt64 (const std::string &section, const std::string &key, int64_t defaultValue=0L) const
| Read 64 bit integer value. More...
double | ReadDouble (const std::string &section, const std::string &key, double defaultValue=0.0) const
| Read double value. More...
long double | ReadLongDouble (const std::string &section, const std::string &key, long double defaultValue=0.0L) const
| Read long double value. More...
std::string | ReadString (const std::string &section, const std::string &key, const std::string &defaultValue="") const
| Read string value. More...
void | WriteBool (const std::string &section, const std::string &key, bool value)
| Write boolean value. More...
void | WriteInt32 (const std::string &section, const std::string &key, int32_t value)
| Write 32 bit integer value. More...
void | WriteInt64 (const std::string &section, const std::string &key, int64_t value)
| Write 64 bit integer value. More...
void | WriteDouble (const std::string &section, const std::string &key, double value)
| Write double value. More...
void | WriteLongDouble (const std::string &section, const std::string &key, long double value)
| Write long double value. More...
void | WriteString (const std::string &section, const std::string &key, const std::string &value)
| Write string value. More...
void | EraseSection (const std::string &section)
| Erase a whole section. More...
void | EraseSections ()
| Erase all the sections. More...
void | EraseKey (const std::string &section, const std::string &key)
| Erase a key within a section. More...
void | EraseKeys (const std::string &section)
| 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 &section, const std::string &key, const std::string &defaultValue) const
| Read value from INI file. More...
void | WriteValueString (const std::string &section, 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.

## Detailed Description

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.

## Constructor & Destructor Documentation

## ◆ IniFile()

core_lib::ini_file::IniFile::IniFile | ( | const std::string & | iniFilePath | ) |
| explicit

INI path based constructor.

Parameters

  [in] | iniFilePath | - Path to INI file.

Create an INI file object from an INI file path.

## Member Function Documentation

## ◆ EraseKey()

void core_lib::ini_file::IniFile::EraseKey | ( | const std::string & | section,
|  | const std::string & | key
| ) |  |

Erase a key within a section.

Parameters

  [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.

## ◆ EraseKeys()

void core_lib::ini_file::IniFile::EraseKeys | ( | const std::string & | section | ) |

Erase all keys in a section.

Parameters

  [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.

## ◆ EraseSection()

void core_lib::ini_file::IniFile::EraseSection | ( | const std::string & | section | ) |

Erase a whole section.

Parameters

  [in] | section | - Section name.

If calling this removes the last section then all comments and blank lines will also be removed.

## ◆ EraseSections()

void core_lib::ini_file::IniFile::EraseSections | ( |  | ) |

Erase all the sections.

This removes all comments and blank lines.

## ◆ GetSection()

keys_list core_lib::ini_file::IniFile::GetSection | ( | const std::string & | section | ) | const

Get section's key-value pairs.

Parameters

  [in] | section | - section Parameter_Description

Returns
  A list of key-value pairs for an INI file section.

## ◆ GetSections()

auto core_lib::ini_file::IniFile::GetSections | ( |  | ) | const

Get sections.

Returns
  A list of INI file section names.

## ◆ KeyExists()

bool core_lib::ini_file::IniFile::KeyExists | ( | const std::string & | section,
|  | const std::string & | key
| ) |  | const

Check if a key exists for a section.

Parameters

  [in] | section | - Section name.
  [in] | key | - Key name.

Returns
  True if key exists, false otherwise.

## ◆ LoadFile()

void core_lib::ini_file::IniFile::LoadFile | ( | const std::string & | iniFilePath | ) |

Load an INI file.

Parameters

  [in] | iniFilePath | - Path to an INI file.

Load from an INI file path.

## ◆ ReadBool()

bool core_lib::ini_file::IniFile::ReadBool | ( | const std::string & | section,
|  | const std::string & | key,
|  | bool | defaultValue = `false`
| ) |  | const

Read boolean value.

Parameters

  [in] | section | - Section name.
  [in] | key | - Key name.
  [in] | defaultValue | - Default value if key not found.

Returns
  Returns the value stored in the INI file.

## ◆ ReadDouble()

double core_lib::ini_file::IniFile::ReadDouble | ( | const std::string & | section,
|  | const std::string & | key,
|  | double | defaultValue = `0.0`
| ) |  | const

Read double value.

Parameters

  [in] | section | - Section name.
  [in] | key | - Key name.
  [in] | defaultValue | - Default value if key not found.

Returns
  Returns the value stored in the INI file.

## ◆ ReadInt32()

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.

Parameters

  [in] | section | - Section name.
  [in] | key | - Key name.
  [in] | defaultValue | - Default value if key not found.

Returns
  Returns the value stored in the INI file.

## ◆ ReadInt64()

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.

Parameters

  [in] | section | - Section name.
  [in] | key | - Key name.
  [in] | defaultValue | - Default value if key not found.

Returns
  Returns the value stored in the INI file.

## ◆ ReadLongDouble()

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.

Parameters

  [in] | section | - Section name.
  [in] | key | - Key name.
  [in] | defaultValue | - Default value if key not found.

Returns
  Returns the value stored in the INI file.

## ◆ ReadString()

std::string core_lib::ini_file::IniFile::ReadString | ( | const std::string & | section,
|  | const std::string & | key,
|  | const std::string & | defaultValue = `""`
| ) |  | const

Read string value.

Parameters

  [in] | section | - Section name.
  [in] | key | - Key name.
  [in] | defaultValue | - Default value if key not found.

Returns
  Returns the value stored in the INI file.

## ◆ ReadValueString()

std::string core_lib::ini_file::IniFile::ReadValueString | ( | const std::string & | section,
|  | const std::string & | key,
|  | const std::string & | defaultValue
| ) |  | const
| private

Read value from INI file.

Parameters

  [in] | section | - The section.
  [in] | key | - The key.
  [in] | defaultValue | - Default value if key not found as const reference.

Returns
  The value.

## ◆ SectionExists()

bool core_lib::ini_file::IniFile::SectionExists | ( | const std::string & | section | ) | const

Check if a section exists.

Parameters

  [in] | section | - Section name.

Returns
  True if section name exists, false otherwise.

## ◆ UpdateFile()

void core_lib::ini_file::IniFile::UpdateFile | ( | const std::string & | overridePath = `""` | ) | const

Update the file.

Parameters

  [in] | overridePath | - Optional override path to save to alternative location.

Write settings back to file on disk.

## ◆ WriteBool()

void core_lib::ini_file::IniFile::WriteBool | ( | const std::string & | section,
|  | const std::string & | key,
|  | bool | value
| ) |  |

Write boolean value.

Parameters

  [in] | section | - Section name.
  [in] | key | - Key name.
  [in] | value | - Value to write to file.

## ◆ WriteDouble()

void core_lib::ini_file::IniFile::WriteDouble | ( | const std::string & | section,
|  | const std::string & | key,
|  | double | value
| ) |  |

Write double value.

Parameters

  [in] | section | - Section name.
  [in] | key | - Key name.
  [in] | value | - Value to write to file.

## ◆ WriteInt32()

void core_lib::ini_file::IniFile::WriteInt32 | ( | const std::string & | section,
|  | const std::string & | key,
|  | int32_t | value
| ) |  |

Write 32 bit integer value.

Parameters

  [in] | section | - Section name.
  [in] | key | - Key name.
  [in] | value | - Value to write to file.

## ◆ WriteInt64()

void core_lib::ini_file::IniFile::WriteInt64 | ( | const std::string & | section,
|  | const std::string & | key,
|  | int64_t | value
| ) |  |

Write 64 bit integer value.

Parameters

  [in] | section | - Section name.
  [in] | key | - Key name.
  [in] | value | - Value to write to file.

## ◆ WriteLongDouble()

void core_lib::ini_file::IniFile::WriteLongDouble | ( | const std::string & | section,
|  | const std::string & | key,
|  | long double | value
| ) |  |

Write long double value.

Parameters

  [in] | section | - Section name.
  [in] | key | - Key name.
  [in] | value | - Value to write to file.

## ◆ WriteString()

void core_lib::ini_file::IniFile::WriteString | ( | const std::string & | section,
|  | const std::string & | key,
|  | const std::string & | value
| ) |  |

Write string value.

Parameters

  [in] | section | - Section name.
  [in] | key | - Key name.
  [in] | value | - Value to write to file.

## ◆ WriteValueString()

void core_lib::ini_file::IniFile::WriteValueString | ( | const std::string & | section,
|  | const std::string & | key,
|  | const std::string & | value
| ) |  |
| private

Write value to INI file.

Parameters

  [in] | section | - The section.
  [in] | key | - The key.
  [in] | value | - Value to write as const reference.

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

- D:/Projects/CoreLibrary/Include/IniFile/IniFile.h
- D:/Projects/CoreLibrary/Source/IniFile/IniFile.cpp