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, StringView &name, StringView &value) const
 Get the environment variable at given index, returning its name and value.
 
bool contains (StringView variableName, size_t *index=nullptr)
 Checks if an environment variable exists in 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 ( StringView variableName,
size_t * index = nullptr )
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()

bool SC::ProcessEnvironment::get ( size_t index,
StringView & name,
StringView & 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

◆ 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: