1998-11-24 23:34:24 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2002-02-06 20:12:24 +00:00
|
|
|
// Name: wx/arrimpl.cpp
|
1998-11-24 23:34:24 +00:00
|
|
|
// Purpose: helper file for implementation of dynamic lists
|
|
|
|
// Author: Vadim Zeitlin
|
1999-10-04 20:15:38 +00:00
|
|
|
// Modified by:
|
1998-11-24 23:34:24 +00:00
|
|
|
// Created: 16.10.97
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 1997 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
2010-07-13 13:29:13 +00:00
|
|
|
// Licence: wxWindows licence
|
1998-11-24 23:34:24 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* 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 20:15:38 +00:00
|
|
|
// needed to resolve the conflict between global T and macro parameter T
|
2000-05-05 16:40:32 +00:00
|
|
|
|
2003-06-01 13:21:40 +00:00
|
|
|
#define _WX_ERROR_REMOVE2(x) wxT("bad index in ") wxT(#x) wxT("::RemoveAt()")
|
1999-10-04 20:15:38 +00:00
|
|
|
|
1998-11-24 23:34:24 +00:00
|
|
|
// macro implements remaining (not inline) methods of template list
|
|
|
|
// (it's private to this file)
|
1999-01-09 00:29:40 +00:00
|
|
|
#undef _DEFINE_OBJARRAY
|
|
|
|
#define _DEFINE_OBJARRAY(T, name) \
|
1998-11-24 23:34:24 +00:00
|
|
|
name::~name() \
|
|
|
|
{ \
|
|
|
|
Empty(); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
void name::DoCopy(const name& src) \
|
|
|
|
{ \
|
Added --use-stl to cnfigure, wxUSE_STL to setup0.h
Moved wx/datetime.inl contents to wx/datetime.h and removed
inline redefinition hack.
Implemented STL-like interface on top of wxList/wxArray, when wxUSE_STL=0.
Implemented wxList-like and wxArray interfaces on top of std::list and
std::vector, when wxUSE_STL=1.
Added arrstr.h, moved wxArrayString declaration there; string.h
#includes arrstr.h only if WXWIN_COMPATIBILITY_2_4 is enabled.
Added WX_CLEAR_HASH_MAP, WX_CLEAR_HASH_TABLE, WX_CLEAR_LIST macros,
to clear a wxHashMap, wxHashTable, wxList containing pointers: deletes
pointers and makes container zero-sized.
When wxUSE_STL=1, wxStringList works like a std::list<wxString>.
Made wxBase compile when wxUSE_STL=1.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21768 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2003-07-08 19:52:35 +00:00
|
|
|
for ( size_t ui = 0; ui < src.size(); ui++ ) \
|
1998-11-24 23:34:24 +00:00
|
|
|
Add(src[ui]); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
name& name::operator=(const name& src) \
|
|
|
|
{ \
|
|
|
|
Empty(); \
|
|
|
|
DoCopy(src); \
|
|
|
|
\
|
|
|
|
return *this; \
|
|
|
|
} \
|
|
|
|
\
|
2002-05-07 21:58:27 +00:00
|
|
|
name::name(const name& src) : wxArrayPtrVoid() \
|
1998-11-24 23:34:24 +00:00
|
|
|
{ \
|
|
|
|
DoCopy(src); \
|
|
|
|
} \
|
|
|
|
\
|
2000-07-15 19:51:35 +00:00
|
|
|
void name::DoEmpty() \
|
1998-11-24 23:34:24 +00:00
|
|
|
{ \
|
Added --use-stl to cnfigure, wxUSE_STL to setup0.h
Moved wx/datetime.inl contents to wx/datetime.h and removed
inline redefinition hack.
Implemented STL-like interface on top of wxList/wxArray, when wxUSE_STL=0.
Implemented wxList-like and wxArray interfaces on top of std::list and
std::vector, when wxUSE_STL=1.
Added arrstr.h, moved wxArrayString declaration there; string.h
#includes arrstr.h only if WXWIN_COMPATIBILITY_2_4 is enabled.
Added WX_CLEAR_HASH_MAP, WX_CLEAR_HASH_TABLE, WX_CLEAR_LIST macros,
to clear a wxHashMap, wxHashTable, wxList containing pointers: deletes
pointers and makes container zero-sized.
When wxUSE_STL=1, wxStringList works like a std::list<wxString>.
Made wxBase compile when wxUSE_STL=1.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21768 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2003-07-08 19:52:35 +00:00
|
|
|
for ( size_t ui = 0; ui < size(); ui++ ) \
|
|
|
|
delete (T*)base_array::operator[](ui); \
|
1998-11-24 23:34:24 +00:00
|
|
|
} \
|
|
|
|
\
|
2002-04-26 21:58:46 +00:00
|
|
|
void name::RemoveAt(size_t uiIndex, size_t nRemove) \
|
1998-11-24 23:34:24 +00:00
|
|
|
{ \
|
Added --use-stl to cnfigure, wxUSE_STL to setup0.h
Moved wx/datetime.inl contents to wx/datetime.h and removed
inline redefinition hack.
Implemented STL-like interface on top of wxList/wxArray, when wxUSE_STL=0.
Implemented wxList-like and wxArray interfaces on top of std::list and
std::vector, when wxUSE_STL=1.
Added arrstr.h, moved wxArrayString declaration there; string.h
#includes arrstr.h only if WXWIN_COMPATIBILITY_2_4 is enabled.
Added WX_CLEAR_HASH_MAP, WX_CLEAR_HASH_TABLE, WX_CLEAR_LIST macros,
to clear a wxHashMap, wxHashTable, wxList containing pointers: deletes
pointers and makes container zero-sized.
When wxUSE_STL=1, wxStringList works like a std::list<wxString>.
Made wxBase compile when wxUSE_STL=1.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21768 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2003-07-08 19:52:35 +00:00
|
|
|
wxCHECK_RET( uiIndex < size(), _WX_ERROR_REMOVE2(name) ); \
|
1998-11-24 23:34:24 +00:00
|
|
|
\
|
2002-04-26 21:58:46 +00:00
|
|
|
for (size_t i = 0; i < nRemove; i++ ) \
|
Added --use-stl to cnfigure, wxUSE_STL to setup0.h
Moved wx/datetime.inl contents to wx/datetime.h and removed
inline redefinition hack.
Implemented STL-like interface on top of wxList/wxArray, when wxUSE_STL=0.
Implemented wxList-like and wxArray interfaces on top of std::list and
std::vector, when wxUSE_STL=1.
Added arrstr.h, moved wxArrayString declaration there; string.h
#includes arrstr.h only if WXWIN_COMPATIBILITY_2_4 is enabled.
Added WX_CLEAR_HASH_MAP, WX_CLEAR_HASH_TABLE, WX_CLEAR_LIST macros,
to clear a wxHashMap, wxHashTable, wxList containing pointers: deletes
pointers and makes container zero-sized.
When wxUSE_STL=1, wxStringList works like a std::list<wxString>.
Made wxBase compile when wxUSE_STL=1.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21768 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2003-07-08 19:52:35 +00:00
|
|
|
delete (T*)base_array::operator[](uiIndex + i); \
|
1998-11-24 23:34:24 +00:00
|
|
|
\
|
Added --use-stl to cnfigure, wxUSE_STL to setup0.h
Moved wx/datetime.inl contents to wx/datetime.h and removed
inline redefinition hack.
Implemented STL-like interface on top of wxList/wxArray, when wxUSE_STL=0.
Implemented wxList-like and wxArray interfaces on top of std::list and
std::vector, when wxUSE_STL=1.
Added arrstr.h, moved wxArrayString declaration there; string.h
#includes arrstr.h only if WXWIN_COMPATIBILITY_2_4 is enabled.
Added WX_CLEAR_HASH_MAP, WX_CLEAR_HASH_TABLE, WX_CLEAR_LIST macros,
to clear a wxHashMap, wxHashTable, wxList containing pointers: deletes
pointers and makes container zero-sized.
When wxUSE_STL=1, wxStringList works like a std::list<wxString>.
Made wxBase compile when wxUSE_STL=1.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21768 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2003-07-08 19:52:35 +00:00
|
|
|
base_array::erase(begin() + uiIndex, begin() + uiIndex + nRemove); \
|
1998-11-24 23:34:24 +00:00
|
|
|
} \
|
|
|
|
\
|
2002-04-26 21:58:46 +00:00
|
|
|
void name::Add(const T& item, size_t nInsert) \
|
1998-11-24 23:34:24 +00:00
|
|
|
{ \
|
2002-12-04 14:11:26 +00:00
|
|
|
if (nInsert == 0) \
|
|
|
|
return; \
|
1998-11-24 23:34:24 +00:00
|
|
|
T* pItem = new T(item); \
|
Added --use-stl to cnfigure, wxUSE_STL to setup0.h
Moved wx/datetime.inl contents to wx/datetime.h and removed
inline redefinition hack.
Implemented STL-like interface on top of wxList/wxArray, when wxUSE_STL=0.
Implemented wxList-like and wxArray interfaces on top of std::list and
std::vector, when wxUSE_STL=1.
Added arrstr.h, moved wxArrayString declaration there; string.h
#includes arrstr.h only if WXWIN_COMPATIBILITY_2_4 is enabled.
Added WX_CLEAR_HASH_MAP, WX_CLEAR_HASH_TABLE, WX_CLEAR_LIST macros,
to clear a wxHashMap, wxHashTable, wxList containing pointers: deletes
pointers and makes container zero-sized.
When wxUSE_STL=1, wxStringList works like a std::list<wxString>.
Made wxBase compile when wxUSE_STL=1.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21768 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2003-07-08 19:52:35 +00:00
|
|
|
size_t nOldSize = size(); \
|
1998-11-24 23:34:24 +00:00
|
|
|
if ( pItem != NULL ) \
|
Added --use-stl to cnfigure, wxUSE_STL to setup0.h
Moved wx/datetime.inl contents to wx/datetime.h and removed
inline redefinition hack.
Implemented STL-like interface on top of wxList/wxArray, when wxUSE_STL=0.
Implemented wxList-like and wxArray interfaces on top of std::list and
std::vector, when wxUSE_STL=1.
Added arrstr.h, moved wxArrayString declaration there; string.h
#includes arrstr.h only if WXWIN_COMPATIBILITY_2_4 is enabled.
Added WX_CLEAR_HASH_MAP, WX_CLEAR_HASH_TABLE, WX_CLEAR_LIST macros,
to clear a wxHashMap, wxHashTable, wxList containing pointers: deletes
pointers and makes container zero-sized.
When wxUSE_STL=1, wxStringList works like a std::list<wxString>.
Made wxBase compile when wxUSE_STL=1.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21768 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2003-07-08 19:52:35 +00:00
|
|
|
base_array::insert(end(), nInsert, pItem); \
|
2002-04-26 21:58:46 +00:00
|
|
|
for (size_t i = 1; i < nInsert; i++) \
|
Added --use-stl to cnfigure, wxUSE_STL to setup0.h
Moved wx/datetime.inl contents to wx/datetime.h and removed
inline redefinition hack.
Implemented STL-like interface on top of wxList/wxArray, when wxUSE_STL=0.
Implemented wxList-like and wxArray interfaces on top of std::list and
std::vector, when wxUSE_STL=1.
Added arrstr.h, moved wxArrayString declaration there; string.h
#includes arrstr.h only if WXWIN_COMPATIBILITY_2_4 is enabled.
Added WX_CLEAR_HASH_MAP, WX_CLEAR_HASH_TABLE, WX_CLEAR_LIST macros,
to clear a wxHashMap, wxHashTable, wxList containing pointers: deletes
pointers and makes container zero-sized.
When wxUSE_STL=1, wxStringList works like a std::list<wxString>.
Made wxBase compile when wxUSE_STL=1.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21768 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2003-07-08 19:52:35 +00:00
|
|
|
base_array::operator[](nOldSize + i) = new T(item); \
|
1998-11-24 23:34:24 +00:00
|
|
|
} \
|
|
|
|
\
|
2002-04-26 21:58:46 +00:00
|
|
|
void name::Insert(const T& item, size_t uiIndex, size_t nInsert) \
|
1998-11-24 23:34:24 +00:00
|
|
|
{ \
|
2002-12-04 14:11:26 +00:00
|
|
|
if (nInsert == 0) \
|
|
|
|
return; \
|
1998-11-24 23:34:24 +00:00
|
|
|
T* pItem = new T(item); \
|
|
|
|
if ( pItem != NULL ) \
|
Added --use-stl to cnfigure, wxUSE_STL to setup0.h
Moved wx/datetime.inl contents to wx/datetime.h and removed
inline redefinition hack.
Implemented STL-like interface on top of wxList/wxArray, when wxUSE_STL=0.
Implemented wxList-like and wxArray interfaces on top of std::list and
std::vector, when wxUSE_STL=1.
Added arrstr.h, moved wxArrayString declaration there; string.h
#includes arrstr.h only if WXWIN_COMPATIBILITY_2_4 is enabled.
Added WX_CLEAR_HASH_MAP, WX_CLEAR_HASH_TABLE, WX_CLEAR_LIST macros,
to clear a wxHashMap, wxHashTable, wxList containing pointers: deletes
pointers and makes container zero-sized.
When wxUSE_STL=1, wxStringList works like a std::list<wxString>.
Made wxBase compile when wxUSE_STL=1.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21768 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2003-07-08 19:52:35 +00:00
|
|
|
base_array::insert(begin() + uiIndex, nInsert, pItem); \
|
2002-04-26 21:58:46 +00:00
|
|
|
for (size_t i = 1; i < nInsert; i++) \
|
Added --use-stl to cnfigure, wxUSE_STL to setup0.h
Moved wx/datetime.inl contents to wx/datetime.h and removed
inline redefinition hack.
Implemented STL-like interface on top of wxList/wxArray, when wxUSE_STL=0.
Implemented wxList-like and wxArray interfaces on top of std::list and
std::vector, when wxUSE_STL=1.
Added arrstr.h, moved wxArrayString declaration there; string.h
#includes arrstr.h only if WXWIN_COMPATIBILITY_2_4 is enabled.
Added WX_CLEAR_HASH_MAP, WX_CLEAR_HASH_TABLE, WX_CLEAR_LIST macros,
to clear a wxHashMap, wxHashTable, wxList containing pointers: deletes
pointers and makes container zero-sized.
When wxUSE_STL=1, wxStringList works like a std::list<wxString>.
Made wxBase compile when wxUSE_STL=1.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21768 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2003-07-08 19:52:35 +00:00
|
|
|
base_array::operator[](uiIndex + i) = new T(item); \
|
1998-11-24 23:34:24 +00:00
|
|
|
} \
|
|
|
|
\
|
1999-01-09 00:29:40 +00:00
|
|
|
int name::Index(const T& Item, bool bFromEnd) const \
|
1998-11-24 23:34:24 +00:00
|
|
|
{ \
|
|
|
|
if ( bFromEnd ) { \
|
Added --use-stl to cnfigure, wxUSE_STL to setup0.h
Moved wx/datetime.inl contents to wx/datetime.h and removed
inline redefinition hack.
Implemented STL-like interface on top of wxList/wxArray, when wxUSE_STL=0.
Implemented wxList-like and wxArray interfaces on top of std::list and
std::vector, when wxUSE_STL=1.
Added arrstr.h, moved wxArrayString declaration there; string.h
#includes arrstr.h only if WXWIN_COMPATIBILITY_2_4 is enabled.
Added WX_CLEAR_HASH_MAP, WX_CLEAR_HASH_TABLE, WX_CLEAR_LIST macros,
to clear a wxHashMap, wxHashTable, wxList containing pointers: deletes
pointers and makes container zero-sized.
When wxUSE_STL=1, wxStringList works like a std::list<wxString>.
Made wxBase compile when wxUSE_STL=1.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21768 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2003-07-08 19:52:35 +00:00
|
|
|
if ( size() > 0 ) { \
|
|
|
|
size_t ui = size() - 1; \
|
1998-11-24 23:34:24 +00:00
|
|
|
do { \
|
Added --use-stl to cnfigure, wxUSE_STL to setup0.h
Moved wx/datetime.inl contents to wx/datetime.h and removed
inline redefinition hack.
Implemented STL-like interface on top of wxList/wxArray, when wxUSE_STL=0.
Implemented wxList-like and wxArray interfaces on top of std::list and
std::vector, when wxUSE_STL=1.
Added arrstr.h, moved wxArrayString declaration there; string.h
#includes arrstr.h only if WXWIN_COMPATIBILITY_2_4 is enabled.
Added WX_CLEAR_HASH_MAP, WX_CLEAR_HASH_TABLE, WX_CLEAR_LIST macros,
to clear a wxHashMap, wxHashTable, wxList containing pointers: deletes
pointers and makes container zero-sized.
When wxUSE_STL=1, wxStringList works like a std::list<wxString>.
Made wxBase compile when wxUSE_STL=1.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21768 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2003-07-08 19:52:35 +00:00
|
|
|
if ( (T*)base_array::operator[](ui) == &Item ) \
|
2008-11-02 02:39:52 +00:00
|
|
|
return static_cast<int>(ui); \
|
1998-11-24 23:34:24 +00:00
|
|
|
ui--; \
|
|
|
|
} \
|
|
|
|
while ( ui != 0 ); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
else { \
|
Added --use-stl to cnfigure, wxUSE_STL to setup0.h
Moved wx/datetime.inl contents to wx/datetime.h and removed
inline redefinition hack.
Implemented STL-like interface on top of wxList/wxArray, when wxUSE_STL=0.
Implemented wxList-like and wxArray interfaces on top of std::list and
std::vector, when wxUSE_STL=1.
Added arrstr.h, moved wxArrayString declaration there; string.h
#includes arrstr.h only if WXWIN_COMPATIBILITY_2_4 is enabled.
Added WX_CLEAR_HASH_MAP, WX_CLEAR_HASH_TABLE, WX_CLEAR_LIST macros,
to clear a wxHashMap, wxHashTable, wxList containing pointers: deletes
pointers and makes container zero-sized.
When wxUSE_STL=1, wxStringList works like a std::list<wxString>.
Made wxBase compile when wxUSE_STL=1.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21768 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2003-07-08 19:52:35 +00:00
|
|
|
for( size_t ui = 0; ui < size(); ui++ ) { \
|
|
|
|
if( (T*)base_array::operator[](ui) == &Item ) \
|
2008-11-02 02:39:52 +00:00
|
|
|
return static_cast<int>(ui); \
|
1998-11-24 23:34:24 +00:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
1999-10-04 20:15:38 +00:00
|
|
|
return wxNOT_FOUND; \
|
|
|
|
}
|
1998-11-24 23:34:24 +00: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 20:12:24 +00:00
|
|
|
#define WX_DEFINE_OBJARRAY(name) _DEFINE_OBJARRAY(_wxObjArray##name, name)
|