Dynamic array of pointers This is a template for a dynamic array of pointers
![]() | increment_ linear growth increment |
![]() | vector_ dynamic array of pointers |
![]() | ~PtrVec ( void ) Destructor |
![]() | PtrVec ( bool internal=true, size_t capacity=0, size_t increment=0 ) Default constructor |
![]() | PtrVec ( const PtrVec&, bool internalize = true ) Copy constructor |
![]() | copy ( const PtrVec&, bool internalize ) Copy method |
![]() | operator = ( const PtrVec &obj ) Assignment/copy operator |
![]() | () ( size_t index ) const Efficient array operator (const version): no bounds checking |
![]() | () ( size_t index ) Efficient array operator (non-const version): no bounds checking |
![]() | operator [] ( size_t index ) const Bounds-checking array operator (const version): throws sxBoundsError |
![]() | operator [] ( size_t index ) Bounds-checking array operator (non-const version): throws sxBoundsError |
![]() | at ( size_t index ) Bounds-adjusting array operator |
![]() | length ( void ) const Returns current occupied length of array |
![]() | entries ( void ) const Return the number of non-NULL entries in vector |
![]() | append ( T* ) Append: efficiently insert given element at end of array |
![]() | insert ( size_t count, size_t offset = 0 ) Insert new array elements |
![]() | nextEmpty () Return the index of the next available empty slot |
![]() | add ( T* ) Add a new array element in the first available empty slot |
![]() | index ( const T* ) Return the index of the given element |
![]() | cut ( size_t count, size_t offset = 0 ) Remove array elements |
![]() | remove ( size_t offset ) Removes the element specified by offset |
![]() | internalize ( void ) Replace external pointers with internal copies of the referenced objects |
![]() | externalize ( void ) Change status of pointers to external |
![]() | internal ( void ) const internal method: returns true if the pointers are internal |
Dynamic array of pointers This is a template for a dynamic array of pointers. The design is very similar to the general-purpose version, ValVec, but specialized according to the memory management issues peculiar to storing pointers. This version uses nil as the fill value, which cannot be customized or disabled. By default, the cut method uses the delete operator to free pointers as they are removed from the array. Before disposing the array, the destructor clears it out with cut. This behavior is avoided if the pointers are designated as external, or shared. In that case it is entirely up to the user to free pointers left dangling by cut. When copying the array, one must choose whether the copy will share with the original the objects referenced by the pointers (shallow copy), or whether the copy will have its own internal duplicates.--------------- WARNING ---------------
The user must provide a specialization of PtrDup() for every polymorphic class that will instantiate this template. Failure to do this may result in unexpected truncation of derived objects. The template methods use PtrDup() when duplication of objects is required, but duplicating a polymorphic object requires assistance from the object itself. For example, consider class B:
class B { public: virtual B* duplicate(void) const = 0; }; inline B* PtrDup(const B *b) { return b ? b->duplicate() : 0; }To avoid confusion and mistakes, place the specialization immediately after the declaration of class B. If class B does not have a duplicator use the following specialization instead:inline B* PtrDup(const B *b) { if (b) throw sxUnimplemented("PtrDup","class B has no duplicator"); else return 0; }
PtrVec( bool internal=true, size_t capacity=0, size_t increment=0 )
PtrVec( const PtrVec&, bool internalize = true )
PtrVec& copy( const PtrVec&, bool internalize )
PtrVec& operator =( const PtrVec &obj )
const T*& operator ()( size_t index ) const
T*& operator ()( size_t index )
const T*& operator []( size_t index ) const
T*& operator []( size_t index )
T*& at( size_t index )
size_t length( void ) const
size_t entries( void ) const
size_t append( T* )
size_t insert( size_t count, size_t offset = 0 )
size_t nextEmpty()
size_t add( T* )
int index( const T* )
size_t cut( size_t count, size_t offset = 0 )
void remove( size_t offset )
cut(1, length-offset-1)
void internalize( void )
void externalize( void )
bool internal( void ) const
alphabetic index hierarchy of classes