KiCad PCB EDA Suite
env_vars.h File Reference

Functions related to environment variables, including help functions. More...

#include <wx/string.h>
#include <vector>
#include <core/optional.h>

Go to the source code of this file.

Typedefs

using ENV_VAR_LIST = std::vector< wxString >
 

Functions

bool IsEnvVarImmutable (const wxString &aEnvVar)
 Determine if an environment variable is "predefined", i.e. More...
 
const ENV_VAR_LISTGetPredefinedEnvVars ()
 Get the list of pre-defined environment variables. More...
 
wxString LookUpEnvVarHelp (const wxString &aEnvVar)
 Look up long-form help text for a given environment variable. More...
 
template<typename VAL_TYPE >
OPT< VAL_TYPE > GetEnvVar (const wxString &aEnvVarName)
 Get an environment variable as a specific type, if set correctly. More...
 
template<>
OPT< wxString > GetEnvVar (const wxString &aEnvVarName)
 Get a string environment variable, if it is set. More...
 
template<>
OPT< double > GetEnvVar (const wxString &aEnvVarName)
 Get a double from an environment variable, if set. More...
 

Detailed Description

Functions related to environment variables, including help functions.

Definition in file env_vars.h.

Typedef Documentation

◆ ENV_VAR_LIST

using ENV_VAR_LIST = std::vector<wxString>

Definition at line 34 of file env_vars.h.

Function Documentation

◆ GetEnvVar() [1/3]

template<typename VAL_TYPE >
OPT<VAL_TYPE> GetEnvVar ( const wxString &  aEnvVarName)

Get an environment variable as a specific type, if set correctly.

Parameters
aEnvVarNamethe name of the environment variable
Returns
an OPT containing the value, if set and parseable, otherwise empty.

Definition at line 111 of file env_vars.cpp.

112 {
113  OPT<double> opt_value;
114 
115  wxString env;
116  if( wxGetEnv( aEnvVarName, &env ) )
117  {
118  double value;
119  if( env.ToDouble( &value ) )
120  {
121  opt_value = value;
122  }
123  }
124 
125  return opt_value;
126 }
boost::optional< T > OPT
Definition: optional.h:7

◆ GetEnvVar() [2/3]

template<>
OPT<wxString> GetEnvVar ( const wxString &  aEnvVarName)

Get a string environment variable, if it is set.

Parameters
aEnvVarNamethe name of the environment variable
Returns
an OPT containing the value, if set, otherwise empty.

Get a string environment variable, if it is set.

Parameters
aEnvVarNamethe name of the environment variable
Returns
an OPT containing the value, if set and parseable, otherwise empty.

Definition at line 111 of file env_vars.cpp.

112 {
113  OPT<double> opt_value;
114 
115  wxString env;
116  if( wxGetEnv( aEnvVarName, &env ) )
117  {
118  double value;
119  if( env.ToDouble( &value ) )
120  {
121  opt_value = value;
122  }
123  }
124 
125  return opt_value;
126 }
boost::optional< T > OPT
Definition: optional.h:7

◆ GetEnvVar() [3/3]

template<>
OPT<double> GetEnvVar ( const wxString &  aEnvVarName)

Get a double from an environment variable, if set.

Parameters
aEnvVarNamethe name of the environment variable
Returns
an OPT containing the value, if set and parseable as a double, otherwise empty.

Get a double from an environment variable, if set.

Get a string environment variable, if it is set.

Parameters
aEnvVarNamethe name of the environment variable
Returns
an OPT containing the value, if set and parseable, otherwise empty.

Definition at line 111 of file env_vars.cpp.

112 {
113  OPT<double> opt_value;
114 
115  wxString env;
116  if( wxGetEnv( aEnvVarName, &env ) )
117  {
118  double value;
119  if( env.ToDouble( &value ) )
120  {
121  opt_value = value;
122  }
123  }
124 
125  return opt_value;
126 }
boost::optional< T > OPT
Definition: optional.h:7

◆ GetPredefinedEnvVars()

const ENV_VAR_LIST& GetPredefinedEnvVars ( )

Get the list of pre-defined environment variables.

Definition at line 61 of file env_vars.cpp.

62 {
63  return predefined_env_vars;
64 }
static const ENV_VAR_LIST predefined_env_vars
Definition: env_vars.cpp:37

References predefined_env_vars.

Referenced by DIALOG_CONFIGURE_PATHS::OnHelp().

◆ IsEnvVarImmutable()

bool IsEnvVarImmutable ( const wxString &  aEnvVar)

Determine if an environment variable is "predefined", i.e.

if the name of the variable is special to KiCad, and isn't just a user-specified substitution name.

Parameters
aEnvVarthe variable to check
Returns
true if predefined

Definition at line 49 of file env_vars.cpp.

50 {
51  for( const auto& s: predefined_env_vars )
52  {
53  if( s == aEnvVar )
54  return true;
55  }
56 
57  return false;
58 }
static const ENV_VAR_LIST predefined_env_vars
Definition: env_vars.cpp:37

References predefined_env_vars.

Referenced by DIALOG_CONFIGURE_PATHS::AppendEnvVar(), and DIALOG_CONFIGURE_PATHS::OnRemoveEnvVar().

◆ LookUpEnvVarHelp()

wxString LookUpEnvVarHelp ( const wxString &  aEnvVar)

Look up long-form help text for a given environment variable.

This is intended for use in more verbose help resources (as opposed to tooltip text)

Parameters
aEnvVarThe variable to look up
Returns
A string with help for that variable. Empty if no help available for this variable.

Definition at line 99 of file env_vars.cpp.

100 {
101  static STRING_MAP env_var_help_text;
102 
103  if( env_var_help_text.size() == 0 )
104  initialiseEnvVarHelp( env_var_help_text );
105 
106  return env_var_help_text[aEnvVar];
107 }
std::map< wxString, wxString > STRING_MAP
Definition: env_vars.cpp:28
void initialiseEnvVarHelp(STRING_MAP &aMap)
Definition: env_vars.cpp:67

References initialiseEnvVarHelp().

Referenced by DIALOG_CONFIGURE_PATHS::OnHelp().