1#ifndef IOUTILITIES_INIFILE_H
2#define IOUTILITIES_INIFILE_H
19 using ScopeData = std::multimap<std::string, std::string>;
20 using Scope = std::pair<ScopeName, ScopeData>;
26 void parse(std::istream &inputStream);
27 void make(std::ostream &outputStream);
85 std::size_t paddedKeyLength = 0;
90 FieldList::iterator findField(std::string_view key);
91 FieldList::const_iterator findField(std::string_view key)
const;
92 FieldList::iterator findField(FieldList::iterator after, std::string_view key);
93 FieldList::const_iterator findField(FieldList::iterator after, std::string_view key)
const;
94 FieldList::iterator fieldEnd();
95 FieldList::const_iterator fieldEnd()
const;
105 SectionList::iterator findSection(std::string_view sectionName);
106 SectionList::const_iterator findSection(std::string_view sectionName)
const;
107 SectionList::iterator findSection(SectionList::iterator after, std::string_view sectionName);
108 SectionList::const_iterator findSection(SectionList::iterator after, std::string_view sectionName)
const;
109 SectionList::iterator sectionEnd();
110 SectionList::const_iterator sectionEnd()
const;
111 std::optional<FieldList::iterator> findField(std::string_view sectionName, std::string_view key);
112 std::optional<FieldList::const_iterator> findField(std::string_view sectionName, std::string_view key)
const;
113 void parse(std::istream &inputStream,
IniFileParseOptions options = IniFileParseOptions::None);
114 void make(std::ostream &outputStream,
IniFileMakeOptions options = IniFileMakeOptions::None);
124 return std::find_if(
sections.begin(),
sections.end(), [§ionName](
const auto &scope) { return scope.name == sectionName; });
140 return std::find_if(after + 1,
sections.end(), [§ionName](
const auto &scope) { return scope.name == sectionName; });
172 const SectionList::iterator scope =
findSection(sectionName);
176 const FieldList::iterator field = scope->findField(key);
177 if (field == scope->fieldEnd()) {
186inline std::optional<AdvancedIniFile::FieldList::const_iterator>
AdvancedIniFile::findField(std::string_view sectionName, std::string_view key)
const
196 return std::find_if(
fields.begin(),
fields.end(), [&key](
const auto &field) { return field.key == key; });
212 return std::find_if(after + 1, fields.end(), [&key](
const auto &field) { return field.key == key; });
The IniFile class allows parsing and writing INI files.
std::multimap< std::string, std::string > ScopeData
IniFile()
Constructs an empty ini file.
ScopeList & data()
Returns the data of the file.
std::pair< ScopeName, ScopeData > Scope
std::vector< Scope > ScopeList
#define CPP_UTILITIES_MARK_FLAG_ENUM_CLASS(Namespace, EnumClassType)
#define CPP_UTILITIES_EXPORT
Marks the symbol to be exported by the c++utilities library.
Contains all utilities provides by the c++utilities library.
The AdvancedIniFile::Field class represents a field within an INI file.
std::string precedingCommentBlock
std::string followingInlineComment
The AdvancedIniFile::Section class represents a section within an INI file.
FieldList::iterator findField(std::string_view key)
Returns an iterator to the first field with the key key.
FieldList::iterator fieldEnd()
Returns an iterator that points one past the last field.
std::string followingInlineComment
std::string precedingCommentBlock
The AdvancedIniFile class allows parsing and writing INI files.
std::optional< FieldList::iterator > findField(std::string_view sectionName, std::string_view key)
Returns an iterator to the first field within the first section with matching sectionName and key.
SectionList::iterator sectionEnd()
Returns an iterator that points one past the last section.
std::vector< Section > SectionList
std::vector< Field > FieldList
SectionList::iterator findSection(std::string_view sectionName)
Returns an iterator to the first section with the name sectionName.