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

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

#include <env_var_utils.h>

Public Member Functions

 SCOPED_PGM_ENV_VAR (const wxString &aName, const std::optional< wxString > &aValue)
 
 ~SCOPED_PGM_ENV_VAR ()
 
 SCOPED_PGM_ENV_VAR (const SCOPED_PGM_ENV_VAR &)=delete
 
SCOPED_PGM_ENV_VARoperator= (const SCOPED_PGM_ENV_VAR &)=delete
 
ENV_VAR_ITEMGetItem ()
 Get the wrapped environment variable item.
 
const ENV_VAR_ITEMGetItem () const
 
void ClearItem ()
 Clear the environment variable for the lifetime of the object.
 

Private Attributes

ENV_VAR_MAPm_pgmEnvVars
 
wxString m_name
 
std::optional< ENV_VAR_ITEMm_oldValue
 

Detailed Description

RAII helper that sets a KiCad program-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 only affects the KiCad program-level environment variable map. It will not affect code that uses wxGetEnv() directly.

Definition at line 83 of file env_var_utils.h.

Constructor & Destructor Documentation

◆ SCOPED_PGM_ENV_VAR() [1/2]

KI_TEST::SCOPED_PGM_ENV_VAR::SCOPED_PGM_ENV_VAR ( const wxString & aName,
const std::optional< wxString > & aValue )
Parameters
aNamethe name of the environment variable to set
aValuethe value to set the variable to. If nullopt, the variable is removed for the lifetime of the object.

Definition at line 75 of file env_var_utils.cpp.

References m_name, m_oldValue, m_pgmEnvVars, and Pgm().

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

◆ ~SCOPED_PGM_ENV_VAR()

KI_TEST::SCOPED_PGM_ENV_VAR::~SCOPED_PGM_ENV_VAR ( )

Definition at line 93 of file env_var_utils.cpp.

References m_name, m_oldValue, and m_pgmEnvVars.

◆ SCOPED_PGM_ENV_VAR() [2/2]

KI_TEST::SCOPED_PGM_ENV_VAR::SCOPED_PGM_ENV_VAR ( const SCOPED_PGM_ENV_VAR & )
delete

References SCOPED_PGM_ENV_VAR().

Member Function Documentation

◆ ClearItem()

void KI_TEST::SCOPED_PGM_ENV_VAR::ClearItem ( )
inline

Clear the environment variable for the lifetime of the object.

Definition at line 108 of file env_var_utils.h.

References m_name, and m_pgmEnvVars.

◆ GetItem() [1/2]

ENV_VAR_ITEM & KI_TEST::SCOPED_PGM_ENV_VAR::GetItem ( )

Get the wrapped environment variable item.

The caller can modify this freely. Whatever it is set to will be restored on destruction.

Definition at line 102 of file env_var_utils.cpp.

References m_name, and m_pgmEnvVars.

Referenced by BOOST_AUTO_TEST_CASE().

◆ GetItem() [2/2]

const ENV_VAR_ITEM & KI_TEST::SCOPED_PGM_ENV_VAR::GetItem ( ) const

Definition at line 108 of file env_var_utils.cpp.

References m_name, and m_pgmEnvVars.

◆ operator=()

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

References SCOPED_PGM_ENV_VAR().

Member Data Documentation

◆ m_name

wxString KI_TEST::SCOPED_PGM_ENV_VAR::m_name
private

Definition at line 112 of file env_var_utils.h.

Referenced by ClearItem(), GetItem(), GetItem(), SCOPED_PGM_ENV_VAR(), and ~SCOPED_PGM_ENV_VAR().

◆ m_oldValue

std::optional<ENV_VAR_ITEM> KI_TEST::SCOPED_PGM_ENV_VAR::m_oldValue
private

Definition at line 113 of file env_var_utils.h.

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

◆ m_pgmEnvVars

ENV_VAR_MAP& KI_TEST::SCOPED_PGM_ENV_VAR::m_pgmEnvVars
private

Definition at line 111 of file env_var_utils.h.

Referenced by ClearItem(), GetItem(), GetItem(), SCOPED_PGM_ENV_VAR(), and ~SCOPED_PGM_ENV_VAR().


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