KiCad PCB EDA Suite
tool_settings.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) 2015 CERN
5  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 
26 #ifndef __TOOL_SETTINGS_H
27 #define __TOOL_SETTINGS_H
28 
29 #include <core/settings.h>
30 
36 class TOOL_BASE;
37 
38 class TOOL_SETTINGS : public SETTINGS
39 {
40  public:
41  TOOL_SETTINGS( TOOL_BASE* aTool = NULL );
43 
44  template<class T>
45  T Get( const wxString& aName, T aDefaultValue ) const
46  {
47  wxConfigBase* config = getConfigBase();
48 
49  if( !config )
50  return aDefaultValue;
51 
52  T tmp = aDefaultValue;
53 
54  config->Read( getKeyName( aName ), &tmp );
55  return tmp;
56  }
57 
58  template<class T>
59  void Set( const wxString& aName, const T &aValue )
60  {
61  wxConfigBase* config = getConfigBase();
62 
63  if( !config )
64  return;
65 
66  config->Write( getKeyName( aName ), aValue );
67  }
68 
69  private:
70  wxString getKeyName( const wxString& aEntryName ) const override;
71 
74  wxConfigBase* getConfigBase() const;
75 
77 
78 };
79 
80 #endif
Class TOOL_SETTINGS.
Definition: settings.h:38
T
enum T contains all this lexer's tokens.
T Get(const wxString &aName, T aDefaultValue) const
Definition: tool_settings.h:45
wxConfigBase * getConfigBase() const
Returns pointer to currently used wxConfigBase.
Definition: tool_base.cpp:92
TOOL_BASE * m_tool
Definition: tool_settings.h:76
void Set(const wxString &aName, const T &aValue)
Definition: tool_settings.h:59
Class TOOL_BASE.
Definition: tool_base.h:68
TOOL_SETTINGS(TOOL_BASE *aTool=NULL)
Definition: tool_base.cpp:66
wxString getKeyName(const wxString &aEntryName) const override
Definition: tool_base.cpp:83