]>
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"
18 #include <string.h> // strdup
20 // ----------------------------------------------------------------------------
21 // Special classes for (wide) character strings: they use malloc/free instead
23 // ----------------------------------------------------------------------------
28 wxCharBuffer(const char *str
)
30 wxASSERT_MSG( str
, _T("NULL string in wxCharBuffer") );
32 m_str
= str
? strdup(str
) : (char *)NULL
;
34 wxCharBuffer(size_t len
)
36 m_str
= (char *)malloc(len
+1);
39 // no need to check for NULL, free() does it
40 ~wxCharBuffer() { free(m_str
); }
42 wxCharBuffer(const wxCharBuffer
& src
)
45 // no reference count yet...
46 ((wxCharBuffer
*)&src
)->m_str
= (char *)NULL
;
48 wxCharBuffer
& operator=(const wxCharBuffer
& src
)
51 // no reference count yet...
52 ((wxCharBuffer
*)&src
)->m_str
= (char *)NULL
;
56 operator const char *() const { return m_str
; }
57 char operator[](size_t n
) const { return m_str
[n
]; }
67 wxWCharBuffer(const wchar_t *wcs
)
69 wxASSERT_MSG( wcs
, _T("NULL string in wxWCharBuffer") );
72 size_t siz
= (wcslen(wcs
)+1)*sizeof(wchar_t);
73 m_wcs
= (wchar_t *)malloc(siz
);
74 memcpy(m_wcs
, wcs
, siz
);
76 else m_wcs
= (wchar_t *)NULL
;
78 wxWCharBuffer(size_t len
)
80 m_wcs
= (wchar_t *)malloc((len
+1)*sizeof(wchar_t));
84 // no need to check for NULL, free() does it
85 ~wxWCharBuffer() { free(m_wcs
); }
87 wxWCharBuffer(const wxWCharBuffer
& src
)
90 // no reference count yet...
91 ((wxWCharBuffer
*)&src
)->m_wcs
= (wchar_t *)NULL
;
93 wxWCharBuffer
& operator=(const wxWCharBuffer
& src
)
96 // no reference count yet...
97 ((wxWCharBuffer
*)&src
)->m_wcs
= (wchar_t *)NULL
;
101 operator const wchar_t *() const { return m_wcs
; }
102 wchar_t operator[](size_t n
) const { return m_wcs
[n
]; }
110 #define wxMB2WXbuf wxWCharBuffer
111 #define wxWX2MBbuf wxCharBuffer
112 #define wxWC2WXbuf wxChar*
113 #define wxWX2WCbuf wxChar*
115 #define wxMB2WXbuf wxChar*
116 #define wxWX2MBbuf wxChar*
117 #define wxWC2WXbuf wxCharBuffer
118 #define wxWX2WCbuf wxWCharBuffer
121 // ----------------------------------------------------------------------------
122 // template class for any kind of data
123 // ----------------------------------------------------------------------------
127 #endif // _WX_BUFFER_H