From 14971e5b9f0b77aeeef6138a513a43556ce0c6a0 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 12 Apr 1999 09:57:22 +0000 Subject: [PATCH] auto buffer class(es) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2095 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/buffer.h | 69 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 include/wx/buffer.h diff --git a/include/wx/buffer.h b/include/wx/buffer.h new file mode 100644 index 0000000000..5e107f4bd3 --- /dev/null +++ b/include/wx/buffer.h @@ -0,0 +1,69 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: buffer.h +// Purpose: auto buffer classes: buffers which automatically free memory +// Author: Vadim Zeitlin +// Modified by: +// Created: 12.04.99 +// RCS-ID: $Id$ +// Copyright: (c) 1998 Vadim Zeitlin +// Licence: wxWindows license +/////////////////////////////////////////////////////////////////////////////// + +// these classes are for private use only for now, they're not documented + +#ifndef _WX_BUFFER_H +#define _WX_BUFFER_H + +#include // strdup() +#include // wcsdup() + +// ---------------------------------------------------------------------------- +// Special classes for (wide) character strings: they use malloc/free instead +// of new/delete +// ---------------------------------------------------------------------------- + +class wxCharBuffer +{ +public: + wxCharBuffer(const char *str) + { + wxASSERT_MSG( str, "NULL string in wxCharBuffer" ); + + m_str = str ? strdup(str) : (char *)NULL; + } + + // no need to check for NULL, free() does it + ~wxCharBuffer() { free(m_str); } + + operator const char *() const { return m_str; } + +private: + char *m_str; +}; + +class wxWCharBuffer +{ +public: + wxWCharBuffer(const wchar_t *wcs) + { + wxASSERT_MSG( wcs, "NULL string in wxWCharBuffer" ); + + m_wcs = wcs ? wcsdup(wcs) : (wchar_t *)NULL; + } + + // no need to check for NULL, free() does it + ~wxWCharBuffer() { free(m_wcs); } + + operator const wchar_t *() const { return m_wcs; } + +private: + wchar_t *m_wcs; +}; + +// ---------------------------------------------------------------------------- +// template class for any kind of data +// ---------------------------------------------------------------------------- + +// TODO + +#endif // _WX_BUFFER_H -- 2.45.2