TSDuck v3.40-4163
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
Environment variables

System environment variables features. More...

Collaboration diagram for Environment variables:

Typedefs

using ts::Environment = std::map< UString, UString >
 Define a container type holding all environment variables.
 

Functions

bool ts::DeleteEnvironment (const UString &name)
 Delete an environment variable.
 
bool ts::EnvironmentExists (const UString &varname)
 Check if an environment variable exists.
 
UString ts::ExpandEnvironment (const UString &path)
 Expand environment variables inside a file path (or any string).
 
UString ts::GetEnvironment (const UString &varname, const UString &defvalue=UString())
 Get the value of an environment variable.
 
void ts::GetEnvironment (Environment &env)
 Get the content of the entire environment (all environment variables).
 
template<class CONTAINER >
void ts::GetEnvironmentPath (CONTAINER &container, const UString &name, const UString &def=UString())
 Get the value of an environment variable containing a search path.
 
template<class CONTAINER >
void ts::GetEnvironmentPathAppend (CONTAINER &container, const UString &name, const UString &def=UString())
 Get the value of an environment variable containing a search path.
 
bool ts::LoadEnvironment (Environment &env, const UString &fileName)
 Load a text file containing environment variables.
 
bool ts::SetEnvironment (const UString &name, const UString &value)
 Set the value of an environment variable.
 
template<class CONTAINER >
void ts::SetEnvironmentPath (const UString &name, const CONTAINER &container)
 Set the value of an environment variable containing a search path.
 

Variables

constexpr const UCharts::PATH_ENVIRONMENT_VARIABLE = platform - specific("PATH", "Path")
 Environment variable containing the command search path.
 
constexpr const UCharts::PLUGINS_PATH_ENVIRONMENT_VARIABLE = u"TSPLUGINS_PATH"
 Name of the environment variable which contains a list of paths for plugins.
 
constexpr UChar ts::SEARCH_PATH_SEPARATOR = platform-specific (':', ';')
 Separator character in search paths.
 

Detailed Description

System environment variables features.

Typedef Documentation

◆ Environment

using ts::Environment = typedef std::map<UString, UString>

Define a container type holding all environment variables.

For each element in the container, the key is the name of an environment variable and the value is the corresponding value of this environment variable.

Function Documentation

◆ EnvironmentExists()

bool ts::EnvironmentExists ( const UString varname)

Check if an environment variable exists.

Parameters
[in]varnameEnvironment variable name.
Returns
True if the specified environment variable exists, false otherwise.

◆ GetEnvironment() [1/2]

UString ts::GetEnvironment ( const UString varname,
const UString defvalue = UString() 
)

Get the value of an environment variable.

Parameters
[in]varnameEnvironment variable name.
[in]defvalueDefault value if the specified environment variable does not exist.
Returns
The value of the specified environment variable it it exists, defvalue otherwise.

◆ GetEnvironmentPath()

template<class CONTAINER >
void ts::GetEnvironmentPath ( CONTAINER &  container,
const UString name,
const UString def = UString() 
)
inline

Get the value of an environment variable containing a search path.

The search path is analyzed and split into individual directory names.

Template Parameters
CONTAINERA container class of UString as defined by the C++ Standard Template Library (STL).
Parameters
[out]containerA container of UString receiving the directory names.
[in]nameEnvironment variable name.
[in]defDefault value if the specified environment variable does not exist.

◆ GetEnvironmentPathAppend()

template<class CONTAINER >
void ts::GetEnvironmentPathAppend ( CONTAINER &  container,
const UString name,
const UString def = UString() 
)
inline

Get the value of an environment variable containing a search path.

The search path is analyzed and split into individual directory names.

Template Parameters
CONTAINERA container class of UString as defined by the C++ Standard Template Library (STL).
Parameters
[in,out]containerA container of UString receiving the directory names. The directory names are appended to the container without erasing previous content.
[in]nameEnvironment variable name.
[in]defDefault value if the specified environment variable does not exist.

◆ SetEnvironment()

bool ts::SetEnvironment ( const UString name,
const UString value 
)

Set the value of an environment variable.

If the variable previously existed, its value is overwritten. If it did not exist, it is created.

Parameters
[in]nameEnvironment variable name.
[in]valueEnvironment variable value.
Returns
True on success, false on error.

◆ SetEnvironmentPath()

template<class CONTAINER >
void ts::SetEnvironmentPath ( const UString name,
const CONTAINER &  container 
)
inline

Set the value of an environment variable containing a search path.

If the variable previously existed, its value is overwritten. If it did not exist, it is created.

Template Parameters
CONTAINERA container class of UString as defined by the C++ Standard Template Library (STL).
Parameters
[in]nameEnvironment variable name.
[in]containerA container of UString containing directory names.

◆ DeleteEnvironment()

bool ts::DeleteEnvironment ( const UString name)

Delete an environment variable.

If the variable did not exist, do nothing, do not generate an error.

Parameters
[in]nameEnvironment variable name.
Returns
True on success, false on error.

◆ ExpandEnvironment()

UString ts::ExpandEnvironment ( const UString path)

Expand environment variables inside a file path (or any string).

Environment variable references '$name' or '${name}' are replaced by the corresponding values from the environment. In the first form, 'name' is the longest combination of letters, digits and underscore. A combination \$ is interpreted as a literal $, not an environment variable reference.

Parameters
[in]pathA path string containing references to environment variables.
Returns
The expanded string.

◆ GetEnvironment() [2/2]

void ts::GetEnvironment ( Environment env)

Get the content of the entire environment (all environment variables).

Parameters
[out]envAn associative container which receives the content of the environment. Each key is the name of an environment variable and the corresponding value is the value of this environment variable.

◆ LoadEnvironment()

bool ts::LoadEnvironment ( Environment env,
const UString fileName 
)

Load a text file containing environment variables.

Each line shall be in the form "name = value". Empty line and line starting with '#' are ignored. Spaces are trimmed.

Parameters
[out]envAn associative container which receives the content of the environment. Each key is the name of an environment variable and the corresponding value is the value of this environment variable.
[in]fileNameName of the file to load.
Returns
True on success, false on error.