/[pcsx2_0.9.7]/trunk/common/include/Utilities/IniInterface.h
ViewVC logotype

Annotation of /trunk/common/include/Utilities/IniInterface.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 62 - (hide annotations) (download)
Tue Sep 7 11:08:22 2010 UTC (9 years, 11 months ago) by william
File MIME type: text/plain
File size: 7936 byte(s)
Auto Commited Import of: pcsx2-0.9.7-r3738-debug in ./trunk
1 william 62 /* 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 "Path.h"
19     #include "FixedPointTypes.h"
20     #include <wx/config.h>
21    
22     // --------------------------------------------------------------------------------------
23     // IniInterface (abstract base class)
24     // --------------------------------------------------------------------------------------
25     // This is used as an interchangable interface for both loading and saving options from an
26     // ini/configuration file. The LoadSave code takes an IniInterface, and the interface
27     // implementation defines whether the options are read or written.
28     //
29     // See also: IniLoader, IniSaver
30     //
31     class IniInterface
32     {
33     protected:
34     wxConfigBase* m_Config;
35    
36     public:
37     virtual ~IniInterface();
38     explicit IniInterface();
39     explicit IniInterface( wxConfigBase& config );
40     explicit IniInterface( wxConfigBase* config );
41    
42     void SetPath( const wxString& path );
43     void Flush();
44    
45     wxConfigBase& GetConfig() { pxAssume( m_Config ); return *m_Config; }
46     bool IsOk() const { return m_Config != NULL; }
47    
48     virtual bool IsLoading() const=0;
49     bool IsSaving() const { return !IsLoading(); }
50    
51     virtual void Entry( const wxString& var, wxString& value, const wxString& defvalue=wxString() )=0;
52     virtual void Entry( const wxString& var, wxDirName& value, const wxDirName& defvalue=wxDirName() )=0;
53     virtual void Entry( const wxString& var, wxFileName& value, const wxFileName& defvalue=wxFileName() )=0;
54     virtual void Entry( const wxString& var, int& value, const int defvalue=0 )=0;
55     virtual void Entry( const wxString& var, uint& value, const uint defvalue=0 )=0;
56     virtual void Entry( const wxString& var, bool& value, const bool defvalue=false )=0;
57    
58     // This special form of Entry is provided for bitfields, which cannot be passed by reference.
59     virtual bool EntryBitBool( const wxString& var, bool value, const bool defvalue=false )=0;
60     virtual int EntryBitfield( const wxString& var, int value, const int defvalue=0 )=0;
61    
62     virtual void Entry( const wxString& var, Fixed100& value, const Fixed100& defvalue=Fixed100() )=0;
63    
64     virtual void Entry( const wxString& var, wxPoint& value, const wxPoint& defvalue=wxDefaultPosition )=0;
65     virtual void Entry( const wxString& var, wxSize& value, const wxSize& defvalue=wxDefaultSize )=0;
66     virtual void Entry( const wxString& var, wxRect& value, const wxRect& defvalue=wxDefaultRect )=0;
67    
68     template< typename T >
69     void EnumEntry( const wxString& var, T& value, const wxChar* const* enumArray=NULL, const T defvalue=(T)0 )
70     {
71     int tstore = (int)value;
72     if( enumArray == NULL )
73     Entry( var, tstore, defvalue );
74     else
75     _EnumEntry( var, tstore, enumArray, defvalue );
76     value = (T)tstore;
77     }
78    
79     protected:
80     virtual void _EnumEntry( const wxString& var, int& value, const wxChar* const* enumArray, int defvalue )=0;
81     };
82    
83     // --------------------------------------------------------------------------------------
84     // ScopedIniGroup
85     // --------------------------------------------------------------------------------------
86     class ScopedIniGroup
87     {
88     protected:
89     IniInterface& m_mom;
90    
91     public:
92     ScopedIniGroup( IniInterface& mommy, const wxString& group );
93     virtual ~ScopedIniGroup();
94     };
95    
96     // --------------------------------------------------------------------------------------
97     // IniLoader
98     // --------------------------------------------------------------------------------------
99     // Implementation of the IniInterface base class, which maps ini actions to loading from
100     // an ini source file.
101     //
102     // See also: IniInterface
103     //
104     class IniLoader : public IniInterface
105     {
106     public:
107     virtual ~IniLoader() throw();
108     explicit IniLoader();
109     explicit IniLoader( wxConfigBase& config );
110     explicit IniLoader( wxConfigBase* config );
111    
112     bool IsLoading() const { return true; }
113    
114     void Entry( const wxString& var, wxString& value, const wxString& defvalue=wxEmptyString );
115     void Entry( const wxString& var, wxDirName& value, const wxDirName& defvalue=wxDirName() );
116     void Entry( const wxString& var, wxFileName& value, const wxFileName& defvalue=wxFileName() );
117     void Entry( const wxString& var, int& value, const int defvalue=0 );
118     void Entry( const wxString& var, uint& value, const uint defvalue=0 );
119     void Entry( const wxString& var, bool& value, const bool defvalue=false );
120    
121     bool EntryBitBool( const wxString& var, bool value, const bool defvalue=false );
122     int EntryBitfield( const wxString& var, int value, const int defvalue=0 );
123    
124     void Entry( const wxString& var, Fixed100& value, const Fixed100& defvalue=Fixed100() );
125    
126     void Entry( const wxString& var, wxPoint& value, const wxPoint& defvalue=wxDefaultPosition );
127     void Entry( const wxString& var, wxSize& value, const wxSize& defvalue=wxDefaultSize );
128     void Entry( const wxString& var, wxRect& value, const wxRect& defvalue=wxDefaultRect );
129    
130     protected:
131     void _EnumEntry( const wxString& var, int& value, const wxChar* const* enumArray, int defvalue );
132     };
133    
134     // --------------------------------------------------------------------------------------
135     // IniSaver
136     // --------------------------------------------------------------------------------------
137     // Implementation of the IniInterface base class, which maps ini actions to saving to
138     // an ini dest file.
139     //
140     // See also: IniInterface
141     //
142     class IniSaver : public IniInterface
143     {
144     public:
145     virtual ~IniSaver();
146     explicit IniSaver();
147     explicit IniSaver( wxConfigBase& config );
148     explicit IniSaver( wxConfigBase* config );
149    
150     bool IsLoading() const { return false; }
151    
152     void Entry( const wxString& var, wxString& value, const wxString& defvalue=wxString() );
153     void Entry( const wxString& var, wxDirName& value, const wxDirName& defvalue=wxDirName() );
154     void Entry( const wxString& var, wxFileName& value, const wxFileName& defvalue=wxFileName() );
155     void Entry( const wxString& var, int& value, const int defvalue=0 );
156     void Entry( const wxString& var, uint& value, const uint defvalue=0 );
157     void Entry( const wxString& var, bool& value, const bool defvalue=false );
158    
159     bool EntryBitBool( const wxString& var, bool value, const bool defvalue=false );
160     int EntryBitfield( const wxString& var, int value, const int defvalue=0 );
161    
162     void Entry( const wxString& var, Fixed100& value, const Fixed100& defvalue=Fixed100() );
163    
164     void Entry( const wxString& var, wxPoint& value, const wxPoint& defvalue=wxDefaultPosition );
165     void Entry( const wxString& var, wxSize& value, const wxSize& defvalue=wxDefaultSize );
166     void Entry( const wxString& var, wxRect& value, const wxRect& defvalue=wxDefaultRect );
167    
168     protected:
169     void _EnumEntry( const wxString& var, int& value, const wxChar* const* enumArray, int defvalue );
170     };
171    
172     // ------------------------------------------------------------------------
173     // GCC Note: wxT() macro is required when using string token pasting. For some reason L generates
174     // syntax errors. >_<
175     //
176     #define IniEntry( varname ) ini.Entry( wxT(#varname), varname, defaults.varname )
177     #define IniBitfield( varname ) varname = ini.EntryBitfield( wxT(#varname), varname, defaults.varname )
178     #define IniBitBool( varname ) varname = ini.EntryBitBool( wxT(#varname), !!varname, defaults.varname )
179    
180     #define IniBitfieldEx( varname, textname ) varname = ini.EntryBitfield( wxT(textname), varname, defaults.varname )
181     #define IniBitBoolEx( varname, textname ) varname = ini.EntryBitBool( wxT(textname), !!varname, defaults.varname )

  ViewVC Help
Powered by ViewVC 1.1.22