TSDuck v3.38-3699
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::DuckConfigFile Class Reference

A singleton which contains the TSDuck configuration file. More...

#include <tsDuckConfigFile.h>

Inheritance diagram for ts::DuckConfigFile:
Collaboration diagram for ts::DuckConfigFile:

Public Types

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

Public Member Functions

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.
 
void getValues (const UString &entry, UStringVector &values) const
 Get all values of an entry.
 
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.
 
ConfigSectionoperator[] (const UString &name)
 Index operator: get a reference to a section inside the configuration file instance.
 
const ConfigSectionoperator[] (const UString &name) const
 Index operator: get a reference to a section inside the configuration file instance.
 
void reset ()
 Reset the content of the configuration.
 
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.
 
ConfigSectionsection (const UString &name)
 Get a reference to a section inside the configuration file instance.
 
const ConfigSectionsection (const UString &name) const
 Get a reference to a section inside the configuration file instance.
 
size_t sectionCount () const
 Get the number of sections in the file.
 
UString value (const UString &entry, const UString &defvalue=UString()) const
 Get the value of an entry.
 

Static Public Member Functions

static fs::path DefaultFileName (FileStyle style=LOCAL_SYSTEM, const UString &app_name=UString())
 Get the default configuration file name.
 
static DuckConfigFileInstance ()
 Get the instance of the singleton of this class.
 

Detailed Description

A singleton which contains the TSDuck configuration file.

Member Enumeration Documentation

◆ FileStyle

enum ts::ConfigFile::FileStyle
inherited

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

Member Function Documentation

◆ Instance()

static DuckConfigFile & ts::DuckConfigFile::Instance ( )
inlinestatic

Get the instance of the singleton of this class.

Returns
The instance of the singleton of this class.

◆ value()

UString ts::DuckConfigFile::value ( const UString entry,
const UString defvalue = UString() 
) const

Get the value of an entry.

A section with the name of the executable is searched first. Then, the global section is used.

Parameters
[in]entryEntry name.
[in]defvalueDefault value.
Returns
The value in the entry or defvalue if entry does not exist.

◆ getValues()

void ts::DuckConfigFile::getValues ( const UString entry,
UStringVector values 
) const

Get all values of an entry.

A section with the name of the executable is searched first. Then, the global section is used.

Parameters
[in]entryEntry name.
[out]valuesVector of values.

◆ DefaultFileName()

static fs::path ts::ConfigFile::DefaultFileName ( FileStyle  style = LOCAL_SYSTEM,
const UString app_name = UString() 
)
staticinherited

Get the default configuration file name.

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

◆ fileName()

fs::path ts::ConfigFile::fileName ( ) const
inlineinherited

Get the latest loaded file.

Returns
The name of the latest loaded file.

◆ load()

bool ts::ConfigFile::load ( const fs::path &  filename,
Report report = (ts::CerrReport::Instance()) 
)
inherited

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 fs::path &  filename,
Report report = (ts::CerrReport::Instance()) 
)
inherited

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)
inherited

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 fs::path &  filename = UString(),
Report report = (ts::CerrReport::Instance()) 
) const
inherited

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
inherited

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
inlineinherited

Get the number of sections in the file.

Returns
The number of sections in the file.

◆ getSectionNames()

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

Get the names of all sections.

Parameters
[out]namesReturned names of all sections.

◆ section() [1/2]

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

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
inherited

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[]() [1/2]

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

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.

◆ operator[]() [2/2]

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

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)
inlineinherited

Delete a section.

Parameters
[in]nameThe section name to delete.

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