1998-11-24 18:34:24 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2002-02-06 15:12:24 -05:00
|
|
|
// Name: wx/arrimpl.cpp
|
1998-11-24 18:34:24 -05:00
|
|
|
// Purpose: helper file for implementation of dynamic lists
|
|
|
|
// Author: Vadim Zeitlin
|
1999-10-04 16:15:38 -04:00
|
|
|
// Modified by:
|
1998-11-24 18:34:24 -05:00
|
|
|
// Created: 16.10.97
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 1997 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
|
|
|
// Licence: wxWindows license
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* Purpose: implements methods of "template" class declared in *
|
|
|
|
* DECLARE_OBJARRAY macro and which couldn't be implemented inline *
|
|
|
|
* (because they need the full definition of type T in scope) *
|
|
|
|
* *
|
|
|
|
* Usage: 1) #include dynarray.h *
|
|
|
|
* 2) WX_DECLARE_OBJARRAY *
|
|
|
|
* 3) #include arrimpl.cpp *
|
|
|
|
* 4) WX_DEFINE_OBJARRAY *
|
|
|
|
*****************************************************************************/
|
|
|
|
|
1999-10-04 16:15:38 -04:00
|
|
|
// needed to resolve the conflict between global T and macro parameter T
|
2000-05-05 12:40:32 -04:00
|
|
|
|
|
|
|
// VC++ can't cope with string concatenation in Unicode mode
|
|
|
|
#if defined(wxUSE_UNICODE) && wxUSE_UNICODE
|
|
|
|
#define _WX_ERROR_REMOVE2(x) wxT("bad index in ::RemoveAt()")
|
|
|
|
#else
|
1999-11-16 08:28:23 -05:00
|
|
|
#define _WX_ERROR_REMOVE2(x) wxT("bad index in " #x "::RemoveAt()")
|
2000-05-05 12:40:32 -04:00
|
|
|
#endif
|
1999-10-04 16:15:38 -04:00
|
|
|
|
1998-11-24 18:34:24 -05:00
|
|
|
// macro implements remaining (not inline) methods of template list
|
|
|
|
// (it's private to this file)
|
1999-01-08 19:29:40 -05:00
|
|
|
#undef _DEFINE_OBJARRAY
|
|
|
|
#define _DEFINE_OBJARRAY(T, name) \
|
1998-11-24 18:34:24 -05:00
|
|
|
name::~name() \
|
|
|
|
{ \
|
|
|
|
Empty(); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
void name::DoCopy(const name& src) \
|
|
|
|
{ \
|
1999-01-08 19:29:40 -05:00
|
|
|
for ( size_t ui = 0; ui < src.Count(); ui++ ) \
|
1998-11-24 18:34:24 -05:00
|
|
|
Add(src[ui]); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
name& name::operator=(const name& src) \
|
|
|
|
{ \
|
|
|
|
Empty(); \
|
|
|
|
DoCopy(src); \
|
|
|
|
\
|
|
|
|
return *this; \
|
|
|
|
} \
|
|
|
|
\
|
2002-05-07 17:58:27 -04:00
|
|
|
name::name(const name& src) : wxArrayPtrVoid() \
|
1998-11-24 18:34:24 -05:00
|
|
|
{ \
|
|
|
|
DoCopy(src); \
|
|
|
|
} \
|
|
|
|
\
|
2000-07-15 15:51:35 -04:00
|
|
|
void name::DoEmpty() \
|
1998-11-24 18:34:24 -05:00
|
|
|
{ \
|
1999-01-08 19:29:40 -05:00
|
|
|
for ( size_t ui = 0; ui < Count(); ui++ ) \
|
2002-03-06 01:31:34 -05:00
|
|
|
delete (T*)wxBaseArrayPtrVoid::Item(ui); \
|
1998-11-24 18:34:24 -05:00
|
|
|
} \
|
|
|
|
\
|
2002-04-26 17:58:46 -04:00
|
|
|
void name::RemoveAt(size_t uiIndex, size_t nRemove) \
|
1998-11-24 18:34:24 -05:00
|
|
|
{ \
|
1999-10-04 16:15:38 -04:00
|
|
|
wxCHECK_RET( uiIndex < Count(), _WX_ERROR_REMOVE2(name) ); \
|
1998-11-24 18:34:24 -05:00
|
|
|
\
|
2002-04-26 17:58:46 -04:00
|
|
|
for (size_t i = 0; i < nRemove; i++ ) \
|
|
|
|
delete (T*)wxBaseArrayPtrVoid::Item(uiIndex + i); \
|
1998-11-24 18:34:24 -05:00
|
|
|
\
|
2002-04-26 17:58:46 -04:00
|
|
|
wxBaseArrayPtrVoid::RemoveAt(uiIndex, nRemove); \
|
1998-11-24 18:34:24 -05:00
|
|
|
} \
|
|
|
|
\
|
2002-04-26 17:58:46 -04:00
|
|
|
void name::Add(const T& item, size_t nInsert) \
|
1998-11-24 18:34:24 -05:00
|
|
|
{ \
|
2002-12-04 09:11:26 -05:00
|
|
|
if (nInsert == 0) \
|
|
|
|
return; \
|
1998-11-24 18:34:24 -05:00
|
|
|
T* pItem = new T(item); \
|
2002-04-26 17:58:46 -04:00
|
|
|
size_t nOldSize = GetCount(); \
|
1998-11-24 18:34:24 -05:00
|
|
|
if ( pItem != NULL ) \
|
2002-04-26 17:58:46 -04:00
|
|
|
wxBaseArrayPtrVoid::Add(pItem, nInsert); \
|
|
|
|
for (size_t i = 1; i < nInsert; i++) \
|
|
|
|
wxBaseArrayPtrVoid::Item(nOldSize + i) = new T(item); \
|
1998-11-24 18:34:24 -05:00
|
|
|
} \
|
|
|
|
\
|
2002-04-26 17:58:46 -04:00
|
|
|
void name::Insert(const T& item, size_t uiIndex, size_t nInsert) \
|
1998-11-24 18:34:24 -05:00
|
|
|
{ \
|
2002-12-04 09:11:26 -05:00
|
|
|
if (nInsert == 0) \
|
|
|
|
return; \
|
1998-11-24 18:34:24 -05:00
|
|
|
T* pItem = new T(item); \
|
|
|
|
if ( pItem != NULL ) \
|
2002-04-26 17:58:46 -04:00
|
|
|
wxBaseArrayPtrVoid::Insert(pItem, uiIndex, nInsert); \
|
|
|
|
for (size_t i = 1; i < nInsert; i++) \
|
|
|
|
wxBaseArrayPtrVoid::Item(uiIndex + i) = new T(item); \
|
1998-11-24 18:34:24 -05:00
|
|
|
} \
|
|
|
|
\
|
1999-01-08 19:29:40 -05:00
|
|
|
int name::Index(const T& Item, bool bFromEnd) const \
|
1998-11-24 18:34:24 -05:00
|
|
|
{ \
|
|
|
|
if ( bFromEnd ) { \
|
|
|
|
if ( Count() > 0 ) { \
|
1999-01-08 19:29:40 -05:00
|
|
|
size_t ui = Count() - 1; \
|
1998-11-24 18:34:24 -05:00
|
|
|
do { \
|
2002-03-06 01:31:34 -05:00
|
|
|
if ( (T*)wxBaseArrayPtrVoid::Item(ui) == &Item ) \
|
1998-11-24 18:34:24 -05:00
|
|
|
return ui; \
|
|
|
|
ui--; \
|
|
|
|
} \
|
|
|
|
while ( ui != 0 ); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
else { \
|
1999-01-08 19:29:40 -05:00
|
|
|
for( size_t ui = 0; ui < Count(); ui++ ) { \
|
2002-03-06 01:31:34 -05:00
|
|
|
if( (T*)wxBaseArrayPtrVoid::Item(ui) == &Item ) \
|
1998-11-24 18:34:24 -05:00
|
|
|
return ui; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
1999-10-04 16:15:38 -04:00
|
|
|
return wxNOT_FOUND; \
|
|
|
|
}
|
1998-11-24 18:34:24 -05:00
|
|
|
|
|
|
|
// redefine the macro so that now it will generate the class implementation
|
|
|
|
// old value would provoke a compile-time error if this file is not included
|
|
|
|
#undef WX_DEFINE_OBJARRAY
|
2002-02-06 15:12:24 -05:00
|
|
|
#define WX_DEFINE_OBJARRAY(name) _DEFINE_OBJARRAY(_wxObjArray##name, name)
|