KiCad PCB EDA Suite
Loading...
Searching...
No Matches
KI_TEST::SCOPED_PROCESS_ENV_VAR Class Reference

RAII helper that sets a process-level environment variable for the lifetime of the object. More...

#include <env_var_utils.h>

Public Member Functions

 SCOPED_PROCESS_ENV_VAR (const wxString &aName, const std::optional< wxString > &aValue)
 
 ~SCOPED_PROCESS_ENV_VAR ()
 
 SCOPED_PROCESS_ENV_VAR (const SCOPED_PROCESS_ENV_VAR &)=delete
 
SCOPED_PROCESS_ENV_VARoperator= (const SCOPED_PROCESS_ENV_VAR &)=delete
 
void SetValue (const wxString &aValue)
 Set a new value for the environment variable (which will still only be in effect for the lifetime of this object).
 
std::optional< wxString > GetValue () const
 Get the current value of the environment variable, if it exists.
 
void ClearValue ()
 Clear the environment variable for the lifetime of this object.
 

Private Attributes

wxString m_name
 
std::optional< wxString > m_oldValue
 

Detailed Description

RAII helper that sets a process-level environment variable for the lifetime of the object.

On destruction, it restores the previous entry, or removes the entry if it did not previously exist.

Note that this affects the process-level environment, so it will affect code that uses wxGetEnv() directly, but if variables have already been read into the KiCad program-level environment variable map, those will not be affected. If you want to affect the program-level environment variable map, use SCOPED_PGM_ENV_VAR

Definition at line 42 of file env_var_utils.h.

Constructor & Destructor Documentation

◆ SCOPED_PROCESS_ENV_VAR() [1/2]

KI_TEST::SCOPED_PROCESS_ENV_VAR::SCOPED_PROCESS_ENV_VAR ( const wxString & aName,
const std::optional< wxString > & aValue )

Definition at line 27 of file env_var_utils.cpp.

References m_name, and m_oldValue.

Referenced by operator=(), and SCOPED_PROCESS_ENV_VAR().

◆ ~SCOPED_PROCESS_ENV_VAR()

KI_TEST::SCOPED_PROCESS_ENV_VAR::~SCOPED_PROCESS_ENV_VAR ( )

Definition at line 44 of file env_var_utils.cpp.

References m_name, and m_oldValue.

◆ SCOPED_PROCESS_ENV_VAR() [2/2]

KI_TEST::SCOPED_PROCESS_ENV_VAR::SCOPED_PROCESS_ENV_VAR ( const SCOPED_PROCESS_ENV_VAR & )
delete

Member Function Documentation

◆ ClearValue()

void KI_TEST::SCOPED_PROCESS_ENV_VAR::ClearValue ( )

Clear the environment variable for the lifetime of this object.

if it was previously set, it will be restored on destruction.

Definition at line 69 of file env_var_utils.cpp.

References m_name.

Referenced by BOOST_AUTO_TEST_CASE().

◆ GetValue()

std::optional< wxString > KI_TEST::SCOPED_PROCESS_ENV_VAR::GetValue ( ) const

Get the current value of the environment variable, if it exists.

Definition at line 59 of file env_var_utils.cpp.

References m_name.

◆ operator=()

SCOPED_PROCESS_ENV_VAR & KI_TEST::SCOPED_PROCESS_ENV_VAR::operator= ( const SCOPED_PROCESS_ENV_VAR & )
delete

◆ SetValue()

void KI_TEST::SCOPED_PROCESS_ENV_VAR::SetValue ( const wxString & aValue)

Set a new value for the environment variable (which will still only be in effect for the lifetime of this object).

Definition at line 53 of file env_var_utils.cpp.

References m_name.

Member Data Documentation

◆ m_name

wxString KI_TEST::SCOPED_PROCESS_ENV_VAR::m_name
private

◆ m_oldValue

std::optional<wxString> KI_TEST::SCOPED_PROCESS_ENV_VAR::m_oldValue
private

Definition at line 71 of file env_var_utils.h.

Referenced by SCOPED_PROCESS_ENV_VAR(), and ~SCOPED_PROCESS_ENV_VAR().


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