3f66f6a5b3
This keyword is not expanded by Git which means it's not replaced with the correct revision value in the releases made using git-based scripts and it's confusing to have lines with unexpanded "$Id$" in the released files. As expanding them with Git is not that simple (it could be done with git archive and export-subst attribute) and there are not many benefits in having them in the first place, just remove all these lines. If nothing else, this will make an eventual transition to Git simpler. Closes #14487. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74602 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
120 lines
3.7 KiB
C++
120 lines
3.7 KiB
C++
/////////////////////////////////////////////////////////////////////////////
|
|
// Name: wx/scopedarray.h
|
|
// Purpose: scoped smart pointer class
|
|
// Author: Vadim Zeitlin
|
|
// Created: 2009-02-03
|
|
// Copyright: (c) Jesse Lovelace and original Boost authors (see below)
|
|
// (c) 2009 Vadim Zeitlin
|
|
// Licence: wxWindows licence
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
#ifndef _WX_SCOPED_ARRAY_H_
|
|
#define _WX_SCOPED_ARRAY_H_
|
|
|
|
#include "wx/defs.h"
|
|
#include "wx/checkeddelete.h"
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// wxScopedArray: A scoped array
|
|
// ----------------------------------------------------------------------------
|
|
|
|
template <class T>
|
|
class wxScopedArray
|
|
{
|
|
public:
|
|
typedef T element_type;
|
|
|
|
wxEXPLICIT wxScopedArray(T * array = NULL) : m_array(array) { }
|
|
|
|
~wxScopedArray() { delete [] m_array; }
|
|
|
|
// test for pointer validity: defining conversion to unspecified_bool_type
|
|
// and not more obvious bool to avoid implicit conversions to integer types
|
|
typedef T *(wxScopedArray<T>::*unspecified_bool_type)() const;
|
|
operator unspecified_bool_type() const
|
|
{
|
|
return m_array ? &wxScopedArray<T>::get : NULL;
|
|
}
|
|
|
|
void reset(T *array = NULL)
|
|
{
|
|
if ( array != m_array )
|
|
{
|
|
delete [] m_array;
|
|
m_array = array;
|
|
}
|
|
}
|
|
|
|
T& operator[](size_t n) const { return m_array[n]; }
|
|
|
|
T *get() const { return m_array; }
|
|
|
|
void swap(wxScopedArray &other)
|
|
{
|
|
T * const tmp = other.m_array;
|
|
other.m_array = m_array;
|
|
m_array = tmp;
|
|
}
|
|
|
|
private:
|
|
T *m_array;
|
|
|
|
DECLARE_NO_COPY_TEMPLATE_CLASS(wxScopedArray, T)
|
|
};
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// old macro based implementation
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// the same but for arrays instead of simple pointers
|
|
#define wxDECLARE_SCOPED_ARRAY(T, name)\
|
|
class name \
|
|
{ \
|
|
private: \
|
|
T * m_ptr; \
|
|
name(name const &); \
|
|
name & operator=(name const &); \
|
|
\
|
|
public: \
|
|
wxEXPLICIT name(T * p = NULL) : m_ptr(p) \
|
|
{} \
|
|
\
|
|
~name(); \
|
|
void reset(T * p = NULL); \
|
|
\
|
|
T & operator[](long int i) const\
|
|
{ \
|
|
wxASSERT(m_ptr != NULL); \
|
|
wxASSERT(i >= 0); \
|
|
return m_ptr[i]; \
|
|
} \
|
|
\
|
|
T * get() const \
|
|
{ \
|
|
return m_ptr; \
|
|
} \
|
|
\
|
|
void swap(name & ot) \
|
|
{ \
|
|
T * tmp = ot.m_ptr; \
|
|
ot.m_ptr = m_ptr; \
|
|
m_ptr = tmp; \
|
|
} \
|
|
};
|
|
|
|
#define wxDEFINE_SCOPED_ARRAY(T, name) \
|
|
name::~name() \
|
|
{ \
|
|
wxCHECKED_DELETE_ARRAY(m_ptr); \
|
|
} \
|
|
void name::reset(T * p){ \
|
|
if (m_ptr != p) \
|
|
{ \
|
|
wxCHECKED_DELETE_ARRAY(m_ptr); \
|
|
m_ptr = p; \
|
|
} \
|
|
}
|
|
|
|
#endif // _WX_SCOPED_ARRAY_H_
|
|
|