2020-02-23 12:21:28 +01:00
//*************************************************************************************************
//*************************************************************************************************
//
// XObjArray
//
// Developed by jief666, from 1997.
//
//*************************************************************************************************
//*************************************************************************************************
# if !defined(__XOBJARRAY_H__)
# define __XOBJARRAY_H__
2020-04-24 08:36:29 +02:00
# include <XToolsConf.h>
2020-04-26 12:12:05 +02:00
# include "XToolsCommon.h"
2020-02-23 12:21:28 +01:00
# if 1
2020-04-24 11:30:09 +02:00
# define XObjArray_DBG(...) printf__VA_ARGS__)
2020-02-23 12:21:28 +01:00
# else
# define XObjArray_DBG(...)
# endif
template < class TYPE >
class XObjArrayEntry
{
public :
TYPE * Object ;
bool FreeIt ;
} ;
template < class TYPE >
class XObjArrayNC
{
public :
XObjArrayEntry < TYPE > * _Data ;
2020-04-26 12:12:05 +02:00
size_t _Len ;
size_t m_allocatedSize ;
2020-02-23 12:21:28 +01:00
public :
void Init ( ) ;
2020-08-11 14:43:53 +02:00
XObjArrayNC ( ) : _Data ( 0 ) , _Len ( 0 ) , m_allocatedSize ( 0 ) { Init ( ) ; }
2020-02-23 12:21:28 +01:00
virtual ~ XObjArrayNC ( ) ;
protected :
2020-04-24 11:30:09 +02:00
// XObjArrayNC(const XObjArrayNC<TYPE> &anObjArrayNC) { (void)anObjArrayNC; panic("Intentionally not defined"); }
// const XObjArrayNC<TYPE> &operator =(const XObjArrayNC<TYPE> &anObjArrayNC) { (void)anObjArrayNC; panic("Intentionally not defined"); }
XObjArrayNC ( const XObjArrayNC < TYPE > & anObjArrayNC ) = delete ;
const XObjArrayNC < TYPE > & operator = ( const XObjArrayNC < TYPE > & anObjArrayNC ) = delete ;
2020-08-11 14:43:53 +02:00
size_t _getLen ( ) const { return _Len ; }
2020-02-23 12:21:28 +01:00
public :
2020-08-11 14:43:53 +02:00
size_t AllocatedSize ( ) const { return m_allocatedSize ; }
size_t size ( ) const { return _Len ; }
size_t length ( ) const { return _Len ; }
2020-02-23 12:21:28 +01:00
2020-08-12 17:15:47 +02:00
bool notEmpty ( ) const { return size ( ) > 0 ; }
bool isEmpty ( ) const { return size ( ) = = 0 ; }
2020-02-23 12:21:28 +01:00
2020-04-26 12:12:05 +02:00
template < typename IntegralType , enable_if ( is_integral ( IntegralType ) ) >
const TYPE & ElementAt ( IntegralType nIndex ) const
{
if ( nIndex < 0 ) {
panic ( " XObjArrayNC::ElementAt() : i < 0. System halted \n " ) ;
}
if ( ( unsigned_type ( IntegralType ) ) nIndex > = _Len ) {
panic ( " XObjArrayNC::ElementAt() -> operator [] - index (%zu) greater than length (%zu) \n " , ( size_t ) nIndex , _Len ) ;
}
return * ( ( TYPE * ) ( _Data [ nIndex ] . Object ) ) ;
}
template < typename IntegralType , enable_if ( is_integral ( IntegralType ) ) >
TYPE & ElementAt ( IntegralType nIndex )
{
if ( nIndex < 0 ) {
panic ( " XObjArrayNC::ElementAt() : i < 0. System halted \n " ) ;
}
if ( ( unsigned_type ( IntegralType ) ) nIndex > = _Len ) {
panic ( " XObjArrayNC::ElementAt() const -> operator [] - index (%zu) greater than length (%zu) \n " , ( size_t ) nIndex , _Len ) ;
}
return * ( ( TYPE * ) ( _Data [ nIndex ] . Object ) ) ;
}
2020-02-23 12:21:28 +01:00
// This was useful for realtime debugging with a debugger that do not recognise references. That was years and years ago. Probably not needed anymore.
2020-05-03 17:07:34 +02:00
// #ifdef _DEBUG_iufasdfsfk
2020-08-11 14:43:53 +02:00
const TYPE * DbgAt ( int i ) const { if ( i > = 0 & & ( size_t ) i < _Len ) return & ElementAt ( ( size_t ) i ) ; else return NULL ; }
2020-05-03 17:07:34 +02:00
// #endif
2020-02-23 12:21:28 +01:00
2020-04-26 12:12:05 +02:00
template < typename IntegralType , enable_if ( is_integral ( IntegralType ) ) >
const TYPE & operator [ ] ( IntegralType nIndex ) const { return ElementAt ( nIndex ) ; }
template < typename IntegralType , enable_if ( is_integral ( IntegralType ) ) >
TYPE & operator [ ] ( IntegralType nIndex ) { return ElementAt ( nIndex ) ; }
2020-02-23 12:21:28 +01:00
2020-08-11 14:43:53 +02:00
size_t AddReference ( TYPE * newElement , bool FreeIt ) ;
2020-02-23 12:21:28 +01:00
2020-08-11 14:43:53 +02:00
// size_t InsertRef(TYPE *newElement, size_t pos, bool FreeIt = false);
size_t InsertRef ( TYPE * newElement , size_t pos , bool FreeIt ) ;
2020-02-23 12:21:28 +01:00
2020-08-11 14:43:53 +02:00
void SetFreeIt ( size_t nIndex , bool Flag ) ;
2020-02-23 12:21:28 +01:00
void SetFreeIt ( const TYPE * Element , bool Flag ) ;
void Remove ( const TYPE * Element ) ;
void RemoveWithoutFreeing ( const TYPE * Element ) ;
void Remove ( const TYPE & Element ) ;
2020-08-11 14:43:53 +02:00
void RemoveAtIndex ( size_t nIndex ) ;
2020-02-23 12:21:28 +01:00
void RemoveAtIndex ( int nIndex ) ;
2020-08-17 21:40:52 +02:00
void RemoveWithoutFreeingAtIndex ( size_t nIndex ) ; // If you use this, there might be a design problem somewhere ???
2020-02-23 12:21:28 +01:00
//void Remove(int nIndex);
void RemoveAllBut ( const TYPE * Element ) ;
2020-08-12 17:15:47 +02:00
void setEmpty ( ) ;
2020-02-23 12:21:28 +01:00
public :
2020-08-11 14:43:53 +02:00
void CheckSize ( size_t nNewSize , size_t nGrowBy = XArrayGrowByDefault ) ;
2020-02-23 12:21:28 +01:00
} ;
template < class TYPE >
class XObjArray : public XObjArrayNC < TYPE >
{
public :
XObjArray ( ) : XObjArrayNC < TYPE > ( ) { }
2020-08-22 15:39:24 +02:00
XObjArray ( bool FreeThem , TYPE * n1 , . . . ) ;
XObjArray ( const TYPE & n1 , bool FreeIt = true ) ;
XObjArray ( const TYPE & n1 , const TYPE & n2 , bool FreeThem = true ) ;
XObjArray ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , bool FreeThem = true ) ;
XObjArray ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , bool FreeThem = true ) ;
XObjArray ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , bool FreeThem = true ) ;
XObjArray ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , bool FreeThem = true ) ;
XObjArray ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , bool FreeThem = true ) ;
XObjArray ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , const TYPE & n8 , bool FreeThem = true ) ;
XObjArray ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , const TYPE & n8 , const TYPE & n9 , bool FreeThem = true ) ;
XObjArray ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , const TYPE & n8 , const TYPE & n9 , const TYPE & n10 , bool FreeThem = true ) ;
XObjArray ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , const TYPE & n8 , const TYPE & n9 , const TYPE & n10 , const TYPE & n11 , bool FreeThem = true ) ;
XObjArray ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , const TYPE & n8 , const TYPE & n9 , const TYPE & n10 , const TYPE & n11 , const TYPE & n12 , bool FreeThem = true ) ;
XObjArray ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , const TYPE & n8 , const TYPE & n9 , const TYPE & n10 , const TYPE & n11 , const TYPE & n12 , const TYPE & n13 , bool FreeThem = true ) ;
XObjArray ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , const TYPE & n8 , const TYPE & n9 , const TYPE & n10 , const TYPE & n11 , const TYPE & n12 , const TYPE & n13 , const TYPE & n14 , bool FreeThem = true ) ;
2020-02-23 12:21:28 +01:00
XObjArray ( const XObjArray < TYPE > & anObjArray ) ;
2020-08-22 15:39:24 +02:00
2020-02-23 12:21:28 +01:00
const XObjArray < TYPE > & operator = ( const XObjArray < TYPE > & anObjArray ) ;
2020-08-11 14:43:53 +02:00
size_t AddCopy ( const TYPE & newElement , bool FreeIt = true ) ;
size_t AddCopies ( const TYPE & n1 , bool FreeIt = true ) ;
size_t AddCopies ( const TYPE & n1 , const TYPE & n2 , bool FreeThem = true ) ;
size_t AddCopies ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , bool FreeThem = true ) ;
size_t AddCopies ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , bool FreeThem = true ) ;
size_t AddCopies ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , bool FreeThem = true ) ;
size_t AddCopies ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , bool FreeThem = true ) ;
size_t AddCopies ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , bool FreeThem = true ) ;
size_t AddCopies ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , const TYPE & n8 , bool FreeThem = true ) ;
size_t AddCopies ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , const TYPE & n8 , const TYPE & n9 , bool FreeThem = true ) ;
size_t AddCopies ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , const TYPE & n8 , const TYPE & n9 , const TYPE & n10 , bool FreeThem = true ) ;
size_t AddCopies ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , const TYPE & n8 , const TYPE & n9 , const TYPE & n10 , const TYPE & n11 , bool FreeThem = true ) ;
size_t AddCopies ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , const TYPE & n8 , const TYPE & n9 , const TYPE & n10 , const TYPE & n11 , const TYPE & n12 , bool FreeThem = true ) ;
size_t AddCopies ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , const TYPE & n8 , const TYPE & n9 , const TYPE & n10 , const TYPE & n11 , const TYPE & n12 , const TYPE & n13 , bool FreeThem = true ) ;
size_t AddCopies ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , const TYPE & n8 , const TYPE & n9 , const TYPE & n10 , const TYPE & n11 , const TYPE & n12 , const TYPE & n13 , const TYPE & n14 , bool FreeThem = true ) ;
2020-02-23 12:21:28 +01:00
//TYPE & AddNew(bool FreeIt = true);
2020-08-11 14:43:53 +02:00
size_t InsertCopy ( const TYPE & newElement , size_t pos ) ;
2020-02-23 12:21:28 +01:00
} ;
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//
// XObjArray
//
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
/* Constructeur */
template < class TYPE >
void XObjArrayNC < TYPE > : : Init ( )
{
2020-02-23 21:23:31 +01:00
_Data = nullptr ;
2020-03-09 02:12:24 +01:00
m_allocatedSize = 0 ;
2020-02-23 12:21:28 +01:00
_Len = 0 ;
// THis was useful for realtime debugging with a debugger that do not recognise references.
2020-05-03 17:07:34 +02:00
// #ifdef _DEBUG_iufasdfsfk
2020-05-15 05:23:33 +02:00
// {
// const TYPE *tmp;
// tmp = DbgAt(0);
// }
2020-05-03 17:07:34 +02:00
// #endif
2020-02-23 12:21:28 +01:00
}
2020-08-22 15:39:24 +02:00
/* Constructeur */
template < class TYPE >
XObjArray < TYPE > : : XObjArray ( bool FreeThem , TYPE * n1 , . . . )
{
va_list va ;
va_start ( va , n1 ) ;
size_t count = 0 ;
2020-08-25 17:35:19 +02:00
TYPE * t = va_arg ( va , TYPE * ) ;
2020-08-22 15:39:24 +02:00
while ( t ! = nullptr ) {
count + + ;
2020-08-25 17:35:19 +02:00
t = va_arg ( va , TYPE * ) ;
2020-08-22 15:39:24 +02:00
}
va_end ( va ) ;
XObjArrayNC < TYPE > : : Init ( ) ;
this - > CheckSize ( count + 1 , ( size_t ) 0 ) ;
XObjArrayNC < TYPE > : : AddReference ( n1 , FreeThem ) ;
va_start ( va , n1 ) ;
2020-08-25 17:35:19 +02:00
t = va_arg ( va , TYPE * ) ;
2020-08-22 15:39:24 +02:00
while ( t ! = nullptr ) {
XObjArrayNC < TYPE > : : AddReference ( t , FreeThem ) ;
2020-08-25 17:35:19 +02:00
t = va_arg ( va , TYPE * ) ;
2020-08-22 15:39:24 +02:00
}
va_end ( va ) ;
}
template < class TYPE >
XObjArray < TYPE > : : XObjArray ( const TYPE & n1 , bool FreeIt )
{
XObjArrayNC < TYPE > : : Init ( ) ;
this - > CheckSize ( 1 , ( size_t ) 0 ) ;
AddCopy ( n1 , FreeIt ) ;
}
template < class TYPE >
XObjArray < TYPE > : : XObjArray ( const TYPE & n1 , const TYPE & n2 , bool FreeThem )
{
XObjArrayNC < TYPE > : : Init ( ) ;
this - > CheckSize ( 2 , ( size_t ) 0 ) ;
AddCopy ( n1 , FreeThem ) ;
AddCopy ( n2 , FreeThem ) ;
}
template < class TYPE >
XObjArray < TYPE > : : XObjArray ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , bool FreeThem )
{
XObjArrayNC < TYPE > : : Init ( ) ;
this - > CheckSize ( 3 , ( size_t ) 0 ) ;
AddCopy ( n1 , FreeThem ) ;
AddCopy ( n2 , FreeThem ) ;
AddCopy ( n3 , FreeThem ) ;
}
template < class TYPE >
XObjArray < TYPE > : : XObjArray ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , bool FreeThem )
{
XObjArrayNC < TYPE > : : Init ( ) ;
this - > CheckSize ( 4 , ( size_t ) 0 ) ;
AddCopy ( n1 , FreeThem ) ;
AddCopy ( n2 , FreeThem ) ;
AddCopy ( n3 , FreeThem ) ;
AddCopy ( n4 , FreeThem ) ;
}
template < class TYPE >
XObjArray < TYPE > : : XObjArray ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , bool FreeThem )
{
XObjArrayNC < TYPE > : : Init ( ) ;
this - > CheckSize ( 5 , ( size_t ) 0 ) ;
AddCopy ( n1 , FreeThem ) ;
AddCopy ( n2 , FreeThem ) ;
AddCopy ( n3 , FreeThem ) ;
AddCopy ( n4 , FreeThem ) ;
AddCopy ( n5 , FreeThem ) ;
}
template < class TYPE >
XObjArray < TYPE > : : XObjArray ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , bool FreeThem )
{
XObjArrayNC < TYPE > : : Init ( ) ;
this - > CheckSize ( 6 , ( size_t ) 0 ) ;
AddCopy ( n1 , FreeThem ) ;
AddCopy ( n2 , FreeThem ) ;
AddCopy ( n3 , FreeThem ) ;
AddCopy ( n4 , FreeThem ) ;
AddCopy ( n5 , FreeThem ) ;
AddCopy ( n6 , FreeThem ) ;
}
template < class TYPE >
XObjArray < TYPE > : : XObjArray ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , bool FreeThem )
{
XObjArrayNC < TYPE > : : Init ( ) ;
this - > CheckSize ( 7 , ( size_t ) 0 ) ;
AddCopy ( n1 , FreeThem ) ;
AddCopy ( n2 , FreeThem ) ;
AddCopy ( n3 , FreeThem ) ;
AddCopy ( n4 , FreeThem ) ;
AddCopy ( n5 , FreeThem ) ;
AddCopy ( n6 , FreeThem ) ;
AddCopy ( n7 , FreeThem ) ;
}
template < class TYPE >
XObjArray < TYPE > : : XObjArray ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , const TYPE & n8 , bool FreeThem )
{
XObjArrayNC < TYPE > : : Init ( ) ;
this - > CheckSize ( 8 , ( size_t ) 0 ) ;
AddCopy ( n1 , FreeThem ) ;
AddCopy ( n2 , FreeThem ) ;
AddCopy ( n3 , FreeThem ) ;
AddCopy ( n4 , FreeThem ) ;
AddCopy ( n5 , FreeThem ) ;
AddCopy ( n6 , FreeThem ) ;
AddCopy ( n7 , FreeThem ) ;
AddCopy ( n8 , FreeThem ) ;
}
template < class TYPE >
XObjArray < TYPE > : : XObjArray ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , const TYPE & n8 , const TYPE & n9 , bool FreeThem )
{
XObjArrayNC < TYPE > : : Init ( ) ;
this - > CheckSize ( 9 , ( size_t ) 0 ) ;
AddCopy ( n1 , FreeThem ) ;
AddCopy ( n2 , FreeThem ) ;
AddCopy ( n3 , FreeThem ) ;
AddCopy ( n4 , FreeThem ) ;
AddCopy ( n5 , FreeThem ) ;
AddCopy ( n6 , FreeThem ) ;
AddCopy ( n7 , FreeThem ) ;
AddCopy ( n8 , FreeThem ) ;
AddCopy ( n9 , FreeThem ) ;
}
template < class TYPE >
XObjArray < TYPE > : : XObjArray ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , const TYPE & n8 , const TYPE & n9 , const TYPE & n10 , bool FreeThem )
{
XObjArrayNC < TYPE > : : Init ( ) ;
this - > CheckSize ( 10 , ( size_t ) 0 ) ;
AddCopy ( n1 , FreeThem ) ;
AddCopy ( n2 , FreeThem ) ;
AddCopy ( n3 , FreeThem ) ;
AddCopy ( n4 , FreeThem ) ;
AddCopy ( n5 , FreeThem ) ;
AddCopy ( n6 , FreeThem ) ;
AddCopy ( n7 , FreeThem ) ;
AddCopy ( n8 , FreeThem ) ;
AddCopy ( n9 , FreeThem ) ;
AddCopy ( n10 , FreeThem ) ;
}
template < class TYPE >
XObjArray < TYPE > : : XObjArray ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , const TYPE & n8 , const TYPE & n9 , const TYPE & n10 , const TYPE & n11 , bool FreeThem )
{
XObjArrayNC < TYPE > : : Init ( ) ;
this - > CheckSize ( 11 , ( size_t ) 0 ) ;
AddCopy ( n1 , FreeThem ) ;
AddCopy ( n2 , FreeThem ) ;
AddCopy ( n3 , FreeThem ) ;
AddCopy ( n4 , FreeThem ) ;
AddCopy ( n5 , FreeThem ) ;
AddCopy ( n6 , FreeThem ) ;
AddCopy ( n7 , FreeThem ) ;
AddCopy ( n8 , FreeThem ) ;
AddCopy ( n9 , FreeThem ) ;
AddCopy ( n10 , FreeThem ) ;
AddCopy ( n11 , FreeThem ) ;
}
template < class TYPE >
XObjArray < TYPE > : : XObjArray ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , const TYPE & n8 , const TYPE & n9 , const TYPE & n10 , const TYPE & n11 , const TYPE & n12 , bool FreeThem )
{
XObjArrayNC < TYPE > : : Init ( ) ;
this - > CheckSize ( 12 , ( size_t ) 0 ) ;
AddCopy ( n1 , FreeThem ) ;
AddCopy ( n2 , FreeThem ) ;
AddCopy ( n3 , FreeThem ) ;
AddCopy ( n4 , FreeThem ) ;
AddCopy ( n5 , FreeThem ) ;
AddCopy ( n6 , FreeThem ) ;
AddCopy ( n7 , FreeThem ) ;
AddCopy ( n8 , FreeThem ) ;
AddCopy ( n9 , FreeThem ) ;
AddCopy ( n10 , FreeThem ) ;
AddCopy ( n11 , FreeThem ) ;
AddCopy ( n12 , FreeThem ) ;
}
template < class TYPE >
XObjArray < TYPE > : : XObjArray ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , const TYPE & n8 , const TYPE & n9 , const TYPE & n10 , const TYPE & n11 , const TYPE & n12 , const TYPE & n13 , bool FreeThem )
{
XObjArrayNC < TYPE > : : Init ( ) ;
this - > CheckSize ( 13 , ( size_t ) 0 ) ;
AddCopy ( n1 , FreeThem ) ;
AddCopy ( n2 , FreeThem ) ;
AddCopy ( n3 , FreeThem ) ;
AddCopy ( n4 , FreeThem ) ;
AddCopy ( n5 , FreeThem ) ;
AddCopy ( n6 , FreeThem ) ;
AddCopy ( n7 , FreeThem ) ;
AddCopy ( n8 , FreeThem ) ;
AddCopy ( n9 , FreeThem ) ;
AddCopy ( n10 , FreeThem ) ;
AddCopy ( n11 , FreeThem ) ;
AddCopy ( n12 , FreeThem ) ;
AddCopy ( n13 , FreeThem ) ;
}
template < class TYPE >
XObjArray < TYPE > : : XObjArray ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , const TYPE & n8 , const TYPE & n9 , const TYPE & n10 , const TYPE & n11 , const TYPE & n12 , const TYPE & n13 , const TYPE & n14 , bool FreeThem )
{
XObjArrayNC < TYPE > : : Init ( ) ;
this - > CheckSize ( 14 , ( size_t ) 0 ) ;
AddCopy ( n1 , FreeThem ) ;
AddCopy ( n2 , FreeThem ) ;
AddCopy ( n3 , FreeThem ) ;
AddCopy ( n4 , FreeThem ) ;
AddCopy ( n5 , FreeThem ) ;
AddCopy ( n6 , FreeThem ) ;
AddCopy ( n7 , FreeThem ) ;
AddCopy ( n8 , FreeThem ) ;
AddCopy ( n9 , FreeThem ) ;
AddCopy ( n10 , FreeThem ) ;
AddCopy ( n11 , FreeThem ) ;
AddCopy ( n12 , FreeThem ) ;
AddCopy ( n13 , FreeThem ) ;
AddCopy ( n14 , FreeThem ) ;
}
2020-02-23 12:21:28 +01:00
/* Constructeur */
template < class TYPE >
2020-04-09 19:07:32 +02:00
XObjArray < TYPE > : : XObjArray ( const XObjArray < TYPE > & anObjArray ) : XObjArrayNC < TYPE > ( )
2020-02-23 12:21:28 +01:00
{
2020-08-11 14:43:53 +02:00
size_t ui ;
2020-02-23 12:21:28 +01:00
2020-08-22 15:39:24 +02:00
XObjArrayNC < TYPE > : : Init ( ) ;
2020-08-11 14:43:53 +02:00
this - > CheckSize ( anObjArray . size ( ) , ( size_t ) 0 ) ;
2020-02-27 15:34:29 +01:00
for ( ui = 0 ; ui < anObjArray . size ( ) ; ui + = 1 ) AddCopy ( anObjArray . ElementAt ( ui ) ) ;
2020-02-23 12:21:28 +01:00
}
/* operator = */
template < class TYPE >
const XObjArray < TYPE > & XObjArray < TYPE > : : operator = ( const XObjArray < TYPE > & anObjArray )
{
2020-08-11 14:43:53 +02:00
size_t ui ;
2020-02-23 12:21:28 +01:00
2020-05-23 22:12:48 +02:00
if ( this = = & anObjArray ) return * this ; // self assignement
2020-08-12 17:15:47 +02:00
XObjArrayNC < TYPE > : : setEmpty ( ) ;
2020-04-26 12:12:05 +02:00
this - > CheckSize ( anObjArray . length ( ) , 0 ) ;
2020-02-27 15:34:29 +01:00
for ( ui = 0 ; ui < anObjArray . size ( ) ; ui + = 1 ) AddCopy ( anObjArray . ElementAt ( ui ) ) ;
2020-02-23 12:21:28 +01:00
return * this ;
}
/* Destructeur */
template < class TYPE >
XObjArrayNC < TYPE > : : ~ XObjArrayNC ( )
{
//printf("XObjArray Destructor\n");
2020-08-12 17:15:47 +02:00
setEmpty ( ) ;
2020-03-21 14:12:26 +01:00
if ( _Data ) free ( _Data ) ;
2020-02-23 12:21:28 +01:00
}
/* CheckSize() */
template < class TYPE >
2020-08-11 14:43:53 +02:00
void XObjArrayNC < TYPE > : : CheckSize ( size_t nNewSize , size_t nGrowBy )
2020-02-23 12:21:28 +01:00
{
2020-03-09 02:12:24 +01:00
if ( m_allocatedSize < nNewSize ) {
2020-02-23 12:21:28 +01:00
nNewSize + = nGrowBy + 1 ;
2020-04-24 08:36:29 +02:00
_Data = ( XObjArrayEntry < TYPE > * ) Xrealloc ( ( void * ) _Data , sizeof ( XObjArrayEntry < TYPE > ) * nNewSize , sizeof ( XObjArrayEntry < TYPE > ) * m_allocatedSize ) ;
2020-02-23 12:21:28 +01:00
if ( ! _Data ) {
2020-04-24 08:36:29 +02:00
panic ( " XObjArrayNC<TYPE>::CheckSize(nNewSize=%zu, nGrowBy=%zu) : Xrealloc(%zu, %zu, % " PRIuPTR " ) returned NULL. System halted \n " , nNewSize , nGrowBy , m_allocatedSize , sizeof ( XObjArrayEntry < TYPE > ) * nNewSize , ( uintptr_t ) _Data ) ;
2020-02-23 12:21:28 +01:00
}
2020-03-09 02:12:24 +01:00
// memset(&_Data[m_allocatedSize], 0, (nNewSize-m_allocatedSize) * sizeof(XObjArrayEntry<TYPE>));
m_allocatedSize = nNewSize ;
2020-02-23 12:21:28 +01:00
}
}
///* Add() */
//template<class TYPE>
//TYPE &XObjArray<TYPE>::AddNew(bool FreeIt)
//{
// XObjArrayNC<TYPE>::CheckSize(XObjArray<TYPE>::_getLen()+1);
// XObjArray<TYPE>::_Data[XObjArray<TYPE>::_Len].Object = new TYPE;
// XObjArray<TYPE>::_Data[XObjArray<TYPE>::_Len].FreeIt = FreeIt;
// XObjArray<TYPE>::_Len += 1;
// return *((TYPE *)(XObjArray<TYPE>::_Data[XObjArray<TYPE>::_Len-1].Object));
//}
2020-08-11 14:43:53 +02:00
/* Add(TYPE &, size_t) */
2020-02-23 12:21:28 +01:00
template < class TYPE >
2020-08-11 14:43:53 +02:00
size_t XObjArray < TYPE > : : AddCopy ( const TYPE & newElement , bool FreeIt )
2020-02-23 12:21:28 +01:00
{
XObjArrayNC < TYPE > : : CheckSize ( XObjArray < TYPE > : : _Len + 1 ) ;
2020-08-12 17:15:47 +02:00
XObjArray < TYPE > : : _Data [ XObjArray < TYPE > : : _Len ] . Object = new TYPE ( newElement ) ;
2020-02-23 12:21:28 +01:00
XObjArray < TYPE > : : _Data [ XObjArray < TYPE > : : _Len ] . FreeIt = FreeIt ;
XObjArray < TYPE > : : _Len + = 1 ;
return XObjArray < TYPE > : : _Len - 1 ;
}
template < class TYPE >
2020-08-11 14:43:53 +02:00
size_t XObjArray < TYPE > : : AddCopies ( const TYPE & n1 , bool FreeIt )
2020-02-23 12:21:28 +01:00
{
return AddCopy ( n1 , FreeIt ) ;
}
template < class TYPE >
2020-08-11 14:43:53 +02:00
size_t XObjArray < TYPE > : : AddCopies ( const TYPE & n1 , const TYPE & n2 , bool FreeThem )
2020-02-23 12:21:28 +01:00
{
2020-08-11 14:43:53 +02:00
size_t ui = AddCopies ( n1 , FreeThem ) ;
2020-02-23 12:21:28 +01:00
AddCopy ( n2 , FreeThem ) ;
return ui ;
}
template < class TYPE >
2020-08-11 14:43:53 +02:00
size_t XObjArray < TYPE > : : AddCopies ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , bool FreeThem )
2020-02-23 12:21:28 +01:00
{
2020-08-11 14:43:53 +02:00
size_t ui = AddCopies ( n1 , n2 , FreeThem ) ;
2020-02-23 12:21:28 +01:00
AddCopy ( n3 , FreeThem ) ;
return ui ;
}
template < class TYPE >
2020-08-11 14:43:53 +02:00
size_t XObjArray < TYPE > : : AddCopies ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , bool FreeThem )
2020-02-23 12:21:28 +01:00
{
2020-08-11 14:43:53 +02:00
size_t ui = AddCopies ( n1 , n2 , n3 , FreeThem ) ;
2020-02-23 12:21:28 +01:00
AddCopy ( n4 , FreeThem ) ;
return ui ;
}
template < class TYPE >
2020-08-11 14:43:53 +02:00
size_t XObjArray < TYPE > : : AddCopies ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , bool FreeThem )
2020-02-23 12:21:28 +01:00
{
2020-08-11 14:43:53 +02:00
size_t ui = AddCopies ( n1 , n2 , n3 , n4 , FreeThem ) ;
2020-02-23 12:21:28 +01:00
AddCopy ( n5 , FreeThem ) ;
return ui ;
}
template < class TYPE >
2020-08-11 14:43:53 +02:00
size_t XObjArray < TYPE > : : AddCopies ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , bool FreeThem )
2020-02-23 12:21:28 +01:00
{
2020-08-11 14:43:53 +02:00
size_t ui = AddCopies ( n1 , n2 , n3 , n4 , n5 , FreeThem ) ;
2020-02-23 12:21:28 +01:00
AddCopy ( n6 , FreeThem ) ;
return ui ;
}
template < class TYPE >
2020-08-11 14:43:53 +02:00
size_t XObjArray < TYPE > : : AddCopies ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , bool FreeThem )
2020-02-23 12:21:28 +01:00
{
2020-08-11 14:43:53 +02:00
size_t ui = AddCopies ( n1 , n2 , n3 , n4 , n5 , n6 , FreeThem ) ;
2020-02-23 12:21:28 +01:00
AddCopy ( n7 , FreeThem ) ;
return ui ;
}
template < class TYPE >
2020-08-11 14:43:53 +02:00
size_t XObjArray < TYPE > : : AddCopies ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , const TYPE & n8 , bool FreeThem )
2020-02-23 12:21:28 +01:00
{
2020-08-11 14:43:53 +02:00
size_t ui = AddCopies ( n1 , n2 , n3 , n4 , n5 , n6 , n7 , FreeThem ) ;
2020-02-23 12:21:28 +01:00
AddCopy ( n8 , FreeThem ) ;
return ui ;
}
template < class TYPE >
2020-08-11 14:43:53 +02:00
size_t XObjArray < TYPE > : : AddCopies ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , const TYPE & n8 , const TYPE & n9 , bool FreeThem )
2020-02-23 12:21:28 +01:00
{
2020-08-11 14:43:53 +02:00
size_t ui = AddCopies ( n1 , n2 , n3 , n4 , n5 , n6 , n7 , n8 , FreeThem ) ;
2020-02-23 12:21:28 +01:00
AddCopy ( n9 , FreeThem ) ;
return ui ;
}
template < class TYPE >
2020-08-11 14:43:53 +02:00
size_t XObjArray < TYPE > : : AddCopies ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , const TYPE & n8 , const TYPE & n9 , const TYPE & n10 , bool FreeThem )
2020-02-23 12:21:28 +01:00
{
2020-08-11 14:43:53 +02:00
size_t ui = AddCopies ( n1 , n2 , n3 , n4 , n5 , n6 , n7 , n8 , n9 , FreeThem ) ;
2020-02-23 12:21:28 +01:00
AddCopy ( n10 , FreeThem ) ;
return ui ;
}
template < class TYPE >
2020-08-11 14:43:53 +02:00
size_t XObjArray < TYPE > : : AddCopies ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , const TYPE & n8 , const TYPE & n9 , const TYPE & n10 , const TYPE & n11 , bool FreeThem )
2020-02-23 12:21:28 +01:00
{
2020-08-11 14:43:53 +02:00
size_t ui = AddCopies ( n1 , n2 , n3 , n4 , n5 , n6 , n7 , n8 , n9 , n10 , FreeThem ) ;
2020-02-23 12:21:28 +01:00
AddCopy ( n11 , FreeThem ) ;
return ui ;
}
template < class TYPE >
2020-08-11 14:43:53 +02:00
size_t XObjArray < TYPE > : : AddCopies ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , const TYPE & n8 , const TYPE & n9 , const TYPE & n10 , const TYPE & n11 , const TYPE & n12 , bool FreeThem )
2020-02-23 12:21:28 +01:00
{
2020-08-11 14:43:53 +02:00
size_t ui = AddCopies ( n1 , n2 , n3 , n4 , n5 , n6 , n7 , n8 , n9 , n10 , n11 , FreeThem ) ;
2020-02-23 12:21:28 +01:00
AddCopy ( n12 , FreeThem ) ;
return ui ;
}
template < class TYPE >
2020-08-11 14:43:53 +02:00
size_t XObjArray < TYPE > : : AddCopies ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , const TYPE & n8 , const TYPE & n9 , const TYPE & n10 , const TYPE & n11 , const TYPE & n12 , const TYPE & n13 , bool FreeThem )
2020-02-23 12:21:28 +01:00
{
2020-08-11 14:43:53 +02:00
size_t ui = AddCopies ( n1 , n2 , n3 , n4 , n5 , n6 , n7 , n8 , n9 , n10 , n11 , n12 , FreeThem ) ;
2020-02-23 12:21:28 +01:00
AddCopy ( n13 , FreeThem ) ;
return ui ;
}
template < class TYPE >
2020-08-11 14:43:53 +02:00
size_t XObjArray < TYPE > : : AddCopies ( const TYPE & n1 , const TYPE & n2 , const TYPE & n3 , const TYPE & n4 , const TYPE & n5 , const TYPE & n6 , const TYPE & n7 , const TYPE & n8 , const TYPE & n9 , const TYPE & n10 , const TYPE & n11 , const TYPE & n12 , const TYPE & n13 , const TYPE & n14 , bool FreeThem )
2020-02-23 12:21:28 +01:00
{
2020-08-11 14:43:53 +02:00
size_t ui = AddCopies ( n1 , n2 , n3 , n4 , n5 , n6 , n7 , n8 , n9 , n10 , n11 , n12 , n13 , FreeThem ) ;
2020-02-23 12:21:28 +01:00
AddCopy ( n14 , FreeThem ) ;
return ui ;
}
2020-08-11 14:43:53 +02:00
/* Add(TYPE *, size_t) */
2020-02-23 12:21:28 +01:00
template < class TYPE >
2020-08-11 14:43:53 +02:00
size_t XObjArrayNC < TYPE > : : AddReference ( TYPE * newElement , bool FreeIt )
2020-02-23 12:21:28 +01:00
{
XObjArrayNC < TYPE > : : CheckSize ( XObjArrayNC < TYPE > : : _Len + 1 ) ;
XObjArrayNC < TYPE > : : _Data [ XObjArrayNC < TYPE > : : _Len ] . Object = newElement ;
XObjArrayNC < TYPE > : : _Data [ XObjArrayNC < TYPE > : : _Len ] . FreeIt = FreeIt ;
XObjArrayNC < TYPE > : : _Len + = 1 ;
return XObjArrayNC < TYPE > : : _Len - 1 ;
}
2020-08-11 14:43:53 +02:00
/* Insert(TYPE &, size_t) */
2020-02-23 12:21:28 +01:00
template < class TYPE >
2020-08-11 14:43:53 +02:00
size_t XObjArray < TYPE > : : InsertCopy ( const TYPE & newElement , size_t pos )
2020-02-23 12:21:28 +01:00
{
if ( pos < XObjArray < TYPE > : : _Len ) {
XObjArrayNC < TYPE > : : CheckSize ( XObjArray < TYPE > : : _Len + 1 ) ;
memmove ( & XObjArray < TYPE > : : _Data [ pos + 1 ] , & XObjArray < TYPE > : : _Data [ pos ] , ( XObjArray < TYPE > : : _Len - pos ) * sizeof ( XObjArrayEntry < TYPE > ) ) ;
XObjArray < TYPE > : : _Data [ pos ] . Object = new TYPE ( newElement ) ;
XObjArray < TYPE > : : _Data [ pos ] . FreeIt = true ;
XObjArray < TYPE > : : _Len + = 1 ;
return pos ;
} else {
return AddCopy ( newElement ) ;
}
}
2020-08-11 14:43:53 +02:00
/* Insert(TYPE &, size_t) */
2020-02-23 12:21:28 +01:00
template < class TYPE >
2020-08-11 14:43:53 +02:00
size_t XObjArrayNC < TYPE > : : InsertRef ( TYPE * newElement , size_t pos , bool FreeIt )
2020-02-23 12:21:28 +01:00
{
if ( pos < XObjArrayNC < TYPE > : : _Len ) {
CheckSize ( XObjArrayNC < TYPE > : : _Len + 1 ) ;
memmove ( & XObjArrayNC < TYPE > : : _Data [ pos + 1 ] , & XObjArrayNC < TYPE > : : _Data [ pos ] , ( XObjArrayNC < TYPE > : : _Len - pos ) * sizeof ( XObjArrayEntry < TYPE > ) ) ;
_Data [ pos ] . Object = newElement ;
_Data [ pos ] . FreeIt = FreeIt ;
XObjArrayNC < TYPE > : : _Len + = 1 ;
return pos ;
} else {
2020-09-14 15:01:30 +02:00
return AddReference ( newElement , FreeIt ) ;
2020-02-23 12:21:28 +01:00
}
}
2020-08-11 14:43:53 +02:00
/* SetFreeIt(size_t, bool) */
2020-02-23 12:21:28 +01:00
template < class TYPE >
2020-08-11 14:43:53 +02:00
void XObjArrayNC < TYPE > : : SetFreeIt ( size_t nIndex , bool Flag )
2020-02-23 12:21:28 +01:00
{
if ( nIndex < XObjArrayNC < TYPE > : : _Len )
{
XObjArrayNC < TYPE > : : _Data [ nIndex ] . FreeIt = Flag ;
}
else {
# if defined(_DEBUG)
2020-08-11 14:43:53 +02:00
throw " XObjArray::SetFreeIt(size_t) -> nIndex >= _Len \n " ;
2020-02-23 12:21:28 +01:00
# endif
}
}
/* SetFreeIt(const TYPE *Element, bool) */
template < class TYPE >
void XObjArrayNC < TYPE > : : SetFreeIt ( const TYPE * Element , bool Flag )
{
2020-08-11 14:43:53 +02:00
size_t i ;
2020-02-23 12:21:28 +01:00
for ( i = 0 ; i < XObjArrayNC < TYPE > : : _Len ; i + = 1 ) {
if ( ( ( TYPE * ) XObjArrayNC < TYPE > : : _Data [ i ] . Object ) = = Element ) {
SetFreeIt ( i , Flag ) ;
return ;
}
}
# if defined(_DEBUG)
throw " XObjArray::SetFreeIt(const TYPE *) -> nIndex >= _Len \n " ;
# endif
}
2020-08-11 14:43:53 +02:00
/* Remove(size_t) */
2020-02-23 12:21:28 +01:00
template < class TYPE >
2020-08-11 14:43:53 +02:00
void XObjArrayNC < TYPE > : : RemoveAtIndex ( size_t nIndex )
2020-02-23 12:21:28 +01:00
{
2020-08-17 21:40:52 +02:00
if ( nIndex > = XObjArrayNC < TYPE > : : _Len ) {
panic ( " void XObjArrayNC<TYPE>::RemoveAtIndex(size_t nIndex) : BUG nIndex (%zu) is > length(). System halted \n " , nIndex ) ;
}
2020-02-23 12:21:28 +01:00
if ( _Data [ nIndex ] . FreeIt )
{
TYPE * TmpObject ; // BCB 4 oblige me to use a tmp var for doing the delete.
TmpObject = ( TYPE * ) ( _Data [ nIndex ] . Object ) ;
delete TmpObject ;
}
2020-03-21 14:12:26 +01:00
if ( nIndex < XObjArrayNC < TYPE > : : _Len - 1 ) memmove ( & _Data [ nIndex ] , & _Data [ nIndex + 1 ] , ( _Len - nIndex - 1 ) * sizeof ( XObjArrayEntry < TYPE > ) ) ;
2020-02-23 12:21:28 +01:00
_Len - = 1 ;
return ;
}
//-------------------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------------
2020-08-11 14:43:53 +02:00
/* RemoveWithoutFreeing(size_t) */
2020-02-23 12:21:28 +01:00
template < class TYPE >
2020-08-17 21:40:52 +02:00
void XObjArrayNC < TYPE > : : RemoveWithoutFreeingAtIndex ( size_t nIndex )
2020-02-23 12:21:28 +01:00
{
if ( nIndex < _Len )
{
if ( nIndex < _Len - 1 ) memcpy ( & _Data [ nIndex ] , & _Data [ nIndex + 1 ] , ( _Len - nIndex - 1 ) * sizeof ( XObjArrayEntry < TYPE > ) ) ;
_Len - = 1 ;
return ;
}
# if defined(_DEBUG)
2020-08-17 21:40:52 +02:00
panic ( " XObjArray::RemoveWithoutFreeing(size_t) -> nIndex > _Len " ) ;
2020-02-23 12:21:28 +01:00
# endif
}
//-------------------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------------
/* Remove(int) */
template < class TYPE >
void XObjArrayNC < TYPE > : : RemoveAtIndex ( int nIndex )
{
2020-04-24 08:36:29 +02:00
# if defined(__XTOOLS_CHECK_OVERFLOW__)
2020-02-23 12:21:28 +01:00
if ( nIndex < 0 ) {
2020-04-24 11:30:09 +02:00
panic ( " XArray<TYPE>::RemoveAtIndex(int nIndex) : BUG nIndex (%d) is < 0. System halted \n " , nIndex ) ;
}
2020-02-23 12:21:28 +01:00
# endif
2020-08-11 14:43:53 +02:00
RemoveAtIndex ( ( size_t ) nIndex ) ; // Remove(size_t) will check that index is < _Len
2020-02-23 12:21:28 +01:00
}
/* Remove(const TYPE &) */
template < class TYPE >
void XObjArrayNC < TYPE > : : Remove ( const TYPE & Element )
{
2020-08-11 14:43:53 +02:00
size_t i ;
2020-02-23 12:21:28 +01:00
for ( i = 0 ; i < _Len ; i + = 1 ) {
if ( * ( ( TYPE * ) ( _Data [ i ] . Object ) ) = = Element ) {
2020-04-05 14:25:39 +02:00
RemoveAtIndex ( i ) ;
2020-02-23 12:21:28 +01:00
return ;
}
}
# if defined(_DEBUG)
2020-04-24 11:30:09 +02:00
printf ( " XObjArray::Remove(TYPE &) -> Not found \n " ) ;
2020-04-05 14:25:39 +02:00
panic ( ) ;
2020-02-23 12:21:28 +01:00
# endif
}
//-------------------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------------
/* Remove(const TYPE *) */
template < class TYPE >
void XObjArrayNC < TYPE > : : Remove ( const TYPE * Element )
{
2020-08-11 14:43:53 +02:00
size_t i ;
2020-02-23 12:21:28 +01:00
for ( i = 0 ; i < _Len ; i + = 1 ) {
if ( ( ( TYPE * ) _Data [ i ] . Object ) = = Element ) {
Remove ( i ) ;
return ;
}
}
# if defined(_DEBUG)
throw " XObjArray::Remove(TYPE *) -> not found \n " ;
# endif
}
//-------------------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------------
/* RemoveWithoutFreeing(const TYPE *) */
template < class TYPE >
void XObjArrayNC < TYPE > : : RemoveWithoutFreeing ( const TYPE * Element )
{
2020-08-11 14:43:53 +02:00
size_t i ;
2020-02-23 12:21:28 +01:00
for ( i = 0 ; i < _Len ; i + = 1 ) {
if ( ( ( TYPE * ) _Data [ i ] . Object ) = = Element ) {
RemoveWithoutFreeing ( i ) ;
return ;
}
}
# if defined(_DEBUG)
throw " XObjArray::RemoveWithoutFreeing(TYPE *) -> not found \n " ;
# endif
}
//-------------------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------------
template < class TYPE >
void XObjArrayNC < TYPE > : : RemoveAllBut ( const TYPE * Element )
{
2020-08-11 14:43:53 +02:00
size_t i ;
2020-02-23 12:21:28 +01:00
for ( i = _Len ; i - - ; ) {
if ( ( ( TYPE * ) _Data [ i ] . Object ) ! = Element ) {
Remove ( i ) ;
}
}
}
/* Empty() */
template < class TYPE >
2020-08-12 17:15:47 +02:00
void XObjArrayNC < TYPE > : : setEmpty ( )
2020-02-23 12:21:28 +01:00
{
2020-08-11 14:43:53 +02:00
size_t i ;
2020-02-23 12:21:28 +01:00
if ( _Len > 0 ) {
for ( i = 0 ; i < _Len ; i + = 1 ) {
if ( _Data [ i ] . FreeIt )
{
TYPE * TmpObject ; // BCB 4 oblige me to use a tmp var for doing the delete.
TmpObject = ( TYPE * ) ( _Data [ i ] . Object ) ;
delete TmpObject ;
}
}
_Len = 0 ;
}
}
# endif