![]() |
TSDuck v3.43-4480
MPEG Transport Stream Toolkit
|
Representation of a configuration file. More...
#include <tsConfigFile.h>

Public Types | |
| enum | FileStyle { LOCAL_SYSTEM , UNIX_STYLE , WINDOWS_STYLE } |
| System-specific style of default configuration file name. More... | |
Public Member Functions | |
| ConfigFile (const fs::path &filename1, const fs::path &filename2, Report &report=(ts::CerrReport::Instance()), const UString &env_disable=UString()) | |
| Constructor. | |
| ConfigFile (const fs::path &filename=fs::path(), Report &report=(ts::CerrReport::Instance()), const UString &env_disable=UString()) | |
| Constructor. | |
| ConfigFile (std::istream &strm) | |
| Constructor. | |
| void | clear () |
| Clear the content of the configuration. | |
| void | deleteSection (const UString &name) |
| Delete a section. | |
| fs::path | fileName () const |
| Get the latest loaded file. | |
| void | getSectionNames (UStringVector &names) const |
| Get the names of all sections. | |
| bool | hasSection (const UString &name) const |
| Check if a section exists. | |
| bool | isLoaded () const |
| Check if the last load operation succeeded (including in the constructor). | |
| bool | load (const fs::path &filename, Report &report=(ts::CerrReport::Instance())) |
| Reload the configuration from a file. | |
| bool | merge (const fs::path &filename, Report &report=(ts::CerrReport::Instance())) |
| Merge the configuration from a file. | |
| void | merge (std::istream &strm) |
| Merge the configuration from a file. | |
| ConfigSection & | operator[] (const UString &name) |
| Index operator: get a reference to a section inside the configuration file instance. | |
| const ConfigSection & | operator[] (const UString &name) const |
| Index operator: get a reference to a section inside the configuration file instance. | |
| bool | save (const fs::path &filename=UString(), Report &report=(ts::CerrReport::Instance())) const |
| Save a configuration file. | |
| std::ostream & | save (std::ostream &strm) const |
| Save a configuration file in a stream. | |
| ConfigSection & | section (const UString &name) |
| Get a reference to a section inside the configuration file instance. | |
| const ConfigSection & | section (const UString &name) const |
| Get a reference to a section inside the configuration file instance. | |
| size_t | size () const |
| Get the number of sections in the file. | |
Static Public Member Functions | |
| static fs::path | DefaultFileName (FileStyle style=LOCAL_SYSTEM, const UString &app_name=UString()) |
| Get the default configuration file name. | |
Representation of a configuration file.
Configuration files are based on the old ".INI" syntax on Windows systems. Lines starting with a '#' are comments and are ignored. The same entry can be specified several times in the same sections, all values are kept in a list.
|
explicit |
Constructor.
| [in] | filename | A file name to read. Don't read a file if empty. |
| [in,out] | report | Where to report errors. |
| [in] | env_disable | Optional name of an environment variable. When the corresponding environment variable is defined to some non-empty value, the file is not loaded. |
| ts::ConfigFile::ConfigFile | ( | const fs::path & | filename1, |
| const fs::path & | filename2, | ||
| Report & | report = (ts::CerrReport::Instance()), |
||
| const UString & | env_disable = UString() |
||
| ) |
Constructor.
| [in] | filename1 | A file name to read. Don't read a file if empty. |
| [in] | filename2 | A file name to read if filename1 does not exist. Don't read a file if empty. |
| [in,out] | report | Where to report errors. |
| [in] | env_disable | Optional name of an environment variable. When the corresponding environment variable is defined to some non-empty value, the file is not loaded. |
|
explicit |
Constructor.
| [in,out] | strm | Opened input text stream to read the configuration file. |
|
static |
Get the default configuration file name.
| [in] | style | System style for file name. |
| [in] | app_name | Application name (default: executable base name). |
|
inline |
Get the latest loaded file.
|
inline |
Check if the last load operation succeeded (including in the constructor).
| bool ts::ConfigFile::load | ( | const fs::path & | filename, |
| Report & | report = (ts::CerrReport::Instance()) |
||
| ) |
Reload the configuration from a file.
| [in] | filename | A file name to read. |
| [in,out] | report | Where to report errors. |
| bool ts::ConfigFile::merge | ( | const fs::path & | filename, |
| Report & | report = (ts::CerrReport::Instance()) |
||
| ) |
Merge the configuration from a file.
The values which are read from the specified file override previous values.
| [in] | filename | A file name to read. |
| [in,out] | report | Where to report errors. |
| void ts::ConfigFile::merge | ( | std::istream & | strm | ) |
Merge the configuration from a file.
The values which are read from the specified file override previous values.
| [in,out] | strm | Opened input text stream to read the configuration file. |
| bool ts::ConfigFile::save | ( | const fs::path & | filename = UString(), |
| Report & | report = (ts::CerrReport::Instance()) |
||
| ) | const |
| std::ostream & ts::ConfigFile::save | ( | std::ostream & | strm | ) | const |
Save a configuration file in a stream.
| [in,out] | strm | Opened output text stream to write the configuration file. |
|
inline |
Get the number of sections in the file.
|
inline |
Check if a section exists.
| [in] | name | The section name. |
| void ts::ConfigFile::getSectionNames | ( | UStringVector & | names | ) | const |
Get the names of all sections.
| [out] | names | Returned names of all sections. |
|
inline |
Get a reference to a section inside the configuration file instance.
Create the section if it does not exist.
| [in] | name | The section name. |
|
inline |
Index operator: get a reference to a section inside the configuration file instance.
Create the section if it does not exist.
| [in] | name | The section name. |
| const ConfigSection & ts::ConfigFile::section | ( | const UString & | name | ) | const |
Get a reference to a section inside the configuration file instance.
| [in] | name | The section name. |
|
inline |
Index operator: get a reference to a section inside the configuration file instance.
| [in] | name | The section name. |
|
inline |
Delete a section.
| [in] | name | The section name to delete. |