]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/buffer.h
1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: auto buffer classes: buffers which automatically free memory
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
12 // these classes are for private use only for now, they're not documented
17 #include "wx/wxchar.h"
19 #include <string.h> // strdup
21 // ----------------------------------------------------------------------------
22 // Special classes for (wide) character strings: they use malloc/free instead
24 // ----------------------------------------------------------------------------
29 wxCharBuffer(const char *str
)
31 wxASSERT_MSG( str
, wxT("NULL string in wxCharBuffer") );
33 m_str
= str
? strdup(str
) : (char *)NULL
;
35 wxCharBuffer(size_t len
)
37 m_str
= (char *)malloc(len
+1);
40 // no need to check for NULL, free() does it
41 ~wxCharBuffer() { free(m_str
); }
43 wxCharBuffer(const wxCharBuffer
& src
)
46 // no reference count yet...
47 ((wxCharBuffer
*)&src
)->m_str
= (char *)NULL
;
49 wxCharBuffer
& operator=(const wxCharBuffer
& src
)
52 // no reference count yet...
53 ((wxCharBuffer
*)&src
)->m_str
= (char *)NULL
;
57 const char *data() const { return m_str
; }
58 operator const char *() const { return m_str
; }
59 char operator[](size_t n
) const { return m_str
[n
]; }
69 wxWCharBuffer(const wchar_t *wcs
)
71 wxASSERT_MSG( wcs
, wxT("NULL string in wxWCharBuffer") );
74 #if (defined(__BORLANDC__) && (__BORLANDC__ > 0x530))
75 size_t siz
= (std::wcslen(wcs
)+1)*sizeof(wchar_t);
77 size_t siz
= (::wcslen(wcs
)+1)*sizeof(wchar_t);
79 m_wcs
= (wchar_t *)malloc(siz
);
80 memcpy(m_wcs
, wcs
, siz
);
82 else m_wcs
= (wchar_t *)NULL
;
84 wxWCharBuffer(size_t len
)
86 m_wcs
= (wchar_t *)malloc((len
+1)*sizeof(wchar_t));
90 // no need to check for NULL, free() does it
91 ~wxWCharBuffer() { free(m_wcs
); }
93 wxWCharBuffer(const wxWCharBuffer
& src
)
96 // no reference count yet...
97 ((wxWCharBuffer
*)&src
)->m_wcs
= (wchar_t *)NULL
;
99 wxWCharBuffer
& operator=(const wxWCharBuffer
& src
)
102 // no reference count yet...
103 ((wxWCharBuffer
*)&src
)->m_wcs
= (wchar_t *)NULL
;
107 const wchar_t *data() const { return m_wcs
; }
108 operator const wchar_t *() const { return m_wcs
; }
109 wchar_t operator[](size_t n
) const { return m_wcs
[n
]; }
117 #define wxMB2WXbuf wxWCharBuffer
118 #define wxWX2MBbuf wxCharBuffer
119 #define wxWC2WXbuf wxChar*
120 #define wxWX2WCbuf wxChar*
122 #define wxMB2WXbuf wxChar*
123 #define wxWX2MBbuf wxChar*
124 #define wxWC2WXbuf wxCharBuffer
125 #define wxWX2WCbuf wxWCharBuffer
126 #endif // Unicode/ANSI
128 // ----------------------------------------------------------------------------
129 // template class for any kind of data
130 // ----------------------------------------------------------------------------
134 #endif // _WX_BUFFER_H