powerd++  0.4.4
Public Member Functions | Private Attributes | List of all members
sys::env::Var Class Reference

A reference type refering to an environment variable. More...

#include <env.hpp>

Public Member Functions

template<size_t Size>
 Var (char const (&name)[Size])
 Construct an environment variable reference. More...
 
 Var (Var const &)=delete
 Do not permit copy construction.
 
Varoperator= (Var const &)=delete
 Do not permit copy assignment.
 
 operator char const * () const
 Retrieve the value of the environment variable. More...
 
Varoperator= (char const *const assign)
 Assign a new value to the environment variable. More...
 
Varerase ()
 Explicitly deletes the environment variable. More...
 
const char * c_str () const
 Explicitly retrieve the value as a character array. More...
 

Private Attributes

const char *const name
 A pointer to the variable name.
 

Detailed Description

A reference type refering to an environment variable.

To avoid issues with the lifetime of the name string this is not copy constructible or assignable.

Constructor & Destructor Documentation

◆ Var()

template<size_t Size>
sys::env::Var::Var ( char const (&)  name[Size])
inline

Construct an environment variable reference.

Template Parameters
SizeThe size of the name buffer
Parameters
nameThe name of the environment variable

Member Function Documentation

◆ c_str()

const char* sys::env::Var::c_str ( ) const
inline

Explicitly retrieve the value as a character array.

Returns
A pointer to the character array with the variable value
Return values
nullptrThe variable does not exist

◆ erase()

Var& sys::env::Var::erase ( )
inline

Explicitly deletes the environment variable.

Returns
A self-reference
Exceptions
sc_error<error>{EINVAL}Invalid variable name
sc_error<error>{ENOMEM}Failed to allocate memory when updating the environment

◆ operator char const *()

sys::env::Var::operator char const * ( ) const
inline

Retrieve the value of the environment variable.

Returns
A pointer to the character array with the variable value
Return values
nullptrThe variable does not exist

◆ operator=()

Var& sys::env::Var::operator= ( char const *const  assign)
inline

Assign a new value to the environment variable.

Deletes the variable if nullptr is assigned.

Parameters
assignThe new value
Returns
A self-reference
Exceptions
sc_error<error>{EINVAL}Invalid variable name
sc_error<error>{ENOMEM}Failed to allocate memory when updating the environment

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