Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
SC::ProcessEnvironment Struct Reference

Reads current process environment variables. More...

#include <Process.h>

Public Member Functions

 ProcessEnvironment (const ProcessEnvironment &)=delete
 
 ProcessEnvironment (ProcessEnvironment &&)=delete
 
ProcessEnvironmentoperator= (const ProcessEnvironment &)=delete
 
ProcessEnvironmentoperator= (ProcessEnvironment &&)=delete
 
size_t size () const
 Returns the total number of environment variables for current process.
 
bool get (size_t index, StringSpan &name, StringSpan &value) const
 Get the environment variable at given index, returning its name and value.
 
bool contains (StringSpan variableName, size_t *index=nullptr) const
 Checks if an environment variable exists in current process.
 
bool get (StringSpan variableName, StringSpan &value) const
 Gets the value of an environment variable from current process.
 

Detailed Description

Reads current process environment variables.

Example: Print all environment variables to stdout

for (size_t idx = 0; idx < environment.size(); ++idx)
{
StringView name, value;
(void)environment.get(idx, name, value);
if (value.isEmpty())
{
report.console.printLine(name);
}
else
{
report.console.print(name);
report.console.print("=");
report.console.printLine(value);
}
}

Member Function Documentation

◆ contains()

bool SC::ProcessEnvironment::contains ( StringSpan variableName,
size_t * index = nullptr ) const
nodiscard

Checks if an environment variable exists in current process.

Parameters
variableNameName of the variable to check
indexOptional pointer to a variable that will receive the index of the variable (only if found)
Returns
true if variableName has been found in list of the variable

◆ get() [1/2]

bool SC::ProcessEnvironment::get ( size_t index,
StringSpan & name,
StringSpan & value ) const
nodiscard

Get the environment variable at given index, returning its name and value.

Parameters
indexThe index of the variable to retrieve (must be less than ProcessEnvironment::size())
nameThe parsed name of the environment variable at requested index
valueThe parsed value of the environment variable at requested index

◆ get() [2/2]

bool SC::ProcessEnvironment::get ( StringSpan variableName,
StringSpan & value ) const
nodiscard

Gets the value of an environment variable from current process.

Parameters
variableNameName of the variable to retrieve
valueValue of the variable when found
Returns
true if variableName has been found

◆ size()

size_t SC::ProcessEnvironment::size ( ) const
inlinenodiscard

Returns the total number of environment variables for current process.


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