]> git.saurik.com Git - wxWidgets.git/blame - src/common/strvararg.cpp
invalidate the best size when adding or deleting items
[wxWidgets.git] / src / common / strvararg.cpp
CommitLineData
c9f78968
VS
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
81727065 35const wxChar *wxArgNormalizer<const wxCStrData&>::get() const
c9f78968 36{
81727065
VS
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
41 // available.
c9f78968
VS
42 return m_value;
43}
44
81727065 45const wxChar *wxArgNormalizer<const wxString&>::get() const
c9f78968 46{
81727065
VS
47#if wxUSE_UNICODE_UTF8 // FIXME-UTF8
48 return (const wxChar*)m_value;
49#else
8f93a29f 50 return m_value.wx_str();
81727065 51#endif
c9f78968
VS
52}
53
81727065 54#if wxUSE_UNICODE // FIXME-UTF8: should be wxUSE_UNICODE_WCHAR
c9f78968
VS
55wxArgNormalizer<const char*>::wxArgNormalizer(const char *value)
56{
81727065
VS
57 // FIXME-UTF8: move this to the header so that m_value doesn't have
58 // to be dynamically allocated
c9f78968
VS
59 m_value = new wxWCharBuffer(wxConvLibc.cMB2WC(value));
60}
61
62wxArgNormalizer<const char*>::~wxArgNormalizer()
63{
64 delete m_value;
65}
66
67const wchar_t *wxArgNormalizer<const char*>::get() const
68{
69 return m_value->data();
70}
81727065 71#endif // wxUSE_UNICODE_WCHAR
c9f78968 72
c9f78968 73
81727065 74#if /*wxUSE_UNICODE_UTF8 ||*/ !wxUSE_UNICODE // FIXME-UTF8
c9f78968
VS
75wxArgNormalizer<const wchar_t*>::wxArgNormalizer(const wchar_t *value)
76{
81727065
VS
77#if wxUSE_UNICODE_UTF8 // FIXME-UTF8: this will be the only case
78 m_value = new wxCharBuffer(wxConvUTF8.cWC2MB(value));
79#else
c9f78968 80 m_value = new wxCharBuffer(wxConvLibc.cWC2MB(value));
81727065 81#endif
c9f78968
VS
82}
83
84wxArgNormalizer<const wchar_t*>::~wxArgNormalizer()
85{
86 delete m_value;
87}
88
89const char *wxArgNormalizer<const wchar_t*>::get() const
90{
91 return m_value->data();
92}
81727065
VS
93#endif // wxUSE_UNICODE_UTF8 || !wxUSE_UNICODE
94
95#if 0 // wxUSE_UNICODE_UTF8 - FIXME-UTF8
96wxArgNormalizer<const char*>::wxArgNormalizer(const char *value)
97{
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
101
102 // convert to widechar string first:
103 wxWCharBuffer buf(wxConvLibc.cMB2WC(value));
104
105 if ( buf )
106 {
107 // then to UTF-8:
108 m_value = new wxCharBuffer(wxConvUTF8.cWC2MB(value));
109 }
110 else
111 {
112 m_value = new wxCharBuffer();
113 }
114}
115
116wxArgNormalizer<const char*>::~wxArgNormalizer()
117{
118 delete m_value;
119}
120
121const char *wxArgNormalizer<const char*>::get() const
122{
123 return m_value->data();
124}
125#endif // wxUSE_UNICODE_UTF8
126
c9f78968 127
359bd4d1
VS
128
129// FIXME-UTF8: move this to the header once it's possible to include buffer.h
130// without including wxcrt.h
359bd4d1
VS
131wxArgNormalizer<wxCharBuffer>::wxArgNormalizer(const wxCharBuffer& buf)
132 : wxArgNormalizer<const char*>(buf.data())
133{
134}
135
136wxArgNormalizer<wxWCharBuffer>::wxArgNormalizer(const wxWCharBuffer& buf)
137 : wxArgNormalizer<const wchar_t*>(buf.data())
138{
139}