/[pcsx2_0.9.7]/trunk/pcsx2/gui/IniInterface.h
ViewVC logotype

Contents of /trunk/pcsx2/gui/IniInterface.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (9 years, 10 months ago) by william
File MIME type: text/plain
File size: 7332 byte(s)
committing r3113 initial commit again...
1 /* PCSX2 - PS2 Emulator for PCs
2 * Copyright (C) 2002-2010 PCSX2 Dev Team
3 *
4 * PCSX2 is free software: you can redistribute it and/or modify it under the terms
5 * of the GNU Lesser General Public License as published by the Free Software Found-
6 * ation, either version 3 of the License, or (at your option) any later version.
7 *
8 * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10 * PURPOSE. See the GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along with PCSX2.
13 * If not, see <http://www.gnu.org/licenses/>.
14 */
15
16 #pragma once
17
18 #include <wx/config.h>
19
20 //////////////////////////////////////////////////////////////////////////////////////////
21 // IniInterface class (abstract base class)
22 //
23 // This is used as an interchangable interface for both loading and saving options from an
24 // ini/configuration file. The LoadSave code takes an IniInterface, and the interface
25 // implementation defines whether the options are read or written.
26 //
27 // See also: IniLoader, IniSaver
28 //
29 class IniInterface
30 {
31 protected:
32 wxConfigBase& m_Config;
33
34 public:
35 virtual ~IniInterface();
36 explicit IniInterface();
37 explicit IniInterface( wxConfigBase& config );
38
39 void SetPath( const wxString& path );
40 void Flush();
41
42 wxConfigBase& GetConfig() { return m_Config; }
43
44 virtual bool IsLoading() const=0;
45 bool IsSaving() const { return !IsLoading(); }
46
47 virtual void Entry( const wxString& var, wxString& value, const wxString& defvalue=wxString() )=0;
48 virtual void Entry( const wxString& var, wxDirName& value, const wxDirName& defvalue=wxDirName() )=0;
49 virtual void Entry( const wxString& var, wxFileName& value, const wxFileName& defvalue=wxFileName() )=0;
50 virtual void Entry( const wxString& var, int& value, const int defvalue=0 )=0;
51 virtual void Entry( const wxString& var, uint& value, const uint defvalue=0 )=0;
52 virtual void Entry( const wxString& var, bool& value, const bool defvalue=false )=0;
53
54 // This special form of Entry is provided for bitfields, which cannot be passed by reference.
55 virtual bool EntryBitBool( const wxString& var, bool value, const bool defvalue=false )=0;
56 virtual int EntryBitfield( const wxString& var, int value, const int defvalue=0 )=0;
57
58 virtual void Entry( const wxString& var, Fixed100& value, const Fixed100& defvalue=Fixed100() )=0;
59
60 virtual void Entry( const wxString& var, wxPoint& value, const wxPoint& defvalue=wxDefaultPosition )=0;
61 virtual void Entry( const wxString& var, wxSize& value, const wxSize& defvalue=wxDefaultSize )=0;
62 virtual void Entry( const wxString& var, wxRect& value, const wxRect& defvalue=wxDefaultRect )=0;
63
64 template< typename T >
65 void EnumEntry( const wxString& var, T& value, const wxChar* const* enumArray=NULL, const T defvalue=(T)0 )
66 {
67 int tstore = (int)value;
68 if( enumArray == NULL )
69 Entry( var, tstore, defvalue );
70 else
71 _EnumEntry( var, tstore, enumArray, defvalue );
72 value = (T)tstore;
73 }
74
75 protected:
76 virtual void _EnumEntry( const wxString& var, int& value, const wxChar* const* enumArray, int defvalue )=0;
77 };
78
79 //////////////////////////////////////////////////////////////////////////////////////////
80 //
81 class IniScopedGroup
82 {
83 protected:
84 IniInterface& m_mom;
85
86 public:
87 IniScopedGroup( IniInterface& mommy, const wxString& group );
88 virtual ~IniScopedGroup();
89 };
90
91 //////////////////////////////////////////////////////////////////////////////////////////
92 // IniLoader class
93 //
94 // Implementation of the IniInterface base class, which maps ini actions to loading from
95 // an ini source file.
96 //
97 // See also: IniInterface
98 //
99 class IniLoader : public IniInterface
100 {
101 public:
102 virtual ~IniLoader() throw();
103 explicit IniLoader();
104 explicit IniLoader( wxConfigBase& config );
105
106 bool IsLoading() const { return true; }
107
108 void Entry( const wxString& var, wxString& value, const wxString& defvalue=wxEmptyString );
109 void Entry( const wxString& var, wxDirName& value, const wxDirName& defvalue=wxDirName() );
110 void Entry( const wxString& var, wxFileName& value, const wxFileName& defvalue=wxFileName() );
111 void Entry( const wxString& var, int& value, const int defvalue=0 );
112 void Entry( const wxString& var, uint& value, const uint defvalue=0 );
113 void Entry( const wxString& var, bool& value, const bool defvalue=false );
114
115 bool EntryBitBool( const wxString& var, bool value, const bool defvalue=false );
116 int EntryBitfield( const wxString& var, int value, const int defvalue=0 );
117
118 void Entry( const wxString& var, Fixed100& value, const Fixed100& defvalue=Fixed100() );
119
120 void Entry( const wxString& var, wxPoint& value, const wxPoint& defvalue=wxDefaultPosition );
121 void Entry( const wxString& var, wxSize& value, const wxSize& defvalue=wxDefaultSize );
122 void Entry( const wxString& var, wxRect& value, const wxRect& defvalue=wxDefaultRect );
123
124 protected:
125 void _EnumEntry( const wxString& var, int& value, const wxChar* const* enumArray, int defvalue );
126 };
127
128 //////////////////////////////////////////////////////////////////////////////////////////
129 // IniSaver class
130 //
131 // Implementation of the IniInterface base class, which maps ini actions to saving to
132 // an ini dest file.
133 //
134 // See also: IniInterface
135 //
136 class IniSaver : public IniInterface
137 {
138 public:
139 virtual ~IniSaver();
140 explicit IniSaver();
141 explicit IniSaver( wxConfigBase& config );
142
143 bool IsLoading() const { return false; }
144
145 void Entry( const wxString& var, wxString& value, const wxString& defvalue=wxString() );
146 void Entry( const wxString& var, wxDirName& value, const wxDirName& defvalue=wxDirName() );
147 void Entry( const wxString& var, wxFileName& value, const wxFileName& defvalue=wxFileName() );
148 void Entry( const wxString& var, int& value, const int defvalue=0 );
149 void Entry( const wxString& var, uint& value, const uint defvalue=0 );
150 void Entry( const wxString& var, bool& value, const bool defvalue=false );
151
152 bool EntryBitBool( const wxString& var, bool value, const bool defvalue=false );
153 int EntryBitfield( const wxString& var, int value, const int defvalue=0 );
154
155 void Entry( const wxString& var, Fixed100& value, const Fixed100& defvalue=Fixed100() );
156
157 void Entry( const wxString& var, wxPoint& value, const wxPoint& defvalue=wxDefaultPosition );
158 void Entry( const wxString& var, wxSize& value, const wxSize& defvalue=wxDefaultSize );
159 void Entry( const wxString& var, wxRect& value, const wxRect& defvalue=wxDefaultRect );
160
161 protected:
162 void _EnumEntry( const wxString& var, int& value, const wxChar* const* enumArray, int defvalue );
163 };
164
165 // ------------------------------------------------------------------------
166 // GCC Note: wxT() macro is required when using string token pasting. For some reason L generates
167 // syntax errors. >_<
168 //
169 #define IniEntry( varname ) ini.Entry( wxT(#varname), varname, defaults.varname )
170 #define IniBitfield( varname ) varname = ini.EntryBitfield( wxT(#varname), varname, defaults.varname )
171 #define IniBitBool( varname ) varname = ini.EntryBitBool( wxT(#varname), !!varname, defaults.varname )
172
173 #define IniBitfieldEx( varname, textname ) varname = ini.EntryBitfield( wxT(textname), varname, defaults.varname )
174 #define IniBitBoolEx( varname, textname ) varname = ini.EntryBitBool( wxT(textname), !!varname, defaults.varname )

  ViewVC Help
Powered by ViewVC 1.1.22