]>
git.saurik.com Git - wxWidgets.git/blob - src/common/strvararg.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/strvararg.cpp
3 // Purpose: macros for implementing type-safe vararg passing of strings
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2007 REA Elektronik GmbH
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
26 #include "wx/strvararg.h"
27 #include "wx/buffer.h"
28 #include "wx/strconv.h"
29 #include "wx/string.h"
31 // ============================================================================
33 // ============================================================================
35 const wxChar
*wxArgNormalizer
<const wxCStrData
&>::get() const
37 // FIXME-UTF8: use some way that doesn't involve implicit conversion,
38 // so that we deallocate any converted buffer immediately;
39 // can't use AsString() because it returns wxString and not
40 // const wxString&, unfortunately; use As[W]CharBuf() when
45 const wxChar
*wxArgNormalizer
<const wxString
&>::get() const
47 #if wxUSE_UNICODE_UTF8 // FIXME-UTF8
48 return (const wxChar
*)m_value
;
50 return m_value
.wx_str();
54 #if wxUSE_UNICODE // FIXME-UTF8: should be wxUSE_UNICODE_WCHAR
55 wxArgNormalizer
<const char*>::wxArgNormalizer(const char *value
)
57 // FIXME-UTF8: move this to the header so that m_value doesn't have
58 // to be dynamically allocated
59 m_value
= new wxWCharBuffer(wxConvLibc
.cMB2WC(value
));
62 wxArgNormalizer
<const char*>::~wxArgNormalizer()
67 const wchar_t *wxArgNormalizer
<const char*>::get() const
69 return m_value
->data();
71 #endif // wxUSE_UNICODE_WCHAR
74 #if /*wxUSE_UNICODE_UTF8 ||*/ !wxUSE_UNICODE // FIXME-UTF8
75 wxArgNormalizer
<const wchar_t*>::wxArgNormalizer(const wchar_t *value
)
77 #if wxUSE_UNICODE_UTF8 // FIXME-UTF8: this will be the only case
78 m_value
= new wxCharBuffer(wxConvUTF8
.cWC2MB(value
));
80 m_value
= new wxCharBuffer(wxConvLibc
.cWC2MB(value
));
84 wxArgNormalizer
<const wchar_t*>::~wxArgNormalizer()
89 const char *wxArgNormalizer
<const wchar_t*>::get() const
91 return m_value
->data();
93 #endif // wxUSE_UNICODE_UTF8 || !wxUSE_UNICODE
95 #if 0 // wxUSE_UNICODE_UTF8 - FIXME-UTF8
96 wxArgNormalizer
<const char*>::wxArgNormalizer(const char *value
)
98 // FIXME-UTF8: move this to the header so that m_value doesn't have
99 // to be dynamically allocated
100 // FIXME-UTF8: optimize this if current locale is UTF-8 one
102 // convert to widechar string first:
103 wxWCharBuffer
buf(wxConvLibc
.cMB2WC(value
));
108 m_value
= new wxCharBuffer(wxConvUTF8
.cWC2MB(value
));
112 m_value
= new wxCharBuffer();
116 wxArgNormalizer
<const char*>::~wxArgNormalizer()
121 const char *wxArgNormalizer
<const char*>::get() const
123 return m_value
->data();
125 #endif // wxUSE_UNICODE_UTF8
129 // FIXME-UTF8: move this to the header once it's possible to include buffer.h
130 // without including wxcrt.h
131 wxArgNormalizer
<wxCharBuffer
>::wxArgNormalizer(const wxCharBuffer
& buf
)
132 : wxArgNormalizer
<const char*>(buf
.data())
136 wxArgNormalizer
<wxWCharBuffer
>::wxArgNormalizer(const wxWCharBuffer
& buf
)
137 : wxArgNormalizer
<const wchar_t*>(buf
.data())