libzypp  17.14.0
zypp::env::ScopedSet Class Reference

Temporarily set/unset an environment variable. More...

#include <Env.h>

Public Member Functions

 ScopedSet (const ScopedSet &)=delete
 
ScopedSetoperator= (const ScopedSet &)=delete
 
 ScopedSet (ScopedSet &&)=default
 
ScopedSetoperator= (ScopedSet &&)=default
 
 ScopedSet ()
 Default ctor (NOOP).
 
 ScopedSet (std::string var_r, const char *val_r)
 Set var_r to val_r (unsets var_r if val_r is a nullptr).
 

Public Attributes

std::unique_ptr< std::string > _val
 

Detailed Description

Temporarily set/unset an environment variable.

Definition at line 28 of file Env.h.

Constructor & Destructor Documentation

zypp::env::ScopedSet::ScopedSet ( const ScopedSet )
delete
zypp::env::ScopedSet::ScopedSet ( ScopedSet &&  )
default
zypp::env::ScopedSet::ScopedSet ( )
inline

Default ctor (NOOP).

Definition at line 38 of file Env.h.

zypp::env::ScopedSet::ScopedSet ( std::string  var_r,
const char *  val_r 
)
inline

Set var_r to val_r (unsets var_r if val_r is a nullptr).

Definition at line 42 of file Env.h.

Member Function Documentation

ScopedSet& zypp::env::ScopedSet::operator= ( const ScopedSet )
delete
ScopedSet& zypp::env::ScopedSet::operator= ( ScopedSet &&  )
default

Member Data Documentation

std::unique_ptr<std::string> zypp::env::ScopedSet::_val
Initial value:
{
if ( !_var.empty() )
{
if ( const char * orig = ::getenv( _var.c_str() ) )
_val.reset( new std::string( orig ) );
setval( val_r );
}
}
{
if ( !_var.empty() )
setval( _val ? _val->c_str() : nullptr );
}
private:
void setval( const char * val_r )
{
if ( val_r )
::setenv( _var.c_str(), val_r, 1 );
else
::unsetenv( _var.c_str() );
}
private:
std::string _var

Definition at line 44 of file Env.h.


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