TSDuck Version 3.32-2820 (TSDuck - The MPEG Transport Stream Toolkit)
ts::ConfigFile Class Reference

Representation of a configuration file. More...

Inheritance diagram for ts::ConfigFile:

Public Types

enum  FileStyle {
  LOCAL_SYSTEM ,
  UNIX_STYLE ,
  WINDOWS_STYLE
}
 System-specific style of default configuration file name. More...
 

Public Member Functions

 ConfigFile (const UString &filename1, const UString &filename2, Report &report=(*(static_cast< ts::Report * >(ts::CerrReport::Instance()))), const UString env_disable=UString())
 Constructor. More...
 
 ConfigFile (const UString &filename=UString(), Report &report=(*(static_cast< ts::Report * >(ts::CerrReport::Instance()))), const UString env_disable=UString())
 Constructor. More...
 
 ConfigFile (std::istream &strm)
 Constructor. More...
 
void deleteSection (const UString &name)
 Delete a section. More...
 
UString fileName () const
 Get the latest loaded file. More...
 
void getSectionNames (UStringVector &names) const
 Get the names of all sections. More...
 
bool load (const UString &filename, Report &report=(*(static_cast< ts::Report * >(ts::CerrReport::Instance()))))
 Reload the configuration from a file. More...
 
bool merge (const UString &filename, Report &report=(*(static_cast< ts::Report * >(ts::CerrReport::Instance()))))
 Merge the configuration from a file. More...
 
void merge (std::istream &strm)
 Merge the configuration from a file. More...
 
ConfigSectionoperator[] (const UString &name)
 Index operator: get a reference to a section inside the configuration file instance. More...
 
const ConfigSectionoperator[] (const UString &name) const
 Index operator: get a reference to a section inside the configuration file instance. More...
 
void reset ()
 Reset the content of the configuration.
 
bool save (const UString &filename=UString(), Report &report=(*(static_cast< ts::Report * >(ts::CerrReport::Instance())))) const
 Save a configuration file. More...
 
std::ostream & save (std::ostream &strm) const
 Save a configuration file in a stream. More...
 
ConfigSectionsection (const UString &name)
 Get a reference to a section inside the configuration file instance. More...
 
const ConfigSectionsection (const UString &name) const
 Get a reference to a section inside the configuration file instance. More...
 
size_t sectionCount () const
 Get the number of sections in the file. More...
 

Static Public Member Functions

static UString DefaultFileName (FileStyle style=LOCAL_SYSTEM, const UString &name=UString())
 Get the default configuration file name. More...
 

Detailed Description

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.

Member Enumeration Documentation

◆ FileStyle

System-specific style of default configuration file name.

Enumerator
LOCAL_SYSTEM 

Same as local operating system.

UNIX_STYLE 

$HOME/.appname

WINDOWS_STYLE 

appname.ini in same directory as executable

Constructor & Destructor Documentation

◆ ConfigFile() [1/3]

ts::ConfigFile::ConfigFile ( const UString filename = UString(),
Report report = (*(static_cast< ts::Report * >(ts::CerrReport::Instance()))),
const UString  env_disable = UString() 
)
explicit

Constructor.

Parameters
[in]filenameA file name to read. Don't read a file if empty.
[in,out]reportWhere to report errors.
[in]env_disableOptional name of an environment variable. When the corresponding environment variable is defined to some non-empty value, the file is not loaded.

◆ ConfigFile() [2/3]

ts::ConfigFile::ConfigFile ( const UString filename1,
const UString filename2,
Report report = (*(static_cast< ts::Report * >(ts::CerrReport::Instance()))),
const UString  env_disable = UString() 
)

Constructor.

Parameters
[in]filename1A file name to read. Don't read a file if empty.
[in]filename2A file name to read if filename1 does not exist. Don't read a file if empty.
[in,out]reportWhere to report errors.
[in]env_disableOptional name of an environment variable. When the corresponding environment variable is defined to some non-empty value, the file is not loaded.

◆ ConfigFile() [3/3]

ts::ConfigFile::ConfigFile ( std::istream &  strm)
explicit

Constructor.

Parameters
[in,out]strmOpened input text stream to read the configuration file.

Member Function Documentation

◆ DefaultFileName()

static UString ts::ConfigFile::DefaultFileName ( FileStyle  style = LOCAL_SYSTEM,
const UString name = UString() 
)
static

Get the default configuration file name.

Parameters
[in]styleSystem style for file name.
[in]nameApplication name (default: executable base name).
Returns
The default configuration file name for the application.

◆ fileName()

UString ts::ConfigFile::fileName ( ) const
inline

Get the latest loaded file.

Returns
The name of the latest loaded file.

◆ load()

bool ts::ConfigFile::load ( const UString filename,
Report report = (*(static_cast< ts::Report * >(ts::CerrReport::Instance()))) 
)

Reload the configuration from a file.

Parameters
[in]filenameA file name to read.
[in,out]reportWhere to report errors.
Returns
True on success, false on error.

◆ merge() [1/2]

bool ts::ConfigFile::merge ( const UString filename,
Report report = (*(static_cast< ts::Report * >(ts::CerrReport::Instance()))) 
)

Merge the configuration from a file.

The values which are read from the specified file override previous values.

Parameters
[in]filenameA file name to read.
[in,out]reportWhere to report errors.
Returns
True on success, false on error.

◆ merge() [2/2]

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.

Parameters
[in,out]strmOpened input text stream to read the configuration file.

◆ save() [1/2]

bool ts::ConfigFile::save ( const UString filename = UString(),
Report report = (*(static_cast< ts::Report * >(ts::CerrReport::Instance()))) 
) const

Save a configuration file.

Parameters
[in]filenameA file name to write. If no file name is specified, use the file name from constructor or last load() or merge().
[in,out]reportWhere to report errors.
Returns
True on success, false on error.

◆ save() [2/2]

std::ostream& ts::ConfigFile::save ( std::ostream &  strm) const

Save a configuration file in a stream.

Parameters
[in,out]strmOpened output text stream to write the configuration file.
Returns
A reference to strm.

◆ sectionCount()

size_t ts::ConfigFile::sectionCount ( ) const
inline

Get the number of sections in the file.

Returns
The number of sections in the file.

◆ getSectionNames()

void ts::ConfigFile::getSectionNames ( UStringVector names) const

Get the names of all sections.

Parameters
[out]namesReturned names of all sections.

◆ section() [1/2]

ConfigSection& ts::ConfigFile::section ( const UString name)
inline

Get a reference to a section inside the configuration file instance.

Create the section if it does not exist.

Parameters
[in]nameThe section name.
Returns
A reference to the section.

◆ operator[]() [1/2]

ConfigSection& ts::ConfigFile::operator[] ( const UString name)
inline

Index operator: get a reference to a section inside the configuration file instance.

Create the section if it does not exist.

Parameters
[in]nameThe section name.
Returns
A reference to the section.

◆ section() [2/2]

const ConfigSection& ts::ConfigFile::section ( const UString name) const

Get a reference to a section inside the configuration file instance.

Create the section if it does not exist.

Parameters
[in]nameThe section name.
Returns
A read-only reference to the section.

◆ operator[]() [2/2]

const ConfigSection& ts::ConfigFile::operator[] ( const UString name) const
inline

Index operator: get a reference to a section inside the configuration file instance.

Create the section if it does not exist.

Parameters
[in]nameThe section name.
Returns
A read-only reference to the section.

◆ deleteSection()

void ts::ConfigFile::deleteSection ( const UString name)
inline

Delete a section.

Parameters
[in]nameThe section name to delete.

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