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

  ViewVC Help
Powered by ViewVC 1.1.22