]> git.saurik.com Git - wxWidgets.git/blame - include/wx/buffer.h
added missing conditional compilation test for wxUSE_PROPSHEET
[wxWidgets.git] / include / wx / buffer.h
CommitLineData
14971e5b
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: buffer.h
3// Purpose: auto buffer classes: buffers which automatically free memory
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 12.04.99
7// RCS-ID: $Id$
8// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9// Licence: wxWindows license
10///////////////////////////////////////////////////////////////////////////////
11
12// these classes are for private use only for now, they're not documented
13
14#ifndef _WX_BUFFER_H
15#define _WX_BUFFER_H
16
853d7d3d 17#include "wx/wxchar.h"
e90c1d2a 18
f93d01be 19#include <string.h> // strdup
14971e5b
VZ
20
21// ----------------------------------------------------------------------------
22// Special classes for (wide) character strings: they use malloc/free instead
23// of new/delete
24// ----------------------------------------------------------------------------
25
26class wxCharBuffer
27{
28public:
29 wxCharBuffer(const char *str)
30 {
223d09f6 31 wxASSERT_MSG( str, wxT("NULL string in wxCharBuffer") );
14971e5b
VZ
32
33 m_str = str ? strdup(str) : (char *)NULL;
34 }
f93d01be
OK
35 wxCharBuffer(size_t len)
36 {
37 m_str = (char *)malloc(len+1);
e90c1d2a 38 m_str[len] = '\0';
f93d01be 39 }
14971e5b
VZ
40 // no need to check for NULL, free() does it
41 ~wxCharBuffer() { free(m_str); }
42
f93d01be
OK
43 wxCharBuffer(const wxCharBuffer& src)
44 {
45 m_str = src.m_str;
46 // no reference count yet...
d87c0ac7 47 ((wxCharBuffer*)&src)->m_str = (char *)NULL;
f93d01be
OK
48 }
49 wxCharBuffer& operator=(const wxCharBuffer& src)
50 {
51 m_str = src.m_str;
52 // no reference count yet...
d87c0ac7 53 ((wxCharBuffer*)&src)->m_str = (char *)NULL;
f93d01be
OK
54 return *this;
55 }
56
f6bcfd97 57 const char *data() const { return m_str; }
14971e5b 58 operator const char *() const { return m_str; }
b1fa8b4e 59 char operator[](size_t n) const { return m_str[n]; }
14971e5b
VZ
60
61private:
62 char *m_str;
63};
64
7a3e402c 65#if wxUSE_WCHAR_T
14971e5b
VZ
66class wxWCharBuffer
67{
68public:
69 wxWCharBuffer(const wchar_t *wcs)
70 {
223d09f6 71 wxASSERT_MSG( wcs, wxT("NULL string in wxWCharBuffer") );
14971e5b 72
853d7d3d 73 if (wcs) {
d834f22c
JS
74#if (defined(__BORLANDC__) && (__BORLANDC__ > 0x530))
75 size_t siz = (std::wcslen(wcs)+1)*sizeof(wchar_t);
76#else
c3b177ae 77 size_t siz = (::wcslen(wcs)+1)*sizeof(wchar_t);
d834f22c 78#endif
853d7d3d
OK
79 m_wcs = (wchar_t *)malloc(siz);
80 memcpy(m_wcs, wcs, siz);
81 }
82 else m_wcs = (wchar_t *)NULL;
f93d01be
OK
83 }
84 wxWCharBuffer(size_t len)
85 {
86 m_wcs = (wchar_t *)malloc((len+1)*sizeof(wchar_t));
e90c1d2a 87 m_wcs[len] = L'\0';
14971e5b
VZ
88 }
89
90 // no need to check for NULL, free() does it
91 ~wxWCharBuffer() { free(m_wcs); }
92
f93d01be
OK
93 wxWCharBuffer(const wxWCharBuffer& src)
94 {
95 m_wcs = src.m_wcs;
96 // no reference count yet...
20456250 97 ((wxWCharBuffer*)&src)->m_wcs = (wchar_t *)NULL;
f93d01be
OK
98 }
99 wxWCharBuffer& operator=(const wxWCharBuffer& src)
100 {
101 m_wcs = src.m_wcs;
102 // no reference count yet...
20456250 103 ((wxWCharBuffer*)&src)->m_wcs = (wchar_t *)NULL;
f93d01be
OK
104 return *this;
105 }
106
f6bcfd97 107 const wchar_t *data() const { return m_wcs; }
14971e5b 108 operator const wchar_t *() const { return m_wcs; }
b1fa8b4e 109 wchar_t operator[](size_t n) const { return m_wcs[n]; }
e90c1d2a 110
14971e5b
VZ
111private:
112 wchar_t *m_wcs;
113};
7a3e402c 114#endif
14971e5b 115
f93d01be 116#if wxUSE_UNICODE
e90c1d2a
VZ
117 #define wxMB2WXbuf wxWCharBuffer
118 #define wxWX2MBbuf wxCharBuffer
119 #define wxWC2WXbuf wxChar*
120 #define wxWX2WCbuf wxChar*
121#else // ANSI
122 #define wxMB2WXbuf wxChar*
123 #define wxWX2MBbuf wxChar*
124 #define wxWC2WXbuf wxCharBuffer
125 #define wxWX2WCbuf wxWCharBuffer
126#endif // Unicode/ANSI
f93d01be 127
14971e5b
VZ
128// ----------------------------------------------------------------------------
129// template class for any kind of data
130// ----------------------------------------------------------------------------
131
132// TODO
133
134#endif // _WX_BUFFER_H