KiCad PCB EDA Suite
include/settings/environment.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef KICAD_ENVIRONMENT_H
21 #define KICAD_ENVIRONMENT_H
22 
23 #include <map>
24 #include <wx/string.h>
25 
60 {
61 public:
62  ENV_VAR_ITEM( const wxString& aValue = wxEmptyString, bool aIsDefinedExternally = false ) :
63  m_value( aValue ),
64  m_isBuiltin( true ),
65  m_isDefinedExternally( aIsDefinedExternally ),
66  m_isDefinedInSettings( false )
67  {
68  }
69 
70  ENV_VAR_ITEM( const wxString& aKey, const wxString& aValue,
71  const wxString& aDefaultValue = wxEmptyString ) :
72  m_key( aKey ),
73  m_value( aValue ),
74  m_defaultValue( aDefaultValue ),
75  m_isBuiltin( true ),
76  m_isDefinedExternally( false ),
77  m_isDefinedInSettings( false )
78  {
79  }
80 
81  ~ENV_VAR_ITEM() throw() {} // tell SWIG no exception
82 
84  void SetDefinedExternally( bool aIsDefinedExternally = true )
85  {
86  m_isDefinedExternally = aIsDefinedExternally;
87  }
88 
90  void SetDefinedInSettings( bool aDefined = true ) { m_isDefinedInSettings = aDefined; }
91 
92  wxString GetKey() const { return m_key; }
93 
94  const wxString& GetValue() const { return m_value; }
95  void SetValue( const wxString& aValue ) { m_value = aValue; }
96 
97  wxString GetDefault() const { return m_defaultValue; }
98 
99  wxString GetSettingsValue() const { return m_settingsValue; }
100  void SetSettingsValue( const wxString& aValue ) { m_settingsValue = aValue; }
101 
102  bool GetBuiltin() const { return m_isBuiltin; }
103 
108  bool IsDefault() const
109  {
110  return m_isBuiltin && m_value == m_defaultValue;
111  }
112 
113 private:
115  wxString m_key;
116 
118  wxString m_value;
119 
121  wxString m_defaultValue;
122 
124  wxString m_settingsValue;
125 
128 
131 
134 };
135 
136 typedef std::map<wxString, ENV_VAR_ITEM> ENV_VAR_MAP;
137 typedef std::map<wxString, ENV_VAR_ITEM>::iterator ENV_VAR_MAP_ITER;
138 typedef std::map<wxString, ENV_VAR_ITEM>::const_iterator ENV_VAR_MAP_CITER;
139 
140 #endif // KICAD_ENVIRONMENT_H
wxString m_defaultValue
The default value, for built-in variables that are always defined.
bool m_isDefinedExternally
Flag to indicate if the environment variable was defined externally to the process.
void SetDefinedInSettings(bool aDefined=true)
wxString GetDefault() const
wxString m_value
The environment variable string value.
KiCad uses environment variables internally for determining the base paths for libraries,...
const wxString & GetValue() const
bool GetDefinedInSettings() const
wxString m_settingsValue
The value that was originally loaded from JSON.
bool m_isBuiltin
Set to true for KiCad built-in variables that are always defined one way or another.
void SetDefinedExternally(bool aIsDefinedExternally=true)
void SetSettingsValue(const wxString &aValue)
ENV_VAR_ITEM(const wxString &aKey, const wxString &aValue, const wxString &aDefaultValue=wxEmptyString)
bool IsDefault() const
Checks if the variable matches its default value (always false for non-built-in vars)
bool m_isDefinedInSettings
Flag to indicate if the environment variable was defined in the settings file.
std::map< wxString, ENV_VAR_ITEM >::iterator ENV_VAR_MAP_ITER
bool GetDefinedExternally() const
wxString GetSettingsValue() const
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
void SetValue(const wxString &aValue)
wxString m_key
The environment variable string key.
std::map< wxString, ENV_VAR_ITEM >::const_iterator ENV_VAR_MAP_CITER
ENV_VAR_ITEM(const wxString &aValue=wxEmptyString, bool aIsDefinedExternally=false)