23 static IniFile read(
const std::string& iniFilePath);
30 explicit IniFile(
const std::string& iniFilePath);
32 void save(
const std::string& iniFilePath);
38 std::optional<std::size_t>
findSectionIndex(std::string_view sectionName)
const;
40 void setCurrentSection(std::string_view sectionName,
bool createIfNotExist =
true);
45 std::optional<std::size_t>
findPropertyIndex(std::string_view propertyName)
const;
49 void setProperty(std::size_t propertyIdx, std::string_view propertyValue);
54 std::string_view propertyName,
55 std::string_view propertyValue,
56 bool createIfNotExist =
true);
66 struct IniSection final
69 std::vector<std::pair<std::string, std::string>> keyValPairs;
72 IniSection& getIniSection(std::size_t sectionIdx);
73 const IniSection& getIniSection(std::size_t sectionIdx)
const;
75 std::vector<IniSection> m_sections;
76 std::size_t m_currentSectionIdx;
83 return m_sections.size();
88 return getIniSection(m_currentSectionIdx).keyValPairs.size();
93 return getIniSection(sectionIdx).name;
98 return getIniSection(m_currentSectionIdx).name;
105 m_currentSectionIdx = sectionIdx;
110 const IniSection& section = getIniSection(m_currentSectionIdx);
113 return section.keyValPairs[propertyIdx].first;
118 const IniSection& section = getIniSection(m_currentSectionIdx);
121 return section.keyValPairs[propertyIdx].second;
126 IniSection& section = getIniSection(m_currentSectionIdx);
129 section.keyValPairs[propertyIdx].second = propertyValue;
132inline IniFile::IniSection& IniFile::getIniSection(
const std::size_t sectionIdx)
136 return m_sections[sectionIdx];
139inline const IniFile::IniSection& IniFile::getIniSection(
const std::size_t sectionIdx)
const
143 return m_sections[sectionIdx];
#define PH_ASSERT_LT(a, b)
Definition assertion.h:64
INI file I/O. This class is useful for recording various settings across the entire engine project....
Definition IniFile.h:21
std::optional< std::size_t > findSectionIndex(std::string_view sectionName) const
Definition IniFile.cpp:77
std::string_view getPropertyValue(std::size_t propertyIdx) const
Definition IniFile.h:116
void setCurrentSection(std::size_t sectionIdx)
Definition IniFile.h:101
std::string_view getCurrentSectionName() const
Definition IniFile.h:96
std::size_t numSections() const
Definition IniFile.h:81
std::optional< std::size_t > findPropertyIndex(std::string_view propertyName) const
Definition IniFile.cpp:90
std::string_view getPropertyName(std::size_t propertyIdx) const
Definition IniFile.h:108
std::string_view getSectionName(std::size_t sectionIdx) const
Definition IniFile.h:91
void clear()
Definition IniFile.h:146
IniFile()
Creates a file with no content. An empty section is made current.
Definition IniFile.cpp:10
void append(const IniFile &other)
Add another INI file to this one. All properties from the other file will be added to this one....
Definition IniFile.cpp:129
void save(const std::string &iniFilePath)
Definition IniFile.cpp:25
std::size_t numProperties() const
Definition IniFile.h:86
void setProperty(std::size_t propertyIdx, std::string_view propertyValue)
Set a property under current section by index.
Definition IniFile.h:124
static IniFile read(const std::string &iniFilePath)
Definition IniFile.cpp:142
The root for all renderer implementations.
Definition assertion.h:9