allow passing wx[W]CharBuffer to wx vararg templates
[wxWidgets.git] / 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
5 // Created: 2007-02-19
6 // RCS-ID: $Id$
7 // Copyright: (c) 2007 REA Elektronik GmbH
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 #include "wx/strvararg.h"
27 #include "wx/buffer.h"
28 #include "wx/strconv.h"
29 #include "wx/string.h"
30
31 // ============================================================================
32 // implementation
33 // ============================================================================
34
35 const wxStringCharType *wxArgNormalizer<const wxCStrData&>::get() const
36 {
37 return m_value;
38 }
39
40 const wxStringCharType *wxArgNormalizer<const wxString&>::get() const
41 {
42 return m_value.wx_str();
43 }
44
45 #if wxUSE_UNICODE_WCHAR
46
47 wxArgNormalizer<const char*>::wxArgNormalizer(const char *value)
48 {
49 m_value = new wxWCharBuffer(wxConvLibc.cMB2WC(value));
50 }
51
52 wxArgNormalizer<const char*>::~wxArgNormalizer()
53 {
54 delete m_value;
55 }
56
57 const wchar_t *wxArgNormalizer<const char*>::get() const
58 {
59 return m_value->data();
60 }
61
62 #elif wxUSE_WCHAR_T // !wxUSE_UNICODE_WCHAR && wxUSE_WCHAR_T
63
64 wxArgNormalizer<const wchar_t*>::wxArgNormalizer(const wchar_t *value)
65 {
66 m_value = new wxCharBuffer(wxConvLibc.cWC2MB(value));
67 }
68
69 wxArgNormalizer<const wchar_t*>::~wxArgNormalizer()
70 {
71 delete m_value;
72 }
73
74 const char *wxArgNormalizer<const wchar_t*>::get() const
75 {
76 return m_value->data();
77 }
78
79 #endif // wxUSE_UNICODE_WCHAR / !wxUSE_UNICODE_WCHAR && wxUSE_WCHAR_T
80
81 // FIXME-UTF8: move this to the header once it's possible to include buffer.h
82 // without including wxcrt.h
83
84 wxArgNormalizer<wxCharBuffer>::wxArgNormalizer(const wxCharBuffer& buf)
85 : wxArgNormalizer<const char*>(buf.data())
86 {
87 }
88
89 wxArgNormalizer<wxWCharBuffer>::wxArgNormalizer(const wxWCharBuffer& buf)
90 : wxArgNormalizer<const wchar_t*>(buf.data())
91 {
92 }