]>
Commit | Line | Data |
---|---|---|
c9f78968 VS |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/strvararg.h | |
3 | // Purpose: macros for implementing type-safe vararg passing of strings | |
4 | // Author: Vaclav Slavik | |
5 | // Created: 2007-02-19 | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) 2007 REA Elektronik GmbH | |
8 | // Licence: wxWindows licence | |
9 | /////////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifndef _WX_STRVARARG_H_ | |
12 | #define _WX_STRVARARG_H_ | |
13 | ||
14 | #include "wx/platform.h" | |
15 | #if wxONLY_WATCOM_EARLIER_THAN(1,4) | |
16 | #error "OpenWatcom version >= 1.4 is required to compile this code" | |
17 | #endif | |
18 | ||
2523e9b7 | 19 | #include "wx/cpp.h" |
e3f6cbd9 | 20 | #include "wx/chartype.h" |
2523e9b7 VS |
21 | #include "wx/strconv.h" |
22 | #include "wx/buffer.h" | |
24d68c95 | 23 | #include "wx/unichar.h" |
c9f78968 VS |
24 | |
25 | class WXDLLIMPEXP_BASE wxCStrData; | |
26 | class WXDLLIMPEXP_BASE wxString; | |
c9f78968 VS |
27 | |
28 | // ---------------------------------------------------------------------------- | |
29 | // WX_DEFINE_VARARG_FUNC* macros | |
30 | // ---------------------------------------------------------------------------- | |
31 | ||
32 | // This macro is used to implement type-safe wrappers for variadic functions | |
33 | // that accept strings as arguments. This makes it possible to pass char*, | |
34 | // wchar_t* or even wxString (as opposed to having to use wxString::c_str()) | |
35 | // to e.g. wxPrintf(). | |
36 | // | |
37 | // This is done by defining a set of N template function taking 1..N arguments | |
38 | // (currently, N is set to 30 in this header). These functions are just thin | |
2523e9b7 VS |
39 | // wrappers around another variadic function ('impl' or 'implUtf8' arguments, |
40 | // see below) and the only thing the wrapper does is that it normalizes the | |
41 | // arguments passed in so that they are of the type expected by variadic | |
42 | // functions taking string arguments, i.e., char* or wchar_t*, depending on the | |
43 | // build: | |
c9f78968 | 44 | // * char* in the current locale's charset in ANSI build |
2523e9b7 VS |
45 | // * char* with UTF-8 encoding if wxUSE_UNICODE_UTF8 and the app is running |
46 | // under an UTF-8 locale | |
47 | // * wchar_t* if wxUSE_UNICODE_WCHAR or if wxUSE_UNICODE_UTF8 and the current | |
48 | // locale is not UTF-8 | |
c9f78968 VS |
49 | // |
50 | // Parameters: | |
2523e9b7 VS |
51 | // [ there are examples in square brackets showing values of the parameters |
52 | // for the wxFprintf() wrapper for fprintf() function with the following | |
53 | // prototype: | |
54 | // int wxFprintf(FILE *stream, const wxString& format, ...); ] | |
55 | // | |
56 | // rettype Functions' return type [int] | |
57 | // name Name of the function [fprintf] | |
58 | // numfixed The number of leading "fixed" (i.e., not variadic) | |
59 | // arguments of the function (e.g. "stream" and "format" | |
60 | // arguments of fprintf()); their type is _not_ converted | |
61 | // using wxArgNormalizer<T>, unlike the rest of | |
62 | // the function's arguments [2] | |
63 | // fixed List of types of the leading "fixed" arguments, in | |
64 | // parenthesis [(FILE*,const wxString&)] | |
65 | // impl Name of the variadic function that implements 'name' for | |
66 | // the native strings representation (wchar_t* if | |
67 | // wxUSE_UNICODE_WCHAR or wxUSE_UNICODE_UTF8 when running under | |
68 | // non-UTF8 locale, char* in ANSI build) [wxCrt_Fprintf] | |
69 | // implUtf8 Like 'impl', but for the UTF-8 char* version to be used | |
70 | // if wxUSE_UNICODE_UTF8 and running under UTF-8 locale | |
71 | // (ignored otherwise) [fprintf] | |
72 | // | |
d1f6e2cf | 73 | #define WX_DEFINE_VARARG_FUNC(rettype, name, numfixed, fixed, impl, implUtf8) \ |
2523e9b7 | 74 | _WX_VARARG_DEFINE_FUNC_N0(rettype, name, impl, implUtf8, numfixed, fixed) \ |
d1f6e2cf | 75 | WX_DEFINE_VARARG_FUNC_SANS_N0(rettype, name, numfixed, fixed, impl, implUtf8) |
2523e9b7 VS |
76 | |
77 | // ditto, but without the version with 0 template/vararg arguments | |
d1f6e2cf | 78 | #define WX_DEFINE_VARARG_FUNC_SANS_N0(rettype, name, \ |
2523e9b7 VS |
79 | numfixed, fixed, impl, implUtf8) \ |
80 | _WX_VARARG_ITER(_WX_VARARG_MAX_ARGS, \ | |
81 | _WX_VARARG_DEFINE_FUNC, \ | |
82 | rettype, name, impl, implUtf8, numfixed, fixed) | |
83 | ||
d1f6e2cf | 84 | // Like WX_DEFINE_VARARG_FUNC, but for variadic functions that don't return |
c9f78968 | 85 | // a value. |
d1f6e2cf | 86 | #define WX_DEFINE_VARARG_FUNC_VOID(name, numfixed, fixed, impl, implUtf8) \ |
2523e9b7 VS |
87 | _WX_VARARG_DEFINE_FUNC_VOID_N0(name, impl, implUtf8, numfixed, fixed) \ |
88 | _WX_VARARG_ITER(_WX_VARARG_MAX_ARGS, \ | |
89 | _WX_VARARG_DEFINE_FUNC_VOID, \ | |
90 | void, name, impl, implUtf8, numfixed, fixed) | |
91 | ||
c9f78968 VS |
92 | // Like WX_DEFINE_VARARG_FUNC_VOID, but instead of wrapping an implementation |
93 | // function, does nothing in defined functions' bodies. | |
94 | // | |
95 | // Used to implement wxLogXXX functions if wxUSE_LOG=0. | |
2523e9b7 VS |
96 | #define WX_DEFINE_VARARG_FUNC_NOP(name, numfixed, fixed) \ |
97 | _WX_VARARG_DEFINE_FUNC_NOP_N0(name, numfixed, fixed) \ | |
98 | _WX_VARARG_ITER(_WX_VARARG_MAX_ARGS, \ | |
99 | _WX_VARARG_DEFINE_FUNC_NOP, \ | |
82e77a80 | 100 | void, name, dummy, dummy, numfixed, fixed) |
2523e9b7 VS |
101 | |
102 | // Like WX_DEFINE_VARARG_FUNC_CTOR, but for defining template constructors | |
d1f6e2cf VS |
103 | #define WX_DEFINE_VARARG_FUNC_CTOR(name, numfixed, fixed, impl, implUtf8) \ |
104 | _WX_VARARG_DEFINE_FUNC_CTOR_N0(name, impl, implUtf8, numfixed, fixed) \ | |
2523e9b7 VS |
105 | _WX_VARARG_ITER(_WX_VARARG_MAX_ARGS, \ |
106 | _WX_VARARG_DEFINE_FUNC_CTOR, \ | |
d1f6e2cf | 107 | void, name, impl, implUtf8, numfixed, fixed) |
c9f78968 | 108 | |
1528e0b8 VS |
109 | |
110 | // ---------------------------------------------------------------------------- | |
111 | // wxFormatString | |
112 | // ---------------------------------------------------------------------------- | |
113 | ||
114 | // This class should be used for format string argument of the functions | |
115 | // defined using WX_DEFINE_VARARG_FUNC_* macros. It converts the string to | |
116 | // char* or wchar_t* for passing to implementation function efficiently (i.e. | |
117 | // without keeping the converted string in memory for longer than necessary, | |
118 | // like c_str()) | |
119 | // | |
120 | // Note that this class can _only_ be used for function arguments! | |
121 | class WXDLLIMPEXP_BASE wxFormatString | |
122 | { | |
123 | public: | |
124 | wxFormatString(const char *str) | |
125 | : m_char(wxCharBuffer::CreateNonOwned(str)), m_str(NULL), m_cstr(NULL) {} | |
126 | wxFormatString(const wchar_t *str) | |
127 | : m_wchar(wxWCharBuffer::CreateNonOwned(str)), m_str(NULL), m_cstr(NULL) {} | |
128 | wxFormatString(const wxString& str) | |
129 | : m_str(&str), m_cstr(NULL) {} | |
130 | wxFormatString(const wxCStrData& str) | |
131 | : m_str(NULL), m_cstr(&str) {} | |
132 | wxFormatString(const wxCharBuffer& str) | |
133 | : m_char(str), m_str(NULL), m_cstr(NULL) {} | |
134 | wxFormatString(const wxWCharBuffer& str) | |
135 | : m_wchar(str), m_str(NULL), m_cstr(NULL) {} | |
136 | ||
137 | #if !wxUSE_UNICODE_WCHAR | |
138 | operator const char*() const | |
139 | { return wx_const_cast(wxFormatString*, this)->AsChar(); } | |
140 | private: | |
141 | const char* AsChar(); | |
142 | #endif // !wxUSE_UNICODE_WCHAR | |
143 | ||
144 | #if wxUSE_UNICODE && !wxUSE_UTF8_LOCALE_ONLY | |
4960f9fc | 145 | public: |
1528e0b8 VS |
146 | operator const wchar_t*() const |
147 | { return wx_const_cast(wxFormatString*, this)->AsWChar(); } | |
148 | private: | |
149 | const wchar_t* AsWChar(); | |
150 | #endif // wxUSE_UNICODE && !wxUSE_UTF8_LOCALE_ONLY | |
151 | ||
152 | private: | |
541aa821 VS |
153 | #ifdef __VISUALC__ |
154 | // "struct 'ConvertedBuffer<T>' needs to have dll-interface to be used by | |
155 | // clients of class 'wxString'" - this is private, we don't care | |
156 | #pragma warning (disable:4251) | |
157 | #endif | |
1528e0b8 VS |
158 | wxCharBuffer m_char; |
159 | wxWCharBuffer m_wchar; | |
541aa821 VS |
160 | #ifdef __VISUALC__ |
161 | #pragma warning (default:4251) | |
162 | #endif | |
163 | ||
1528e0b8 VS |
164 | // NB: we can use a pointer here, because wxFormatString is only used |
165 | // as function argument, so it has shorter life than the string | |
166 | // passed to the ctor | |
167 | const wxString * const m_str; | |
168 | const wxCStrData * const m_cstr; | |
169 | ||
170 | DECLARE_NO_COPY_CLASS(wxFormatString) | |
171 | }; | |
172 | ||
c9f78968 | 173 | // ---------------------------------------------------------------------------- |
2523e9b7 | 174 | // wxArgNormalizer*<T> converters |
c9f78968 VS |
175 | // ---------------------------------------------------------------------------- |
176 | ||
177 | // Converts an argument passed to wxPrint etc. into standard form expected, | |
178 | // by wxXXX functions, e.g. all strings (wxString, char*, wchar_t*) are | |
179 | // converted into wchar_t* or char* depending on the build. | |
180 | template<typename T> | |
181 | struct wxArgNormalizer | |
182 | { | |
183 | wxArgNormalizer(const T& value) : m_value(value) {} | |
184 | ||
185 | // Returns the value in a form that can be safely passed to real vararg | |
186 | // functions. In case of strings, this is char* in ANSI build and wchar_t* | |
187 | // in Unicode build. | |
c9afb3cb | 188 | T get() const { return m_value; } |
c9f78968 | 189 | |
c9afb3cb | 190 | T m_value; |
c9f78968 VS |
191 | }; |
192 | ||
2523e9b7 VS |
193 | // normalizer for passing arguments to functions working with wchar_t* (and |
194 | // until ANSI build is removed, char* in ANSI build as well - FIXME-UTF8) | |
195 | // string representation | |
196 | #if !wxUSE_UTF8_LOCALE_ONLY | |
197 | template<typename T> | |
198 | struct wxArgNormalizerWchar : public wxArgNormalizer<T> | |
199 | { | |
200 | wxArgNormalizerWchar(const T& value) : wxArgNormalizer<T>(value) {} | |
201 | }; | |
202 | #endif // !wxUSE_UTF8_LOCALE_ONLY | |
203 | ||
204 | // normalizer for passing arguments to functions working with UTF-8 encoded | |
205 | // char* strings | |
206 | #if wxUSE_UNICODE_UTF8 | |
207 | template<typename T> | |
208 | struct wxArgNormalizerUtf8 : public wxArgNormalizer<T> | |
209 | { | |
210 | wxArgNormalizerUtf8(const T& value) : wxArgNormalizer<T>(value) {} | |
211 | }; | |
212 | ||
213 | #define wxArgNormalizerNative wxArgNormalizerUtf8 | |
214 | #else // wxUSE_UNICODE_WCHAR | |
215 | #define wxArgNormalizerNative wxArgNormalizerWchar | |
216 | #endif // wxUSE_UNICODE_UTF8 // wxUSE_UNICODE_UTF8 | |
217 | ||
218 | ||
219 | ||
c9f78968 VS |
220 | // special cases for converting strings: |
221 | ||
2523e9b7 VS |
222 | |
223 | // base class for wxArgNormalizer<T> specializations that need to do conversion; | |
224 | // CharType is either wxStringCharType or wchar_t in UTF-8 build when wrapping | |
225 | // widechar CRT function | |
226 | template<typename CharType> | |
227 | struct wxArgNormalizerWithBuffer | |
c9f78968 | 228 | { |
2523e9b7 | 229 | typedef wxCharTypeBuffer<CharType> CharBuffer; |
c9f78968 | 230 | |
2523e9b7 VS |
231 | wxArgNormalizerWithBuffer() {} |
232 | wxArgNormalizerWithBuffer(const CharBuffer& buf) : m_value(buf) {} | |
c9f78968 | 233 | |
2523e9b7 VS |
234 | const CharType *get() const { return m_value; } |
235 | ||
236 | CharBuffer m_value; | |
c9f78968 VS |
237 | }; |
238 | ||
2523e9b7 | 239 | // string objects: |
c9f78968 | 240 | template<> |
2523e9b7 | 241 | struct WXDLLIMPEXP_BASE wxArgNormalizerNative<const wxString&> |
c9f78968 | 242 | { |
2523e9b7 VS |
243 | wxArgNormalizerNative(const wxString& s) : m_value(s) {} |
244 | const wxStringCharType *get() const; | |
c9f78968 VS |
245 | |
246 | const wxString& m_value; | |
247 | }; | |
248 | ||
2523e9b7 | 249 | // c_str() values: |
c9f78968 | 250 | template<> |
2523e9b7 | 251 | struct WXDLLIMPEXP_BASE wxArgNormalizerNative<const wxCStrData&> |
c9f78968 | 252 | { |
2523e9b7 VS |
253 | wxArgNormalizerNative(const wxCStrData& value) : m_value(value) {} |
254 | const wxStringCharType *get() const; | |
255 | ||
256 | const wxCStrData& m_value; | |
c9f78968 VS |
257 | }; |
258 | ||
2523e9b7 VS |
259 | // wxString/wxCStrData conversion to wchar_t* value |
260 | #if wxUSE_UNICODE_UTF8 && !wxUSE_UTF8_LOCALE_ONLY | |
c9f78968 | 261 | template<> |
2523e9b7 VS |
262 | struct WXDLLIMPEXP_BASE wxArgNormalizerWchar<const wxString&> |
263 | : public wxArgNormalizerWithBuffer<wchar_t> | |
c9f78968 | 264 | { |
2523e9b7 | 265 | wxArgNormalizerWchar(const wxString& s); |
c9f78968 VS |
266 | }; |
267 | ||
268 | template<> | |
2523e9b7 VS |
269 | struct WXDLLIMPEXP_BASE wxArgNormalizerWchar<const wxCStrData&> |
270 | : public wxArgNormalizerWithBuffer<wchar_t> | |
c9f78968 | 271 | { |
2523e9b7 | 272 | wxArgNormalizerWchar(const wxCStrData& s); |
c9f78968 | 273 | }; |
2523e9b7 VS |
274 | #endif // wxUSE_UNICODE_UTF8 && !wxUSE_UTF8_LOCALE_ONLY |
275 | ||
276 | ||
277 | // C string pointers of the wrong type (wchar_t* for ANSI or UTF8 build, | |
278 | // char* for wchar_t Unicode build or UTF8): | |
279 | #if wxUSE_UNICODE_WCHAR | |
81727065 | 280 | |
81727065 | 281 | template<> |
2523e9b7 VS |
282 | struct wxArgNormalizerWchar<const char*> |
283 | : public wxArgNormalizerWithBuffer<wchar_t> | |
81727065 | 284 | { |
2523e9b7 VS |
285 | wxArgNormalizerWchar(const char* s) |
286 | : wxArgNormalizerWithBuffer<wchar_t>(wxConvLibc.cMB2WC(s)) {} | |
81727065 | 287 | }; |
c9f78968 | 288 | |
2523e9b7 VS |
289 | #elif wxUSE_UNICODE_UTF8 |
290 | ||
81727065 | 291 | template<> |
2523e9b7 VS |
292 | struct wxArgNormalizerUtf8<const wchar_t*> |
293 | : public wxArgNormalizerWithBuffer<char> | |
81727065 | 294 | { |
2523e9b7 VS |
295 | wxArgNormalizerUtf8(const wchar_t* s) |
296 | : wxArgNormalizerWithBuffer<char>(wxConvUTF8.cWC2MB(s)) {} | |
81727065 | 297 | }; |
c9f78968 VS |
298 | |
299 | template<> | |
2523e9b7 VS |
300 | struct wxArgNormalizerUtf8<const char*> |
301 | : public wxArgNormalizerWithBuffer<char> | |
c9f78968 | 302 | { |
2523e9b7 VS |
303 | wxArgNormalizerUtf8(const char* s) |
304 | { | |
f461887a VS |
305 | if ( wxLocaleIsUtf8 ) |
306 | { | |
307 | m_value = wxCharBuffer::CreateNonOwned(s); | |
308 | } | |
309 | else | |
310 | { | |
311 | // convert to widechar string first: | |
312 | wxWCharBuffer buf(wxConvLibc.cMB2WC(s)); | |
313 | ||
314 | // then to UTF-8: | |
315 | if ( buf ) | |
316 | m_value = wxConvUTF8.cWC2MB(buf); | |
317 | } | |
2523e9b7 | 318 | } |
c9f78968 VS |
319 | }; |
320 | ||
2523e9b7 VS |
321 | // UTF-8 build needs conversion to wchar_t* too: |
322 | #if !wxUSE_UTF8_LOCALE_ONLY | |
c9f78968 | 323 | template<> |
2523e9b7 VS |
324 | struct wxArgNormalizerWchar<const char*> |
325 | : public wxArgNormalizerWithBuffer<wchar_t> | |
c9f78968 | 326 | { |
2523e9b7 VS |
327 | wxArgNormalizerWchar(const char* s) |
328 | : wxArgNormalizerWithBuffer<wchar_t>(wxConvLibc.cMB2WC(s)) {} | |
c9f78968 | 329 | }; |
2523e9b7 VS |
330 | #endif // !wxUSE_UTF8_LOCALE_ONLY |
331 | ||
332 | #else // ANSI - FIXME-UTF8 | |
c9f78968 | 333 | |
359bd4d1 | 334 | template<> |
2523e9b7 VS |
335 | struct wxArgNormalizerWchar<const wchar_t*> |
336 | : public wxArgNormalizerWithBuffer<char> | |
359bd4d1 | 337 | { |
2523e9b7 VS |
338 | wxArgNormalizerWchar(const wchar_t* s) |
339 | : wxArgNormalizerWithBuffer<char>(wxConvLibc.cWC2MB(s)) {} | |
359bd4d1 VS |
340 | }; |
341 | ||
2523e9b7 VS |
342 | #endif // wxUSE_UNICODE_WCHAR/wxUSE_UNICODE_UTF8/ANSI |
343 | ||
344 | ||
345 | // this macro is used to implement specialization that are exactly same as | |
346 | // some other specialization, i.e. to "forward" the implementation (e.g. for | |
347 | // T=wxString and T=const wxString&). Note that the ctor takes BaseT argument, | |
348 | // not T! | |
349 | #if wxUSE_UNICODE_UTF8 | |
350 | #if wxUSE_UTF8_LOCALE_ONLY | |
351 | #define WX_ARG_NORMALIZER_FORWARD(T, BaseT) \ | |
352 | _WX_ARG_NORMALIZER_FORWARD_IMPL(wxArgNormalizerUtf8, T, BaseT) | |
353 | #else // possibly non-UTF8 locales | |
354 | #define WX_ARG_NORMALIZER_FORWARD(T, BaseT) \ | |
355 | _WX_ARG_NORMALIZER_FORWARD_IMPL(wxArgNormalizerWchar, T, BaseT); \ | |
356 | _WX_ARG_NORMALIZER_FORWARD_IMPL(wxArgNormalizerUtf8, T, BaseT) | |
357 | #endif | |
358 | #else // wxUSE_UNICODE_WCHAR | |
359 | #define WX_ARG_NORMALIZER_FORWARD(T, BaseT) \ | |
360 | _WX_ARG_NORMALIZER_FORWARD_IMPL(wxArgNormalizerWchar, T, BaseT) | |
361 | #endif // wxUSE_UNICODE_UTF8/wxUSE_UNICODE_WCHAR | |
362 | ||
363 | #define _WX_ARG_NORMALIZER_FORWARD_IMPL(Normalizer, T, BaseT) \ | |
364 | template<> \ | |
365 | struct Normalizer<T> : public Normalizer<BaseT> \ | |
366 | { \ | |
367 | Normalizer(BaseT value) : Normalizer<BaseT>(value) {} \ | |
368 | } | |
369 | ||
370 | // non-reference versions of specializations for string objects | |
371 | WX_ARG_NORMALIZER_FORWARD(wxString, const wxString&); | |
372 | WX_ARG_NORMALIZER_FORWARD(wxCStrData, const wxCStrData&); | |
373 | ||
374 | // versions for passing non-const pointers: | |
375 | WX_ARG_NORMALIZER_FORWARD(char*, const char*); | |
376 | WX_ARG_NORMALIZER_FORWARD(wchar_t*, const wchar_t*); | |
377 | ||
378 | // versions for passing wx[W]CharBuffer: | |
379 | WX_ARG_NORMALIZER_FORWARD(wxCharBuffer, const char*); | |
380 | WX_ARG_NORMALIZER_FORWARD(const wxCharBuffer&, const char*); | |
381 | WX_ARG_NORMALIZER_FORWARD(wxWCharBuffer, const wchar_t*); | |
382 | WX_ARG_NORMALIZER_FORWARD(const wxWCharBuffer&, const wchar_t*); | |
383 | ||
564a5bbe VS |
384 | // versions for std::[w]string: |
385 | #if wxUSE_STD_STRING | |
386 | ||
387 | #include "wx/stringimpl.h" | |
388 | ||
389 | #if !wxUSE_UTF8_LOCALE_ONLY | |
390 | template<> | |
391 | struct wxArgNormalizerWchar<const std::string&> | |
392 | : public wxArgNormalizerWchar<const char*> | |
393 | { | |
394 | wxArgNormalizerWchar(const std::string& s) | |
395 | : wxArgNormalizerWchar<const char*>(s.c_str()) {} | |
396 | }; | |
397 | ||
398 | template<> | |
399 | struct wxArgNormalizerWchar<const wxStdWideString&> | |
400 | : public wxArgNormalizerWchar<const wchar_t*> | |
401 | { | |
402 | wxArgNormalizerWchar(const wxStdWideString& s) | |
403 | : wxArgNormalizerWchar<const wchar_t*>(s.c_str()) {} | |
404 | }; | |
405 | #endif // !wxUSE_UTF8_LOCALE_ONLY | |
406 | ||
407 | #if wxUSE_UNICODE_UTF8 | |
408 | template<> | |
409 | struct wxArgNormalizerUtf8<const std::string&> | |
410 | : public wxArgNormalizerUtf8<const char*> | |
411 | { | |
412 | wxArgNormalizerUtf8(const std::string& s) | |
413 | : wxArgNormalizerUtf8<const char*>(s.c_str()) {} | |
414 | }; | |
415 | ||
416 | template<> | |
417 | struct wxArgNormalizerUtf8<const wxStdWideString&> | |
418 | : public wxArgNormalizerUtf8<const wchar_t*> | |
419 | { | |
420 | wxArgNormalizerUtf8(const wxStdWideString& s) | |
421 | : wxArgNormalizerUtf8<const wchar_t*>(s.c_str()) {} | |
422 | }; | |
423 | #endif // wxUSE_UNICODE_UTF8 | |
424 | ||
425 | WX_ARG_NORMALIZER_FORWARD(std::string, const std::string&); | |
426 | WX_ARG_NORMALIZER_FORWARD(wxStdWideString, const wxStdWideString&); | |
427 | ||
428 | #endif // wxUSE_STD_STRING | |
429 | ||
430 | ||
24d68c95 VS |
431 | // versions for wxUniChar, wxUniCharRef: |
432 | ||
433 | #if !wxUSE_UTF8_LOCALE_ONLY | |
434 | template<> | |
435 | struct wxArgNormalizerWchar<const wxUniChar&> | |
436 | : public wxArgNormalizerWchar<wxChar/*FIXME-UTF8: should be wchar_t after ANSI removal*/> | |
437 | { | |
438 | wxArgNormalizerWchar(const wxUniChar& s) | |
439 | : wxArgNormalizerWchar<wxChar>((wxChar)s) {} | |
440 | }; | |
441 | #endif // !wxUSE_UTF8_LOCALE_ONLY | |
442 | ||
443 | #if wxUSE_UNICODE_UTF8 | |
444 | template<> | |
445 | struct wxArgNormalizerUtf8<const wxUniChar&> | |
446 | : public wxArgNormalizerUtf8<char> | |
447 | { | |
448 | wxArgNormalizerUtf8(const wxUniChar& s) | |
449 | // FIXME-UTF8: this is lossy, we need to convert to string, but that | |
450 | // requires format string update | |
451 | : wxArgNormalizerUtf8<char>((const char)s) {} | |
452 | }; | |
453 | #endif // wxUSE_UNICODE_UTF8 | |
454 | ||
455 | WX_ARG_NORMALIZER_FORWARD(wxUniChar, const wxUniChar&); | |
456 | WX_ARG_NORMALIZER_FORWARD(const wxUniCharRef&, const wxUniChar&); | |
457 | WX_ARG_NORMALIZER_FORWARD(wxUniCharRef, const wxUniChar&); | |
458 | ||
459 | ||
2523e9b7 VS |
460 | #undef WX_ARG_NORMALIZER_FORWARD |
461 | #undef _WX_ARG_NORMALIZER_FORWARD_IMPL | |
462 | ||
463 | // ---------------------------------------------------------------------------- | |
464 | // WX_VA_ARG_STRING | |
465 | // ---------------------------------------------------------------------------- | |
466 | ||
467 | // Replacement for va_arg() for use with strings in functions that accept | |
468 | // strings normalized by wxArgNormalizer<T>: | |
469 | ||
470 | struct WXDLLIMPEXP_BASE wxArgNormalizedString | |
359bd4d1 | 471 | { |
2523e9b7 VS |
472 | wxArgNormalizedString(const void* ptr) : m_ptr(ptr) {} |
473 | ||
474 | // returns true if non-NULL string was passed in | |
475 | bool IsValid() const { return m_ptr != NULL; } | |
476 | operator bool() const { return IsValid(); } | |
477 | ||
478 | // extracts the string, returns empty string if NULL was passed in | |
479 | wxString GetString() const; | |
480 | operator wxString() const; | |
481 | ||
482 | private: | |
483 | const void *m_ptr; | |
359bd4d1 VS |
484 | }; |
485 | ||
2523e9b7 | 486 | #define WX_VA_ARG_STRING(ap) wxArgNormalizedString(va_arg(ap, const void*)) |
359bd4d1 | 487 | |
2523e9b7 VS |
488 | // ---------------------------------------------------------------------------- |
489 | // implementation of the WX_DEFINE_VARARG_* macros | |
490 | // ---------------------------------------------------------------------------- | |
359bd4d1 | 491 | |
2523e9b7 VS |
492 | // NB: The vararg emulation code is limited to 30 variadic and 4 fixed |
493 | // arguments at the moment. | |
494 | // If you need more variadic arguments, you need to | |
c9f78968 VS |
495 | // 1) increase the value of _WX_VARARG_MAX_ARGS |
496 | // 2) add _WX_VARARG_JOIN_* and _WX_VARARG_ITER_* up to the new | |
497 | // _WX_VARARG_MAX_ARGS value to the lists below | |
2523e9b7 VS |
498 | // If you need more fixed arguments, you need to |
499 | // 1) increase the value of _WX_VARARG_MAX_FIXED_ARGS | |
500 | // 2) add _WX_VARARG_FIXED_EXPAND_* and _WX_VARARG_FIXED_UNUSED_EXPAND_* | |
501 | // macros below | |
c9f78968 | 502 | #define _WX_VARARG_MAX_ARGS 30 |
2523e9b7 | 503 | #define _WX_VARARG_MAX_FIXED_ARGS 4 |
c9f78968 VS |
504 | |
505 | #define _WX_VARARG_JOIN_1(m) m(1) | |
506 | #define _WX_VARARG_JOIN_2(m) _WX_VARARG_JOIN_1(m), m(2) | |
507 | #define _WX_VARARG_JOIN_3(m) _WX_VARARG_JOIN_2(m), m(3) | |
508 | #define _WX_VARARG_JOIN_4(m) _WX_VARARG_JOIN_3(m), m(4) | |
509 | #define _WX_VARARG_JOIN_5(m) _WX_VARARG_JOIN_4(m), m(5) | |
510 | #define _WX_VARARG_JOIN_6(m) _WX_VARARG_JOIN_5(m), m(6) | |
511 | #define _WX_VARARG_JOIN_7(m) _WX_VARARG_JOIN_6(m), m(7) | |
512 | #define _WX_VARARG_JOIN_8(m) _WX_VARARG_JOIN_7(m), m(8) | |
513 | #define _WX_VARARG_JOIN_9(m) _WX_VARARG_JOIN_8(m), m(9) | |
514 | #define _WX_VARARG_JOIN_10(m) _WX_VARARG_JOIN_9(m), m(10) | |
515 | #define _WX_VARARG_JOIN_11(m) _WX_VARARG_JOIN_10(m), m(11) | |
516 | #define _WX_VARARG_JOIN_12(m) _WX_VARARG_JOIN_11(m), m(12) | |
517 | #define _WX_VARARG_JOIN_13(m) _WX_VARARG_JOIN_12(m), m(13) | |
518 | #define _WX_VARARG_JOIN_14(m) _WX_VARARG_JOIN_13(m), m(14) | |
519 | #define _WX_VARARG_JOIN_15(m) _WX_VARARG_JOIN_14(m), m(15) | |
520 | #define _WX_VARARG_JOIN_16(m) _WX_VARARG_JOIN_15(m), m(16) | |
521 | #define _WX_VARARG_JOIN_17(m) _WX_VARARG_JOIN_16(m), m(17) | |
522 | #define _WX_VARARG_JOIN_18(m) _WX_VARARG_JOIN_17(m), m(18) | |
523 | #define _WX_VARARG_JOIN_19(m) _WX_VARARG_JOIN_18(m), m(19) | |
524 | #define _WX_VARARG_JOIN_20(m) _WX_VARARG_JOIN_19(m), m(20) | |
525 | #define _WX_VARARG_JOIN_21(m) _WX_VARARG_JOIN_20(m), m(21) | |
526 | #define _WX_VARARG_JOIN_22(m) _WX_VARARG_JOIN_21(m), m(22) | |
527 | #define _WX_VARARG_JOIN_23(m) _WX_VARARG_JOIN_22(m), m(23) | |
528 | #define _WX_VARARG_JOIN_24(m) _WX_VARARG_JOIN_23(m), m(24) | |
529 | #define _WX_VARARG_JOIN_25(m) _WX_VARARG_JOIN_24(m), m(25) | |
530 | #define _WX_VARARG_JOIN_26(m) _WX_VARARG_JOIN_25(m), m(26) | |
531 | #define _WX_VARARG_JOIN_27(m) _WX_VARARG_JOIN_26(m), m(27) | |
532 | #define _WX_VARARG_JOIN_28(m) _WX_VARARG_JOIN_27(m), m(28) | |
533 | #define _WX_VARARG_JOIN_29(m) _WX_VARARG_JOIN_28(m), m(29) | |
534 | #define _WX_VARARG_JOIN_30(m) _WX_VARARG_JOIN_29(m), m(30) | |
535 | ||
2523e9b7 VS |
536 | #define _WX_VARARG_ITER_1(m,a,b,c,d,e,f) m(1,a,b,c,d,e,f) |
537 | #define _WX_VARARG_ITER_2(m,a,b,c,d,e,f) _WX_VARARG_ITER_1(m,a,b,c,d,e,f) m(2,a,b,c,d,e,f) | |
538 | #define _WX_VARARG_ITER_3(m,a,b,c,d,e,f) _WX_VARARG_ITER_2(m,a,b,c,d,e,f) m(3,a,b,c,d,e,f) | |
539 | #define _WX_VARARG_ITER_4(m,a,b,c,d,e,f) _WX_VARARG_ITER_3(m,a,b,c,d,e,f) m(4,a,b,c,d,e,f) | |
540 | #define _WX_VARARG_ITER_5(m,a,b,c,d,e,f) _WX_VARARG_ITER_4(m,a,b,c,d,e,f) m(5,a,b,c,d,e,f) | |
541 | #define _WX_VARARG_ITER_6(m,a,b,c,d,e,f) _WX_VARARG_ITER_5(m,a,b,c,d,e,f) m(6,a,b,c,d,e,f) | |
542 | #define _WX_VARARG_ITER_7(m,a,b,c,d,e,f) _WX_VARARG_ITER_6(m,a,b,c,d,e,f) m(7,a,b,c,d,e,f) | |
543 | #define _WX_VARARG_ITER_8(m,a,b,c,d,e,f) _WX_VARARG_ITER_7(m,a,b,c,d,e,f) m(8,a,b,c,d,e,f) | |
544 | #define _WX_VARARG_ITER_9(m,a,b,c,d,e,f) _WX_VARARG_ITER_8(m,a,b,c,d,e,f) m(9,a,b,c,d,e,f) | |
545 | #define _WX_VARARG_ITER_10(m,a,b,c,d,e,f) _WX_VARARG_ITER_9(m,a,b,c,d,e,f) m(10,a,b,c,d,e,f) | |
546 | #define _WX_VARARG_ITER_11(m,a,b,c,d,e,f) _WX_VARARG_ITER_10(m,a,b,c,d,e,f) m(11,a,b,c,d,e,f) | |
547 | #define _WX_VARARG_ITER_12(m,a,b,c,d,e,f) _WX_VARARG_ITER_11(m,a,b,c,d,e,f) m(12,a,b,c,d,e,f) | |
548 | #define _WX_VARARG_ITER_13(m,a,b,c,d,e,f) _WX_VARARG_ITER_12(m,a,b,c,d,e,f) m(13,a,b,c,d,e,f) | |
549 | #define _WX_VARARG_ITER_14(m,a,b,c,d,e,f) _WX_VARARG_ITER_13(m,a,b,c,d,e,f) m(14,a,b,c,d,e,f) | |
550 | #define _WX_VARARG_ITER_15(m,a,b,c,d,e,f) _WX_VARARG_ITER_14(m,a,b,c,d,e,f) m(15,a,b,c,d,e,f) | |
551 | #define _WX_VARARG_ITER_16(m,a,b,c,d,e,f) _WX_VARARG_ITER_15(m,a,b,c,d,e,f) m(16,a,b,c,d,e,f) | |
552 | #define _WX_VARARG_ITER_17(m,a,b,c,d,e,f) _WX_VARARG_ITER_16(m,a,b,c,d,e,f) m(17,a,b,c,d,e,f) | |
553 | #define _WX_VARARG_ITER_18(m,a,b,c,d,e,f) _WX_VARARG_ITER_17(m,a,b,c,d,e,f) m(18,a,b,c,d,e,f) | |
554 | #define _WX_VARARG_ITER_19(m,a,b,c,d,e,f) _WX_VARARG_ITER_18(m,a,b,c,d,e,f) m(19,a,b,c,d,e,f) | |
555 | #define _WX_VARARG_ITER_20(m,a,b,c,d,e,f) _WX_VARARG_ITER_19(m,a,b,c,d,e,f) m(20,a,b,c,d,e,f) | |
556 | #define _WX_VARARG_ITER_21(m,a,b,c,d,e,f) _WX_VARARG_ITER_20(m,a,b,c,d,e,f) m(21,a,b,c,d,e,f) | |
557 | #define _WX_VARARG_ITER_22(m,a,b,c,d,e,f) _WX_VARARG_ITER_21(m,a,b,c,d,e,f) m(22,a,b,c,d,e,f) | |
558 | #define _WX_VARARG_ITER_23(m,a,b,c,d,e,f) _WX_VARARG_ITER_22(m,a,b,c,d,e,f) m(23,a,b,c,d,e,f) | |
559 | #define _WX_VARARG_ITER_24(m,a,b,c,d,e,f) _WX_VARARG_ITER_23(m,a,b,c,d,e,f) m(24,a,b,c,d,e,f) | |
560 | #define _WX_VARARG_ITER_25(m,a,b,c,d,e,f) _WX_VARARG_ITER_24(m,a,b,c,d,e,f) m(25,a,b,c,d,e,f) | |
561 | #define _WX_VARARG_ITER_26(m,a,b,c,d,e,f) _WX_VARARG_ITER_25(m,a,b,c,d,e,f) m(26,a,b,c,d,e,f) | |
562 | #define _WX_VARARG_ITER_27(m,a,b,c,d,e,f) _WX_VARARG_ITER_26(m,a,b,c,d,e,f) m(27,a,b,c,d,e,f) | |
563 | #define _WX_VARARG_ITER_28(m,a,b,c,d,e,f) _WX_VARARG_ITER_27(m,a,b,c,d,e,f) m(28,a,b,c,d,e,f) | |
564 | #define _WX_VARARG_ITER_29(m,a,b,c,d,e,f) _WX_VARARG_ITER_28(m,a,b,c,d,e,f) m(29,a,b,c,d,e,f) | |
565 | #define _WX_VARARG_ITER_30(m,a,b,c,d,e,f) _WX_VARARG_ITER_29(m,a,b,c,d,e,f) m(30,a,b,c,d,e,f) | |
566 | ||
567 | ||
568 | #define _WX_VARARG_FIXED_EXPAND_1(t1) \ | |
569 | t1 f1 | |
570 | #define _WX_VARARG_FIXED_EXPAND_2(t1,t2) \ | |
571 | t1 f1, t2 f2 | |
572 | #define _WX_VARARG_FIXED_EXPAND_3(t1,t2,t3) \ | |
573 | t1 f1, t2 f2, t3 f3 | |
574 | #define _WX_VARARG_FIXED_EXPAND_4(t1,t2,t3,t4) \ | |
575 | t1 f1, t2 f2, t3 f3, t4 f4 | |
576 | ||
577 | #define _WX_VARARG_FIXED_UNUSED_EXPAND_1(t1) \ | |
578 | t1 WXUNUSED(f1) | |
579 | #define _WX_VARARG_FIXED_UNUSED_EXPAND_2(t1,t2) \ | |
580 | t1 WXUNUSED(f1), t2 WXUNUSED(f2) | |
581 | #define _WX_VARARG_FIXED_UNUSED_EXPAND_3(t1,t2,t3) \ | |
582 | t1 WXUNUSED(f1), t2 WXUNUSED(f2), t3 WXUNUSED(f3) | |
583 | #define _WX_VARARG_FIXED_UNUSED_EXPAND_4(t1,t2,t3,t4) \ | |
584 | t1 WXUNUSED(f1), t2 WXUNUSED(f2), t3 WXUNUSED(f3), t4 WXUNUSED(f4) | |
585 | ||
586 | ||
587 | // This macro expands N-items tuple of fixed arguments types into part of | |
588 | // function's declaration. For example, | |
589 | // "_WX_VARARG_FIXED_EXPAND(3, (int, char*, int))" expands into | |
590 | // "int f1, char* f2, int f3". | |
591 | #define _WX_VARARG_FIXED_EXPAND(N, args) \ | |
592 | _WX_VARARG_FIXED_EXPAND_IMPL(N, args) | |
593 | #define _WX_VARARG_FIXED_EXPAND_IMPL(N, args) \ | |
594 | _WX_VARARG_FIXED_EXPAND_##N args | |
595 | ||
596 | // Ditto for unused arguments | |
597 | #define _WX_VARARG_FIXED_UNUSED_EXPAND(N, args) \ | |
598 | _WX_VARARG_FIXED_UNUSED_EXPAND_IMPL(N, args) | |
599 | #define _WX_VARARG_FIXED_UNUSED_EXPAND_IMPL(N, args) \ | |
600 | _WX_VARARG_FIXED_UNUSED_EXPAND_##N args | |
601 | ||
c9f78968 VS |
602 | |
603 | // This macro calls another macro 'm' passed as second argument 'N' times, | |
604 | // with its only argument set to 1..N, and concatenates the results using | |
605 | // comma as separator. | |
606 | // | |
607 | // An example: | |
608 | // #define foo(i) x##i | |
609 | // // this expands to "x1,x2,x3,x4" | |
610 | // _WX_VARARG_JOIN(4, foo) | |
611 | // | |
612 | // | |
613 | // N must not be greater than _WX_VARARG_MAX_ARGS (=30). | |
614 | #define _WX_VARARG_JOIN(N, m) _WX_VARARG_JOIN_IMPL(N, m) | |
615 | #define _WX_VARARG_JOIN_IMPL(N, m) _WX_VARARG_JOIN_##N(m) | |
616 | ||
2523e9b7 | 617 | |
c9f78968 | 618 | // This macro calls another macro 'm' passed as second argument 'N' times, with |
2523e9b7 VS |
619 | // its first argument set to 1..N and the remaining arguments set to 'a', 'b', |
620 | // 'c', 'd', 'e' and 'f'. The results are separated with whitespace in the | |
621 | // expansion. | |
c9f78968 VS |
622 | // |
623 | // An example: | |
624 | // // this macro expands to: | |
2523e9b7 VS |
625 | // // foo(1,a,b,c,d,e,f) |
626 | // // foo(2,a,b,c,d,e,f) | |
627 | // // foo(3,a,b,c,d,e,f) | |
628 | // _WX_VARARG_ITER(3, foo, a, b, c, d, e, f) | |
c9f78968 VS |
629 | // |
630 | // N must not be greater than _WX_VARARG_MAX_ARGS (=30). | |
2523e9b7 VS |
631 | #define _WX_VARARG_ITER(N,m,a,b,c,d,e,f) \ |
632 | _WX_VARARG_ITER_IMPL(N,m,a,b,c,d,e,f) | |
633 | #define _WX_VARARG_ITER_IMPL(N,m,a,b,c,d,e,f) \ | |
634 | _WX_VARARG_ITER_##N(m,a,b,c,d,e,f) | |
c9f78968 | 635 | |
2523e9b7 VS |
636 | // Generates code snippet for i-th "variadic" argument in vararg function's |
637 | // prototype: | |
638 | #define _WX_VARARG_ARG(i) T##i a##i | |
c9f78968 | 639 | |
2523e9b7 | 640 | // Like _WX_VARARG_ARG_UNUSED, but outputs argument's type with WXUNUSED: |
d1f6e2cf | 641 | #define _WX_VARARG_ARG_UNUSED(i) T##i WXUNUSED(a##i) |
c9f78968 | 642 | |
2523e9b7 VS |
643 | // Generates code snippet for i-th type in vararg function's template<...>: |
644 | #define _WX_VARARG_TEMPL(i) typename T##i | |
c9f78968 VS |
645 | |
646 | // Generates code snippet for passing i-th argument of vararg function | |
2523e9b7 VS |
647 | // wrapper to its implementation, normalizing it in the process: |
648 | #define _WX_VARARG_PASS_WCHAR(i) wxArgNormalizerWchar<T##i>(a##i).get() | |
649 | #define _WX_VARARG_PASS_UTF8(i) wxArgNormalizerUtf8<T##i>(a##i).get() | |
650 | ||
651 | ||
652 | // And the same for fixed arguments, _not_ normalizing it: | |
653 | // FIXME-UTF8: this works, but uses wxString's implicit conversion to wxChar* | |
654 | // for the 'format' argument (which is const wxString&) _if_ the | |
655 | // implementation function has C sting argument; we need to | |
656 | // have wxFixedArgNormalizer<T> here that will pass everything | |
657 | // as-is except for wxString (for which wx_str() would be used), | |
658 | // but OTOH, we don't want to do that if the implementation takes | |
659 | // wxString argument | |
660 | #define _WX_VARARG_PASS_FIXED(i) f##i | |
661 | ||
662 | #if wxUSE_UNICODE_UTF8 | |
663 | #define _WX_VARARG_DO_CALL_UTF8(return_kw, impl, implUtf8, N, numfixed) \ | |
664 | return_kw implUtf8(_WX_VARARG_JOIN(numfixed, _WX_VARARG_PASS_FIXED), \ | |
665 | _WX_VARARG_JOIN(N, _WX_VARARG_PASS_UTF8)) | |
666 | #define _WX_VARARG_DO_CALL0_UTF8(return_kw, impl, implUtf8, numfixed) \ | |
667 | return_kw implUtf8(_WX_VARARG_JOIN(numfixed, _WX_VARARG_PASS_FIXED)) | |
668 | #endif // wxUSE_UNICODE_UTF8 | |
669 | ||
670 | #define _WX_VARARG_DO_CALL_WCHAR(return_kw, impl, implUtf8, N, numfixed) \ | |
671 | return_kw impl(_WX_VARARG_JOIN(numfixed, _WX_VARARG_PASS_FIXED), \ | |
672 | _WX_VARARG_JOIN(N, _WX_VARARG_PASS_WCHAR)) | |
673 | #define _WX_VARARG_DO_CALL0_WCHAR(return_kw, impl, implUtf8, numfixed) \ | |
674 | return_kw impl(_WX_VARARG_JOIN(numfixed, _WX_VARARG_PASS_FIXED)) | |
675 | ||
676 | #if wxUSE_UNICODE_UTF8 | |
677 | #if wxUSE_UTF8_LOCALE_ONLY | |
678 | #define _WX_VARARG_DO_CALL _WX_VARARG_DO_CALL_UTF8 | |
679 | #define _WX_VARARG_DO_CALL0 _WX_VARARG_DO_CALL0_UTF8 | |
680 | #else // possibly non-UTF8 locales | |
681 | #define _WX_VARARG_DO_CALL(return_kw, impl, implUtf8, N, numfixed) \ | |
682 | if ( wxLocaleIsUtf8 ) \ | |
683 | _WX_VARARG_DO_CALL_UTF8(return_kw, impl, implUtf8, N, numfixed);\ | |
684 | else \ | |
685 | _WX_VARARG_DO_CALL_WCHAR(return_kw, impl, implUtf8, N, numfixed) | |
686 | ||
687 | #define _WX_VARARG_DO_CALL0(return_kw, impl, implUtf8, numfixed) \ | |
688 | if ( wxLocaleIsUtf8 ) \ | |
689 | _WX_VARARG_DO_CALL0_UTF8(return_kw, impl, implUtf8, numfixed); \ | |
690 | else \ | |
691 | _WX_VARARG_DO_CALL0_WCHAR(return_kw, impl, implUtf8, numfixed) | |
692 | #endif // wxUSE_UTF8_LOCALE_ONLY or not | |
693 | #else // wxUSE_UNICODE_WCHAR or ANSI | |
694 | #define _WX_VARARG_DO_CALL _WX_VARARG_DO_CALL_WCHAR | |
695 | #define _WX_VARARG_DO_CALL0 _WX_VARARG_DO_CALL0_WCHAR | |
696 | #endif // wxUSE_UNICODE_UTF8 / wxUSE_UNICODE_WCHAR | |
c9f78968 VS |
697 | |
698 | ||
699 | // Macro to be used with _WX_VARARG_ITER in the implementation of | |
700 | // WX_DEFINE_VARARG_FUNC (see its documentation for the meaning of arguments) | |
2523e9b7 VS |
701 | #define _WX_VARARG_DEFINE_FUNC(N, rettype, name, \ |
702 | impl, implUtf8, numfixed, fixed) \ | |
703 | template<_WX_VARARG_JOIN(N, _WX_VARARG_TEMPL)> \ | |
704 | rettype name(_WX_VARARG_FIXED_EXPAND(numfixed, fixed), \ | |
705 | _WX_VARARG_JOIN(N, _WX_VARARG_ARG)) \ | |
706 | { \ | |
707 | _WX_VARARG_DO_CALL(return, impl, implUtf8, N, numfixed); \ | |
708 | } | |
709 | ||
710 | #define _WX_VARARG_DEFINE_FUNC_N0(rettype, name, \ | |
711 | impl, implUtf8, numfixed, fixed) \ | |
712 | inline rettype name(_WX_VARARG_FIXED_EXPAND(numfixed, fixed)) \ | |
713 | { \ | |
714 | _WX_VARARG_DO_CALL0(return, impl, implUtf8, numfixed); \ | |
c9f78968 VS |
715 | } |
716 | ||
717 | // Macro to be used with _WX_VARARG_ITER in the implementation of | |
718 | // WX_DEFINE_VARARG_FUNC_VOID (see its documentation for the meaning of | |
719 | // arguments; rettype is ignored and is used only to satisfy _WX_VARARG_ITER's | |
720 | // requirements). | |
2523e9b7 VS |
721 | #define _WX_VARARG_DEFINE_FUNC_VOID(N, rettype, name, \ |
722 | impl, implUtf8, numfixed, fixed) \ | |
723 | template<_WX_VARARG_JOIN(N, _WX_VARARG_TEMPL)> \ | |
724 | void name(_WX_VARARG_FIXED_EXPAND(numfixed, fixed), \ | |
725 | _WX_VARARG_JOIN(N, _WX_VARARG_ARG)) \ | |
726 | { \ | |
727 | _WX_VARARG_DO_CALL(wxEMPTY_PARAMETER_VALUE, \ | |
728 | impl, implUtf8, N, numfixed); \ | |
729 | } | |
730 | ||
731 | #define _WX_VARARG_DEFINE_FUNC_VOID_N0(name, impl, implUtf8, numfixed, fixed) \ | |
732 | inline void name(_WX_VARARG_FIXED_EXPAND(numfixed, fixed)) \ | |
733 | { \ | |
734 | _WX_VARARG_DO_CALL0(wxEMPTY_PARAMETER_VALUE, \ | |
735 | impl, implUtf8, numfixed); \ | |
736 | } | |
737 | ||
738 | // Macro to be used with _WX_VARARG_ITER in the implementation of | |
739 | // WX_DEFINE_VARARG_FUNC_CTOR (see its documentation for the meaning of | |
740 | // arguments; rettype is ignored and is used only to satisfy _WX_VARARG_ITER's | |
741 | // requirements). | |
742 | #define _WX_VARARG_DEFINE_FUNC_CTOR(N, rettype, name, \ | |
743 | impl, implUtf8, numfixed, fixed) \ | |
744 | template<_WX_VARARG_JOIN(N, _WX_VARARG_TEMPL)> \ | |
745 | name(_WX_VARARG_FIXED_EXPAND(numfixed, fixed), \ | |
746 | _WX_VARARG_JOIN(N, _WX_VARARG_ARG)) \ | |
747 | { \ | |
748 | _WX_VARARG_DO_CALL(wxEMPTY_PARAMETER_VALUE, \ | |
749 | impl, implUtf8, N, numfixed); \ | |
750 | } | |
751 | ||
752 | #define _WX_VARARG_DEFINE_FUNC_CTOR_N0(name, impl, implUtf8, numfixed, fixed) \ | |
753 | inline name(_WX_VARARG_FIXED_EXPAND(numfixed, fixed)) \ | |
754 | { \ | |
755 | _WX_VARARG_DO_CALL0(wxEMPTY_PARAMETER_VALUE, \ | |
756 | impl, implUtf8, numfixed); \ | |
c9f78968 VS |
757 | } |
758 | ||
759 | // Macro to be used with _WX_VARARG_ITER in the implementation of | |
760 | // WX_DEFINE_VARARG_FUNC_NOP, i.e. empty stub for a disabled vararg function. | |
761 | // The rettype and impl arguments are ignored. | |
2523e9b7 VS |
762 | #define _WX_VARARG_DEFINE_FUNC_NOP(N, rettype, name, \ |
763 | impl, implUtf8, numfixed, fixed) \ | |
764 | template<_WX_VARARG_JOIN(N, _WX_VARARG_TEMPL)> \ | |
765 | void name(_WX_VARARG_FIXED_UNUSED_EXPAND(numfixed, fixed), \ | |
766 | _WX_VARARG_JOIN(N, _WX_VARARG_ARG_UNUSED)) \ | |
767 | {} | |
768 | ||
769 | #define _WX_VARARG_DEFINE_FUNC_NOP_N0(name, numfixed, fixed) \ | |
770 | inline void name(_WX_VARARG_FIXED_UNUSED_EXPAND(numfixed, fixed)) \ | |
771 | {} | |
c9f78968 | 772 | |
59a14f69 VS |
773 | |
774 | // ---------------------------------------------------------------------------- | |
775 | // workaround for OpenWatcom bug #351 | |
776 | // ---------------------------------------------------------------------------- | |
777 | ||
778 | #ifdef __WATCOMC__ | |
779 | // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351 | |
780 | ||
781 | // This macro can be used to forward a 'vararg' template to another one with | |
782 | // different fixed arguments types. Parameters are same as for | |
783 | // WX_DEFINE_VARARG_FUNC (rettype=void can be used here), 'convfixed' is how | |
784 | // to convert fixed arguments. For example, this is typical code for dealing | |
785 | // with different forms of format string: | |
786 | // | |
787 | // WX_DEFINE_VARARG_FUNC_VOID(Printf, 1, (const wxFormatString&), | |
788 | // DoPrintfWchar, DoPrintfUtf8) | |
789 | // #ifdef __WATCOMC__ | |
790 | // WX_VARARG_WATCOM_WORKAROUND(void, Printf, 1, (const wxString&), | |
791 | // (wxFormatString(f1))) | |
792 | // WX_VARARG_WATCOM_WORKAROUND(void, Printf, 1, (const char*), | |
793 | // (wxFormatString(f1))) | |
794 | // ... | |
795 | #define WX_VARARG_WATCOM_WORKAROUND(rettype, name, numfixed, fixed, convfixed)\ | |
796 | _WX_VARARG_ITER(_WX_VARARG_MAX_ARGS, \ | |
797 | _WX_VARARG_WATCOM_WORKAROUND, \ | |
798 | rettype, name, convfixed, dummy, numfixed, fixed) | |
799 | ||
800 | #define WX_VARARG_WATCOM_WORKAROUND_CTOR(name, numfixed, fixed, convfixed) \ | |
801 | _WX_VARARG_ITER(_WX_VARARG_MAX_ARGS, \ | |
802 | _WX_VARARG_WATCOM_WORKAROUND_CTOR, \ | |
803 | dummy, name, convfixed, dummy, numfixed, fixed) | |
804 | ||
805 | #define _WX_VARARG_WATCOM_UNPACK_1(a1) a1 | |
806 | #define _WX_VARARG_WATCOM_UNPACK_2(a1, a2) a1, a2 | |
807 | #define _WX_VARARG_WATCOM_UNPACK_3(a1, a2, a3) a1, a2, a3 | |
808 | #define _WX_VARARG_WATCOM_UNPACK_4(a1, a2, a3, a4) a1, a2, a3, a4 | |
809 | #define _WX_VARARG_WATCOM_UNPACK(N, convfixed) \ | |
810 | _WX_VARARG_WATCOM_UNPACK_##N convfixed | |
811 | ||
812 | #define _WX_VARARG_WATCOM_WORKAROUND(N, rettype, name, \ | |
813 | convfixed, dummy, numfixed, fixed) \ | |
814 | template<_WX_VARARG_JOIN(N, _WX_VARARG_TEMPL)> \ | |
815 | rettype name(_WX_VARARG_FIXED_EXPAND(numfixed, fixed), \ | |
816 | _WX_VARARG_JOIN(N, _WX_VARARG_ARG)) \ | |
817 | { \ | |
818 | return name(_WX_VARARG_WATCOM_UNPACK(numfixed, convfixed), \ | |
819 | _WX_VARARG_JOIN(N, _WX_VARARG_PASS_WCHAR)); \ | |
820 | } | |
821 | ||
822 | #define _WX_VARARG_WATCOM_WORKAROUND_CTOR(N, dummy1, name, \ | |
823 | convfixed, dummy2, numfixed, fixed) \ | |
824 | template<_WX_VARARG_JOIN(N, _WX_VARARG_TEMPL)> \ | |
825 | name(_WX_VARARG_FIXED_EXPAND(numfixed, fixed), \ | |
826 | _WX_VARARG_JOIN(N, _WX_VARARG_ARG)) \ | |
827 | { \ | |
828 | name(_WX_VARARG_WATCOM_UNPACK(numfixed, convfixed), \ | |
829 | _WX_VARARG_JOIN(N, _WX_VARARG_PASS_WCHAR)); \ | |
830 | } | |
831 | ||
832 | #endif // __WATCOMC__ | |
833 | ||
c9f78968 | 834 | #endif // _WX_STRVARARG_H_ |