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

Contents of /trunk/common/include/Utilities/Dependencies.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 283 - (show annotations) (download)
Thu Dec 23 12:39:52 2010 UTC (9 years, 7 months ago) by william
File MIME type: text/plain
File size: 10364 byte(s)
Auto Commited Import of: pcsx2-0.9.7-DEBUG (upstream: v0.9.7.4132 local: v0.9.7.282-latest) in ./trunk
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 // Dependencies.h : Contains classes required by all Utilities headers.
19 // This file is included by most .h files provided by the Utilities class.
20
21 #include "pxForwardDefs.h"
22
23 // This should prove useful....
24 #define wxsFormat wxString::Format
25
26 #ifdef PCSX2_DEBUG
27 # define tryDEBUG try
28 # define catchDEBUG(clause) catch(clause)
29 #else
30 # define tryDEBUG if(true)
31 # define catchDEBUG(clause) if(false)
32 #endif
33
34 #if defined(PCSX2_DEVBUILD) || defined(PCSX2_DEBUG)
35 # define tryDEVEL try
36 # define catchDEVEL catch(clause)
37 #else
38 # define tryDEBUG if(true)
39 # define catchDEBUG(clause) if(false)
40 #endif
41
42 // --------------------------------------------------------------------------------------
43 // ImplementEnumOperators (macro)
44 // --------------------------------------------------------------------------------------
45 // This macro implements ++/-- operators for any conforming enumeration. In order for an
46 // enum to conform, it must have _FIRST and _COUNT members defined, and must have a full
47 // compliment of sequential members (no custom assignments) --- looking like so:
48 //
49 // enum Dummy {
50 // Dummy_FIRST,
51 // Dummy_Item = Dummy_FIRST,
52 // Dummy_Crap,
53 // Dummy_COUNT
54 // };
55 //
56 // The macro also defines utility functions for bounds checking enumerations:
57 // EnumIsValid(value); // returns TRUE if the enum value is between FIRST and COUNT.
58 // EnumAssert(value);
59 //
60 // It also defines a *prototype* for converting the enumeration to a string. Note that this
61 // method is not implemented! You must implement it yourself if you want to use it:
62 // EnumToString(value);
63 //
64 #define ImplementEnumOperators( enumName ) \
65 static __fi enumName& operator++ ( enumName& src ) { src = (enumName)((int)src+1); return src; } \
66 static __fi enumName& operator-- ( enumName& src ) { src = (enumName)((int)src-1); return src; } \
67 static __fi enumName operator++ ( enumName& src, int ) { enumName orig = src; src = (enumName)((int)src+1); return orig; } \
68 static __fi enumName operator-- ( enumName& src, int ) { enumName orig = src; src = (enumName)((int)src-1); return orig; } \
69 \
70 static __fi bool operator< ( const enumName& left, const pxEnumEnd_t& ) { return (int)left < enumName##_COUNT; } \
71 static __fi bool operator!=( const enumName& left, const pxEnumEnd_t& ) { return (int)left != enumName##_COUNT; } \
72 static __fi bool operator==( const enumName& left, const pxEnumEnd_t& ) { return (int)left == enumName##_COUNT; } \
73 \
74 static __fi bool EnumIsValid( enumName id ) { \
75 return ((int)id >= enumName##_FIRST) && ((int)id < enumName##_COUNT); } \
76 static __fi bool EnumAssert( enumName id ) { \
77 return pxAssert( EnumIsValid(id) ); } \
78 \
79 extern const wxChar* EnumToString( enumName id )
80
81 class pxEnumEnd_t { };
82 static const pxEnumEnd_t pxEnumEnd = {};
83
84 // --------------------------------------------------------------------------------------
85 // DeclareNoncopyableObject
86 // --------------------------------------------------------------------------------------
87 // This macro provides an easy and clean method for ensuring objects are not copyable.
88 // Simply add the macro to the head or tail of your class declaration, and attempts to
89 // copy the class will give you a moderately obtuse compiler error that will have you
90 // scratching your head for 20 minutes.
91 //
92 // (... but that's probably better than having a weird invalid object copy having you
93 // scratch your head for a day).
94 //
95 // Programmer's notes:
96 // * We intentionally do NOT provide implementations for these methods, which should
97 // never be referenced anyway.
98
99 // * I've opted for macro form over multi-inherited class form (Boost style), because
100 // the errors generated by the macro are considerably less voodoo. The Boost-style
101 // The macro reports the exact class that causes the copy failure, while Boost's class
102 // approach just reports an error in whatever "NoncopyableObject" is inherited.
103 //
104 // * This macro is the same as wxWidgets' DECLARE_NO_COPY_CLASS macro. This one is free
105 // of wx dependencies though, and has a nicer typeset. :)
106 //
107 #ifndef DeclareNoncopyableObject
108 # define DeclareNoncopyableObject(classname) \
109 private: \
110 explicit classname(const classname&); \
111 classname& operator=(const classname&)
112 #endif
113
114
115 // --------------------------------------------------------------------------------------
116 // ScopedBool - Makes sure a boolean is set back to FALSE when current scope is left
117 // --------------------------------------------------------------------------------------
118 // Exception-safe way of tracking entry and exit of various functions of execution zones.
119 //
120 class ScopedBool
121 {
122 protected:
123 bool* m_boolme;
124
125 public:
126 ScopedBool(bool& boolme)
127 {
128 boolme = true;
129 m_boolme = &boolme;
130 }
131
132 ~ScopedBool() throw()
133 {
134 *m_boolme = false;
135 }
136 };
137
138 // --------------------------------------------------------------------------------------
139 // _(x) / _t(x) / _d(x) / pxL(x) / pxLt(x) [macros]
140 // --------------------------------------------------------------------------------------
141 // Define pxWex's own i18n helpers. These override the wxWidgets helpers and provide
142 // additional functionality. Define them FIRST THING, to make sure that wx's own gettext
143 // macros aren't in place.
144 //
145 // _ is for standard translations
146 // _t is for tertiary low priority translations
147 // _d is for debug/devel build translations
148
149 #define WXINTL_NO_GETTEXT_MACRO
150
151 #ifndef _
152 # define _(s) pxGetTranslation(_T(s))
153 #endif
154
155 #ifndef _t
156 # define _t(s) pxGetTranslation(_T(s))
157 #endif
158
159 #ifndef _d
160 # define _d(s) pxGetTranslation(_T(s))
161 #endif
162
163 // pxL / pxLt / pxDt -- macros provided for tagging translation strings, without actually running
164 // them through the translator (which the _() does automatically, and sometimes we don't
165 // want that). This is a shorthand replacement for wxTRANSLATE. pxL is a standard translation
166 // moniker. pxLt is for tertiary strings that have a very low translation priority. pxDt is for
167 // debug/devel specific translations.
168 //
169 #ifndef pxL
170 # define pxL(a) wxT(a)
171 #endif
172
173 #ifndef pxLt
174 # define pxLt(a) wxT(a)
175 #endif
176
177 #ifndef pxDt
178 # define pxDt(a) wxT(a)
179 #endif
180
181
182 #include <wx/string.h>
183 #include <wx/intl.h>
184 #include <wx/log.h>
185
186 #include <stdexcept>
187 #include <cstring> // string.h under c++
188 #include <cstdio> // stdio.h under c++
189 #include <cstdlib>
190 #include <vector>
191 #include <list>
192
193 #include "Pcsx2Defs.h"
194
195 // --------------------------------------------------------------------------------------
196 // Handy Human-readable constants for common immediate values (_16kb -> _4gb)
197
198 static const sptr _64kb = 0x10000;
199 static const sptr _16kb = _64kb / 4;
200 static const sptr _128kb = _64kb * 2;
201 static const sptr _256kb = _128kb * 2;
202
203 static const s64 _1mb = 0x100000;
204 static const s64 _8mb = _1mb * 8;
205 static const s64 _16mb = _1mb * 16;
206 static const s64 _32mb = _1mb * 32;
207 static const s64 _64mb = _1mb * 64;
208 static const s64 _256mb = _1mb * 256;
209 static const s64 _1gb = _256mb * 4;
210 static const s64 _4gb = _1gb * 4;
211
212
213 // --------------------------------------------------------------------------------------
214 // pxE(key, msg) and pxEt(key, msg) [macros]
215 // --------------------------------------------------------------------------------------
216 // Translation Feature: pxE is used as a method of dereferencing very long english text
217 // descriptions via a "key" identifier. In this way, the english text can be revised without
218 // it breaking existing translation bindings. Make sure to add pxE to your PO catalog's
219 // source code identifiers, and then reference the source code to see what the current
220 // english version is.
221 //
222 // Valid prefix types:
223 //
224 // !Panel: Key-based translation of a panel or dialog text; usually either a header or
225 // checkbox description, by may also include some controls with long labels.
226 // These have the highest translation priority.
227 //
228 // !Notice: Key-based translation of a popup dialog box; either a notice, confirmation,
229 // or error. These typically have very high translation priority (roughly equal
230 // or slightly less than pxE_Panel).
231 //
232 // !Tooltip: Key-based translation of a tooltip for a button on a tool bar. Since buttons are
233 // rarely self-explanatory, these translations are considered medium to high priority.
234 //
235 // !Wizard Key-based translation of a heading, checkbox item, description, or other text
236 // associated with the First-time wizard. Translation of these items is considered
237 // lower-priority to most other messages; but equal or higher priority to ContextTips.
238 //
239 // !ContextTip: Key-based translation of a tooltip for a control on a dialog/panel. Translation
240 // of these items is typically considered "lowest priority" as they usually provide
241 // only tertiary (extra) info to the user.
242 //
243
244 #define pxE(key, english) pxExpandMsg( wxT(key), english )
245
246 // For use with tertiary translations (low priority).
247 #define pxEt(key, english) pxExpandMsg( wxT(key), english )
248
249 // For use with Dev/debug build translations (low priority).
250 #define pxE_dev(key, english) pxExpandMsg( wxT(key), english )
251
252
253 extern const wxChar* __fastcall pxExpandMsg( const wxChar* key, const wxChar* englishContent );
254 extern const wxChar* __fastcall pxGetTranslation( const wxChar* message );
255 extern bool pxIsEnglish( int id );
256
257 extern wxString fromUTF8( const char* src );
258 extern wxString fromAscii( const char* src );
259
260
261 #include "Utilities/Assertions.h"
262 #include "Utilities/Exceptions.h"
263 #include "Utilities/ScopedPtr.h"
264 #include "Utilities/ScopedAlloc.h"

  ViewVC Help
Powered by ViewVC 1.1.22