Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
Antares::IniFile::Section Class Referencefinal

A single section, with all its keys. More...

#include <inifile.h>

Public Member Functions

 Section (const AnyString &name)
 
template<class U >
Propertyadd (const AnyString &key, const U &value)
 Add a new property.
 
template<class U >
Propertyadd (const AnyString &key, const std::optional< U > &value)
 
void add (const Property &property)
 
void saveToStream (std::ostream &file, uint64_t &written) const
 
Propertyfind (const AnyString &key)
 
const Propertyfind (const AnyString &key) const
 
template<class U , class StringT >
read (const StringT &key, const U &defValue) const
 Try to read a property.
 
template<class CallbackT >
void each (const CallbackT &callback)
 Iterate through all properties.
 
template<class CallbackT >
void each (const CallbackT &callback) const
 Iterate through all properties (const)
 
bool empty () const
 Get if the section is empty.
 
uint size () const
 Get the number of properties.
 
template<class U >
IniFile::Propertyadd (const AnyString &key, const U &value)
 
template<class U >
IniFile::Propertyadd (const AnyString &key, const std::optional< U > &value)
 

Public Attributes

Yuni::ShortString256 name
 The name of the section.
 
IniFile::PropertyfirstProperty = nullptr
 The first property of the section.
 
IniFile::PropertylastProperty = nullptr
 The last property of the section.
 
Sectionnext = nullptr
 The next section.
 

Detailed Description

A single section, with all its keys.

Member Function Documentation

◆ each() [1/2]

template<class CallbackT >
void Antares::IniFile::Section::each ( const CallbackT & callback)

Iterate through all properties.

IniFile ini;
if (ini.open("/tmp/test.ini"))
{
ini.each([&] (const IniFile::Section& section)
{
std::cout << '[' << section.name << "]\n";
section.properties([&] (const IniFile::Property& property)
{
std::cout << property.key << " = " << property.value << '\n';
});
std::cout << '\n';
});
}
A single entry in an INI file.
Definition inifile.h:43
A single section, with all its keys.
Definition inifile.h:67
Yuni::ShortString256 name
The name of the section.
Definition inifile.h:152
Data for an INI file.
Definition inifile.h:34
void each(const CallbackT &callback)
Iterate through all sections.
Definition inifile.hxx:99
bool open(const std::string &filename, bool warnings=true)
Load an INI file.
Definition inifile.cpp:238

◆ each() [2/2]

template<class CallbackT >
void Antares::IniFile::Section::each ( const CallbackT & callback) const

Iterate through all properties (const)

IniFile ini;
if (ini.open("/tmp/test.ini"))
{
ini.each([&] (const IniFile::Section& section)
{
std::cout << '[' << section.name << "]\n";
section.properties([&] (const IniFile::Property& property)
{
std::cout << property.key << " = " << property.value << '\n';
});
std::cout << '\n';
});
}

◆ read()

template<class U , class StringT >
U Antares::IniFile::Section::read ( const StringT & key,
const U & defValue ) const
inline

Try to read a property.

If the property can not be found, the default value will be used.

Parameters
keyThe property name
defValueThe default value
Returns
The associated value

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