Classes | Public Types | Public Member Functions | List of all members
blaze::PtrVector< T, D, G > Class Template Reference

Implementation of a vector for (polymorphic) pointers. More...

#include <PtrVector.h>

Classes

class  CastIterator
 Dynamic cast iterator for polymorphic pointer vectors.The CastIterator class is part of the PtrVector class and represent a forward iterator over all elements of type C contained in a range of elements of type T, where C is a type derived from T. More...
 
class  ConstCastIterator
 Dynamic cast iterator for polymorphic pointer vectors.The ConstCastIterator class is part of the PtrVector class and represent a forward iterator over all elements of type C contained in a range of elements of type T, where C is a type derived from T. The ConstCastIterator is the counterpart of CastIterator for constant vectors. More...
 

Public Types

typedef T * ValueType
 Type of the underlying values.
 
typedef T * PointerType
 Pointer to a non-const object.
 
typedef const T * ConstPointerType
 Pointer to a const object.
 
typedef T *& ReferenceType
 Reference to a non-const object.
 
typedef T *const & ConstReferenceType
 Reference to a const object.
 
typedef size_t SizeType
 Size type of the pointer vector.
 
typedef PtrIterator< T > Iterator
 Iterator over non-const objects.
 
typedef PtrIterator< const T > ConstIterator
 Iterator over const objects.
 
typedef D DeletionPolicy
 Type of the deletion policy.
 
typedef G GrowthPolicy
 Type of the growth policy.
 
typedef ValueType value_type
 Type of the underlying values.
 
typedef PointerType pointer
 Pointer to a non-const object.
 
typedef ConstPointerType const_pointer
 Pointer to a const object.
 
typedef ReferenceType reference
 Reference to a non-const object.
 
typedef ConstReferenceType const_reference
 Reference to a const object.
 
typedef SizeType size_type
 Size type of the pointer vector.
 

Public Member Functions

template<typename T2 , typename D2 , typename G2 >
PtrVector< T, D, G > & operator= (const PtrVector< T2, D2, G2 > &pv)
 Assignment operator for different PtrVector instances. More...
 
template<typename C >
PtrVector< T, D, G >::BLAZE_TEMPLATE CastIterator< C > erase (CastIterator< C > pos)
 Removing an element from the pointer vector. More...
 
template<typename C >
PtrVector< T, D, G >::BLAZE_TEMPLATE CastIterator< C > release (CastIterator< C > pos)
 Releasing an element from the pointer vector. More...
 
Constructors
 PtrVector (SizeType initCapacity=0)
 Standard constructor for PtrVector. More...
 
 PtrVector (const PtrVector &pv)
 Copy constructor for PtrVector. More...
 
template<typename T2 , typename D2 , typename G2 >
 PtrVector (const PtrVector< T2, D2, G2 > &pv)
 Conversion constructor from different PtrVector instances. More...
 
Destructor
 ~PtrVector ()
 Destructor for PtrVector. More...
 
Assignment operators
PtrVectoroperator= (const PtrVector &pv)
 Copy assignment operator for PtrVector. More...
 
template<typename T2 , typename D2 , typename G2 >
PtrVectoroperator= (const PtrVector< T2, D2, G2 > &pv)
 
Get functions
SizeType maxSize () const
 Returns the maximum possible size of a pointer vector. More...
 
SizeType size () const
 Returns the current size of the pointer vector. More...
 
template<typename C >
SizeType size () const
 
SizeType capacity () const
 Returns the capacity of the pointer vector. More...
 
bool isEmpty () const
 Returns true if the pointer vector has no elements. More...
 
Access functions
ReferenceType operator[] (SizeType index)
 Subscript operator for the direct access to the pointer vector elements. More...
 
ConstReferenceType operator[] (SizeType index) const
 Subscript operator for the direct access to the pointer vector elements. More...
 
ReferenceType front ()
 Returns a reference to the first element of the pointer vector. More...
 
ConstReferenceType front () const
 Returns a reference to the first element of the pointer vector. More...
 
ReferenceType back ()
 Returns a reference to the last element of the pointer vector. More...
 
ConstReferenceType back () const
 Returns a reference to the last element of the pointer vector. More...
 
Iterator functions
Iterator begin ()
 Returns an iterator to the beginning of the pointer vector. More...
 
ConstIterator begin () const
 Returns an iterator to the beginning of the pointer vector. More...
 
template<typename C >
CastIterator< C > begin ()
 
template<typename C >
ConstCastIterator< C > begin () const
 
Iterator end ()
 Returns an iterator just past the last element of the pointer vector. More...
 
ConstIterator end () const
 Returns an iterator just past the last element of the pointer vector. More...
 
template<typename C >
CastIterator< C > end ()
 
template<typename C >
ConstCastIterator< C > end () const
 
Element functions
void pushBack (PointerType p)
 Adding an element to the end of the pointer vector. More...
 
void popBack ()
 Removing an element from the end of the pointer vector. More...
 
void releaseBack ()
 Releasing the element at the end of the pointer vector. More...
 
template<typename IteratorType >
void assign (IteratorType first, IteratorType last)
 Assigning a range of elements to the pointer vector. More...
 
Iterator insert (Iterator pos, PointerType p)
 Inserting an element into the pointer vector. More...
 
template<typename IteratorType >
void insert (Iterator pos, IteratorType first, IteratorType last)
 Inserting a range of elements into the pointer vector. More...
 
Iterator erase (Iterator pos)
 Removing an element from the pointer vector. More...
 
template<typename C >
CastIterator< C > erase (CastIterator< C > pos)
 
Iterator release (Iterator pos)
 Releasing an element from the pointer vector. More...
 
template<typename C >
CastIterator< C > release (CastIterator< C > pos)
 
void clear ()
 Removing all elements from the pointer vector. More...
 
Utility functions
void reserve (SizeType newCapacity)
 Setting the minimum capacity of the pointer vector. More...
 
void swap (PtrVector &pv)
 Swapping the contents of two pointer vectors. More...
 

Private Member Functions

Helper functions
size_t calcCapacity (size_t minCapacity) const
 Calculating the new capacity of the vector based on its growth policy. More...
 
void deleteElement (PointerType ptr) const
 Deleting an element of the pointer vector according to the deletion policy. More...
 
Insertion helper functions
void insert (T **const pos, PointerType p)
 Inserting an element into the pointer vector. More...
 
template<typename IteratorType >
void insert (T **pos, IteratorType first, IteratorType last, SizeType n)
 Inserting a range of elements into the pointer vector. More...
 

Private Attributes

Member variables
SizeType size_
 The current size of the pointer vector.
 
SizeType capacity_
 The capacity of the pointer vector.
 
PointerTypebegin_
 Pointer to the first element of the pointer vector.
 
PointerTypeend_
 Pointer to the last element of the pointer vector.
 

Friends

CastIterator/ConstCastIterator comparison operators
template<typename L , typename R >
bool operator== (const CastIterator< L > &lhs, const CastIterator< R > &rhs)
 Equality comparison between two CastIterator objects. More...
 
template<typename L , typename R >
bool operator== (const CastIterator< L > &lhs, const ConstCastIterator< R > &rhs)
 Equality comparison between a CastIterator and a ConstCastIterator. More...
 
template<typename L , typename R >
bool operator== (const ConstCastIterator< L > &lhs, const CastIterator< R > &rhs)
 Equality comparison between a ConstCastIterator and a CastIterator. More...
 
template<typename L , typename R >
bool operator== (const ConstCastIterator< L > &lhs, const ConstCastIterator< R > &rhs)
 Equality comparison between two ConstCastIterator objects. More...
 
template<typename L , typename R >
bool operator!= (const CastIterator< L > &lhs, const CastIterator< R > &rhs)
 Inequality comparison between two CastIterator objects. More...
 
template<typename L , typename R >
bool operator!= (const CastIterator< L > &lhs, const ConstCastIterator< R > &rhs)
 Inequality comparison between a CastIterator and a ConstCastIterator. More...
 
template<typename L , typename R >
bool operator!= (const ConstCastIterator< L > &lhs, const CastIterator< R > &rhs)
 Inequality comparison between a ConstCastIterator and a CastIterator. More...
 
template<typename L , typename R >
bool operator!= (const ConstCastIterator< L > &lhs, const ConstCastIterator< R > &rhs)
 Inequality comparison between two ConstCastIterator objects. More...
 

Detailed Description

template<typename T, typename D = PtrDelete, typename G = OptimalGrowth>
class blaze::PtrVector< T, D, G >

Implementation of a vector for (polymorphic) pointers.

Basic usage

The std::vector is one of the standard libraries most useful tools. It is the standard solution for a dynamically allocated, automatically growing, and memory managed array. It provides fast random access to its elements, since a vector guarantees that the elements lie adjacent in memory and manages the dynamically allocated memory according to the RAII idiom.
Yet there are some situations, where users of std::vector experience several drawbacks, especially when std::vector is used in combination with pointers. For instance, a const_iterator over a range of pointers will not allow the stored pointers to change, but the objects behind the pointers remain changeable. The following example illustrates that it is possible to change the values of double values through an iterator-to-const:

typedef std::vector<double*> Doubles;
Doubles doubles; // Creating a vector for pointers to double values
// Filling the vector with pointers to double values. All values are initialized with 1.
for( size_t i=0; i<10; ++i )
doubles.push_back( new double( 1.0 ) );
// Accessing the first rigid body
Doubles::const_iterator first = doubles.begin();
*first = 2.0; // Changes the double value through an iterator-to-const

The basic reason for this behavior is that std::vector is unaware of the fact that it stores pointers instead of objects and therefore the pointer are considered constant, not the objects behind the pointer.
Another drawback of std::vector is the fact that during destruction of a vector object the dynamically allocated bodies are not deleted. Again, std::vector is unaware of the special property of pointers and therefore does not apply any kind of deletion policy. It basically calls the default destructor for pointers, which in turn does nothing and especially does not destroy the attached objects.
A different approach is taken by the Boost ptr_vector. A ptr_vector is perfectly aware of the fact that is stores pointers to dynamically objects (and in consequence may only be used with pointers to dynamically allocated objects) and takes full responsibilty for these resources. However, in order to accomplish this task, ptr_vector completely abstracts from the fact that it stores pointers and provides a view as if it would contain objects instead of pointers. Unfortunately, this strict memory management might cause problems, for instance in case the vector to pointers is used both internally (including proper resource management) and outside by the user (without any resource management).
In case both std::vector and boost::ptr_vector are not suitable data structures, the Blaze library provides a special vector container for pointers, which is a cross of the functionalities of the std::vector and ptr_vector. The Blaze PtrVector is not a RAII class in the classic sense (as for instance the Boost ptr_vector) since it does not strictly encapsule the resource management. As in the case of std::vector, it still is the responsibility of a user of PtrVector to manage the resources accordingly. However, PtrVector can be used internally to store pointers to dynamically allocated objects and resources within RAII classes, and outside by a user as storage for handles to resources that are managed elsewhere. In contrast to the boost::ptr_vector, the PtrVector provides full access to the contained pointers, but its iterators work similar to the ptr_vector iterator and only provide access to the objects behind the pointers, creating the illusion that objects are stored instead of pointers:

typedef blaze::PtrVector<double> Doubles;
Doubles doubles; // Creating an empty PtrVector for pointers to double values
doubles.pushBack( new double(1.0) ); // A new pointer-to-double is added to the vector
double_vector::iterator first = doubles.begin();
*first = 2.0; // No indirection needed
Doubles::ConstIterator second( first+1 );
*second = 3.0; // Compile time error! It is not possible to change double
// values via an iterator-to-const

Notice the differences in the usage of the iterator in contrast to the std::vector and boost::ptr_vector. In contrast to them the functions of PtrVector follow the naming convention of the Blaze library (i.e. pushBack instead of push_back). In addition, the underlying iterator adds an additional dereference to all access operators, which eases the access to the underlying objects:

// STL style:
*first = 2.0;
// pe style:
*first = 2.0;

A noteworthy difference between the STL vector and the pointer vector is the used template argument: instead of the pointer type, the Blaze pointer vector is only provided with the type of the underlying objects:

// STL style:
std::vector<double*> vector;
// pe style:

Additionally, the Blaze pointer vector offers some limited possibilities to configure the memory management and the growth of the internal storage, and implements special features for polymorphic pointers, as for instance a convenient way to iterate over a subset of polymorphic objects contained in the pointer vector.

Polymorphic pointers

For polymorphic pointers, the PtrVector class additionally offers two special iterators to iterate over all objects of a specific type: the CastIterator and ConstCastIterator.

// Definition of class A and the derived type B
class A { ... };
class B : public A { ... };
// Definition of function f for non-const pointer vectors
void f( blaze::PtrVector<A>& vector )
{
// Loop over all objects of type B contained in the vector
for( ; begin!=end; ++begin )
...
}
// Definition of function f for const pointer vectors
void f( const blaze::PtrVector<A>& vector )
{
// Loop over all objects of type B contained in the vector
for( ; begin!=end; ++begin )
}

In the example, the cast iterators are used to iterate over all objects of type B within the pointer vector, where B must be a type derived from A. The attempt to use these iterators for types that are not derived from A results in a compile time error. Note that the usage of the cast iterators is computaionally more expensive than the use of the standard iterators. Therefore these iterators should not be used unless a down-cast is really necessary, e.g. in order to access a type specific function.

Using a pointer vector within other container classes

If a pointer vector is used within an other container and is used to store polymorphic pointers, you might face the problem of not being able to create type definitions for the cast iterators. Whereas it is possible to create typedefs for the standard iterators, it is unfortunately not possible (yet) to create type definitions for template classes. In order to create a new return type within the container, the following approach could be taken:

template< typename A >
class Container
{
public:
template< typename C >
struct CastIterator : public blaze::PtrVector<A>::CastIterator<C>
{
CastIterator( const blaze::PtrVector<A>::CastIterator<C>& it )
: blaze::PtrVector<A>::CastIterator<C>( it ) // Initializing the base class
{}
};
template< typename C >
CastIterator<C> begin();
template< typename C >
CastIterator<C> end();
private:
};

Instead of a typedef within the Container class, a new class CastIterator is derived from the PtrVector::CastIterator class. This approach acts similar as the typedef as a user can now use the Container as follows:

class A { ... };
class B : public A { ... };
Container<A>::CastIterator<B> begin;

This provides the same abstraction from the internal implementation as the desired typedef. The same approach could be taken for a ConstCastIterator definition.

Adapting a pointer vector

The growth and deletion behavior of the PtrVector class can be adapted to any specific task. The second template argument of the PtrVector specifies the growth rate. The following growth rates can be selected:

The third template argument of the PtrVector specifies the deletion behavior for the case that the pointer vector is destroyed. Note that the deletion behavior has only limited effect on the memory management of the contained resources. For instance, copying a PtrVector always results in a shallow copy, i.e., the contained resources are not copied/cloned. Therefore the deletion policy should be considered a convenience functionality in the context of a resource managing class. The following policies can be selected:

Constructor & Destructor Documentation

template<typename T , typename D , typename G >
blaze::PtrVector< T, D, G >::PtrVector ( SizeType  initCapacity = 0)
inlineexplicit

Standard constructor for PtrVector.

Parameters
initCapacityThe initial capacity of the pointer vector.

The default initial capacity of the pointer vector is specified by the selected growth policy.

template<typename T , typename D , typename G >
blaze::PtrVector< T, D, G >::PtrVector ( const PtrVector< T, D, G > &  pv)
inline

Copy constructor for PtrVector.

Parameters
pvThe pointer vector to be copied.
template<typename T , typename D , typename G >
template<typename T2 , typename D2 , typename G2 >
blaze::PtrVector< T, D, G >::PtrVector ( const PtrVector< T2, D2, G2 > &  pv)
inline

Conversion constructor from different PtrVector instances.

Parameters
pvThe pointer vector to be copied.
template<typename T , typename D , typename G >
blaze::PtrVector< T, D, G >::~PtrVector ( )
inline

Destructor for PtrVector.

In the destructor, the selected deletion policy is applied to all elements of the pointer vector.

Member Function Documentation

template<typename T , typename D , typename G >
template<typename IteratorType >
void blaze::PtrVector< T, D, G >::assign ( IteratorType  first,
IteratorType  last 
)
inline

Assigning a range of elements to the pointer vector.

Parameters
firstIterator to the first element of the element range.
lastIterator to the element one past the last element of the element range.
Returns
void
Exceptions
std::length_errorMaximum pointer vector length exceeded.

This functions assigns the elements in the range $ [first,last) $ to the pointer vector. All elements previously contained in the pointer vector are removed. The assign function runs in linear time.

template<typename T , typename D , typename G >
PtrVector< T, D, G >::ReferenceType blaze::PtrVector< T, D, G >::back ( )
inline

Returns a reference to the last element of the pointer vector.

Returns
Handle to the last element.

Note: No runtime check is performed if the last element exists!

template<typename T , typename D , typename G >
PtrVector< T, D, G >::ConstReferenceType blaze::PtrVector< T, D, G >::back ( ) const
inline

Returns a reference to the last element of the pointer vector.

Returns
Handle to the last element.

Note: No runtime check is performed if the last element exists!

template<typename T , typename D , typename G >
PtrVector< T, D, G >::BLAZE_TEMPLATE CastIterator< C > blaze::PtrVector< T, D, G >::begin ( )
inline

Returns an iterator to the beginning of the pointer vector.

Returns an iterator to the first element of type C within the pointer vector.

Returns
Iterator to the beginning of the pointer vector.
Iterator to the first element of type C.

This function returns an iterator to the first element of type C within in the pointer vector, where C is a type derived from the type T of objects contained in the pointer vector. In case there is no element of type C contained in the vector, an iterator just past the last element of the pointer vector is returned. In combination with the according end function (see example), this iterator allows to iterate over all objects of type C in the range of the pointer vector. The attempt to use this function for types that are not derived from T results in a compile time error.

// Definition of class A and the derived type B
class A { ... };
class B : public A { ... };
// Definition of function f for non-const pointer vectors
void f( blaze::PtrVector<A>& vector )
{
blaze::PtrVector<A>::CastIterator<B> begin = vector.begin<B>();
blaze::PtrVector<A>::CastIterator<B> end = vector.end<B>();
// Loop over all objects of type B contained in the vector
for( ; begin!=end; ++begin )
...
}
// Definition of function f for const pointer vectors
void f( const blaze::PtrVector<A>& vector )
{
// Loop over all objects of type B contained in the vector
for( ; begin!=end; ++begin )
}

Note: Using the templated versions of begin() and end() to traverse all elements of type C in the element range of the pointer vector is more expensive than using the non-template versions to traverse the entire range of elements. Use this function only if you require a type-specific member of type C.

template<typename T , typename D , typename G >
PtrVector< T, D, G >::BLAZE_TEMPLATE ConstCastIterator< C > blaze::PtrVector< T, D, G >::begin ( ) const
inline

Returns an iterator to the beginning of the pointer vector.

Returns an iterator to the first element of type C within the pointer vector.

Returns
Iterator to the beginning of the pointer vector.
Iterator to the first element of type C.

This function returns an iterator to the first element of type C within in the pointer vector, where C is a type derived from the type T of objects contained in the pointer vector. In case there is no element of type C contained in the vector, an iterator just past the last element of the pointer vector is returned. In combination with the according end function (see example), this iterator allows to iterate over all objects of type C in the range of the pointer vector. The attempt to use this function for types that are not derived from T results in a compile time error.

// Definition of class A and the derived type B
class A { ... };
class B : public A { ... };
// Definition of function f for non-const pointer vectors
void f( blaze::PtrVector<A>& vector )
{
blaze::PtrVector<A>::CastIterator<B> begin = vector.begin<B>();
blaze::PtrVector<A>::CastIterator<B> end = vector.end<B>();
// Loop over all objects of type B contained in the vector
for( ; begin!=end; ++begin )
...
}
// Definition of function f for const pointer vectors
void f( const blaze::PtrVector<A>& vector )
{
// Loop over all objects of type B contained in the vector
for( ; begin!=end; ++begin )
}

Note: Using the templated versions of begin() and end() to traverse all elements of type C in the element range of the pointer vector is more expensive than using the non-template version to traverse the entire range of elements. Use this function only if you require a type-specific member of type C.

template<typename T , typename D , typename G >
size_t blaze::PtrVector< T, D, G >::calcCapacity ( size_t  minCapacity) const
inlineprivate

Calculating the new capacity of the vector based on its growth policy.

Parameters
minCapacityThe minimum necessary capacity.
Returns
The new capacity.
template<typename T , typename D , typename G >
PtrVector< T, D, G >::SizeType blaze::PtrVector< T, D, G >::capacity ( ) const
inline

Returns the capacity of the pointer vector.

Returns
The capacity.
template<typename T , typename D , typename G >
void blaze::PtrVector< T, D, G >::clear ( )
inline

Removing all elements from the pointer vector.

Returns
void
template<typename T , typename D , typename G >
void blaze::PtrVector< T, D, G >::deleteElement ( PointerType  ptr) const
inlineprivate

Deleting an element of the pointer vector according to the deletion policy.

Parameters
ptrThe element to be deleted.
Returns
void
template<typename T , typename D , typename G >
PtrVector< T, D, G >::BLAZE_TEMPLATE CastIterator< C > blaze::PtrVector< T, D, G >::end ( )
inline

Returns an iterator just past the last element of the pointer vector.

Returns
Iterator just past the last element of the pointer vector.
Iterator just past the last element of the pointer vector.

This function returns an iterator just past the last element of the pointer vector. In combination with the according begin function (see example), this iterator allows to iterate over all objects of type C in the range of the pointer vector. The attempt to use this function for types that are not derived from T results in a compile time error.

// Definition of class A and the derived type B
class A { ... };
class B : public A { ... };
// Definition of function f for non-const pointer vectors
void f( blaze::PtrVector<A>& vector )
{
blaze::PtrVector<A>::CastIterator<B> begin = vector.begin<B>();
blaze::PtrVector<A>::CastIterator<B> end = vector.end<B>();
// Loop over all objects of type B contained in the vector
for( ; begin!=end; ++begin )
...
}
// Definition of function f for const pointer vectors
void f( const blaze::PtrVector<A>& vector )
{
// Loop over all objects of type B contained in the vector
for( ; begin!=end; ++begin )
}

Note: Using the templated versions of begin() and end() to traverse all elements of type C in the element range of the pointer vector is more expensive than using the non-template versions to traverse the entire range of elements. Use this function only if you require a type-specific member of type C.

template<typename T , typename D , typename G >
PtrVector< T, D, G >::BLAZE_TEMPLATE ConstCastIterator< C > blaze::PtrVector< T, D, G >::end ( ) const
inline

Returns an iterator just past the last element of the pointer vector.

Returns
Iterator just past the last element of the pointer vector.
Iterator just past the last element of the pointer vector.

This function returns an iterator just past the last element of the pointer vector. In combination with the according begin function (see example), this iterator allows to iterate over all objects of type C in the range of the pointer vector. The attempt to use this function for types that are not derived from T results in a compile time error.

// Definition of class A and the derived type B
class A { ... };
class B : public A { ... };
// Definition of function f for non-const pointer vectors
void f( blaze::PtrVector<A>& vector )
{
blaze::PtrVector<A>::CastIterator<B> begin = vector.begin<B>();
blaze::PtrVector<A>::CastIterator<B> end = vector.end<B>();
// Loop over all objects of type B contained in the vector
for( ; begin!=end; ++begin )
...
}
// Definition of function f for const pointer vectors
void f( const blaze::PtrVector<A>& vector )
{
// Loop over all objects of type B contained in the vector
for( ; begin!=end; ++begin )
}

Note: Using the templated versions of begin() and end() to traverse all elements of type C in the element range of the pointer vector is more expensive than using the non-template version to traverse the entire range of elements. Use this function only if you require a type-specific member of type C.

template<typename T , typename D , typename G >
PtrVector< T, D, G >::Iterator blaze::PtrVector< T, D, G >::erase ( Iterator  pos)
inline

Removing an element from the pointer vector.

Parameters
posThe position of the element to be removed.
Returns
Iterator to the element after the erased element.

This function erases an element from the pointer vector, i.e. the element is deleted according to the deletion policy of the pointer vector and removed from the vector. Note that in case the deletion policy is NoDelete, this function is identical to the release() function.

template<typename T, typename D = PtrDelete, typename G = OptimalGrowth>
template<typename C >
PtrVector<T,D,G>::BLAZE_TEMPLATE CastIterator<C> blaze::PtrVector< T, D, G >::erase ( CastIterator< C >  pos)
inline

Removing an element from the pointer vector.

Parameters
posThe position of the element to be removed.
Returns
Iterator to the element after the erased element.

This function erases an element from the pointer vector, i.e. the element is deleted according to the deletion policy of the pointer vector and removed from the vector. Note that in case the deletion policy is NoDelete, this function is identical to the release() function.

template<typename T , typename D , typename G >
PtrVector< T, D, G >::ReferenceType blaze::PtrVector< T, D, G >::front ( )
inline

Returns a reference to the first element of the pointer vector.

Returns
Handle to the first element.

Note: No runtime check is performed if the first element exists!

template<typename T , typename D , typename G >
PtrVector< T, D, G >::ConstReferenceType blaze::PtrVector< T, D, G >::front ( ) const
inline

Returns a reference to the first element of the pointer vector.

Returns
Handle to the first element.

Note: No runtime check is performed if the first element exists!

template<typename T , typename D , typename G >
PtrVector< T, D, G >::Iterator blaze::PtrVector< T, D, G >::insert ( Iterator  pos,
PointerType  p 
)
inline

Inserting an element into the pointer vector.

Parameters
posThe position before which the element is inserted.
pThe pointer to be inserted into the pointer vector.
Returns
Iterator to the inserted element.
Exceptions
std::length_errorMaximum pointer vector length exceeded.

The insert function runs in linear time. Note however that inserting elements into a pointer vector can be a relatively time-intensive operation.

template<typename T , typename D , typename G >
template<typename IteratorType >
void blaze::PtrVector< T, D, G >::insert ( Iterator  pos,
IteratorType  first,
IteratorType  last 
)
inline

Inserting a range of elements into the pointer vector.

Parameters
posThe position before which the elements are inserted.
firstIterator to the first element of the element range.
lastIterator to the element one past the last element of the element range.
Returns
void
Exceptions
std::length_errorMaximum pointer vector length exceeded.

This functions inserts the elements in the range $ [first,last) $ into the pointer vector. The insert function runs in linear time. Note however that inserting elements into a pointer vector can be a relatively time-intensive operation.

template<typename T, typename D , typename G >
void blaze::PtrVector< T, D, G >::insert ( T **const  pos,
PointerType  p 
)
private

Inserting an element into the pointer vector.

Parameters
posThe position before which the element is inserted.
pThe pointer to be inserted into the pointer vector.
Returns
void
Exceptions
std::length_errorMaximum pointer vector length exceeded.
template<typename T, typename D , typename G >
template<typename IteratorType >
void blaze::PtrVector< T, D, G >::insert ( T **  pos,
IteratorType  first,
IteratorType  last,
SizeType  n 
)
private

Inserting a range of elements into the pointer vector.

Parameters
posThe position before which the elements are inserted.
firstIterator to the first element of the element range.
lastIterator to the element one past the last element of the element range.
nThe number of elements to be inserted.
Returns
void
Exceptions
std::length_errorMaximum pointer vector length exceeded.
template<typename T , typename D , typename G >
bool blaze::PtrVector< T, D, G >::isEmpty ( ) const
inline

Returns true if the pointer vector has no elements.

Returns
true if the pointer vector is empty, false if it is not.
template<typename T , typename D , typename G >
PtrVector< T, D, G >::SizeType blaze::PtrVector< T, D, G >::maxSize ( ) const
inline

Returns the maximum possible size of a pointer vector.

Returns
The maximum possible size.
template<typename T , typename D , typename G >
PtrVector< T, D, G > & blaze::PtrVector< T, D, G >::operator= ( const PtrVector< T, D, G > &  pv)

Copy assignment operator for PtrVector.

Parameters
pvThe pointer vector to be copied.
Returns
Reference to the assigned pointer vector.
template<typename T, typename D = PtrDelete, typename G = OptimalGrowth>
template<typename T2 , typename D2 , typename G2 >
PtrVector<T,D,G>& blaze::PtrVector< T, D, G >::operator= ( const PtrVector< T2, D2, G2 > &  pv)

Assignment operator for different PtrVector instances.

Parameters
pvThe pointer vector to be copied.
Returns
Reference to the assigned pointer vector.
template<typename T , typename D , typename G >
PtrVector< T, D, G >::ReferenceType blaze::PtrVector< T, D, G >::operator[] ( SizeType  index)
inline

Subscript operator for the direct access to the pointer vector elements.

Parameters
indexAccess index. The index has to be in the range $[0..size-1]$.
Returns
Handle to the accessed element.

Note: No runtime check is performed to insure the validity of the access index.

template<typename T , typename D , typename G >
PtrVector< T, D, G >::ConstReferenceType blaze::PtrVector< T, D, G >::operator[] ( SizeType  index) const
inline

Subscript operator for the direct access to the pointer vector elements.

Parameters
indexAccess index. The index has to be in the range $[0..size-1]$.
Returns
Handle to the accessed element.

Note: No runtime check is performed to insure the validity of the access index.

template<typename T , typename D , typename G >
void blaze::PtrVector< T, D, G >::popBack ( )
inline

Removing an element from the end of the pointer vector.

Returns
void

This function removes the element at the end of the pointer vector, i.e. the element is deleted according to the deletion policy and removed from the vector. Note that in case the deletion policy is NoDelete, this function is identical to the releaseBack() function.

template<typename T , typename D , typename G >
void blaze::PtrVector< T, D, G >::pushBack ( PointerType  p)
inline

Adding an element to the end of the pointer vector.

Parameters
pThe pointer to be added to the end of the pointer vector.
Returns
void
Exceptions
std::length_errorMaximum pointer vector length exceeded.

The pushBack function runs in constant time.

template<typename T , typename D , typename G >
PtrVector< T, D, G >::Iterator blaze::PtrVector< T, D, G >::release ( Iterator  pos)
inline

Releasing an element from the pointer vector.

Parameters
posThe position of the element to be released.
Returns
Iterator to the element after the released element.

This function releases an element from the pointer vector, i.e. the element is removed without applying the deletion policy. Therefore the responsibility to delete the element is passed to the function caller.

template<typename T, typename D = PtrDelete, typename G = OptimalGrowth>
template<typename C >
PtrVector<T,D,G>::BLAZE_TEMPLATE CastIterator<C> blaze::PtrVector< T, D, G >::release ( CastIterator< C >  pos)
inline

Releasing an element from the pointer vector.

Parameters
posThe position of the element to be released.
Returns
Iterator to the element after the released element.

This function releases an element from the pointer vector, i.e. the element is removed without applying the deletion policy. Therefore the responsibility to delete the element is passed to the function caller.

template<typename T , typename D , typename G >
void blaze::PtrVector< T, D, G >::releaseBack ( )
inline

Releasing the element at the end of the pointer vector.

Returns
void

This function releases the element at the end of the pointer vector, i.e. the element is removed without applying the deletion policy. Therefore the responsibility to delete the element is passed to the function caller. Note that in case the deletion policy is NoDelete, this function is identical to the popBack() function.

template<typename T , typename D , typename G >
void blaze::PtrVector< T, D, G >::reserve ( SizeType  newCapacity)

Setting the minimum capacity of the pointer vector.

Parameters
newCapacityThe new minimum capacity of the pointer vector.
Returns
void
template<typename T , typename D , typename G >
PtrVector< T, D, G >::SizeType blaze::PtrVector< T, D, G >::size ( ) const
inline

Returns the current size of the pointer vector.

Returns the total number of objects of type C contained in the pointer vector.

Returns
The current size.
The total number of objects of type C.

This function calculates the total number of objects of type C within the pointer vector, where C is a type derived from the type T of objects contained in the pointer vector. The attempt to use this function for types that are not derived from T results in a compile time error.

// Definition of class A and the derived type B
class A { ... };
class B : public A { ... };
// Definition of a pointer vector for class A
typedef blaze::PtrVector<A> AVector;
AVector vector;
AVector::SizeType total = vector.size(); // Calculating the total number of pointers
AVector::SizeType numB = vector.size<B>(); // Calculating the total number of B objects

Note: The total number of objects of type C is not cached inside the pointer vector but is calculated each time the function is called. Using the templated version of size() to calculate the total number objects of type C is therefore more expensive than using the non-template version of size() to get the total number of pointers in the vector!

template<typename T , typename D , typename G >
void blaze::PtrVector< T, D, G >::swap ( PtrVector< T, D, G > &  pv)
inline

Swapping the contents of two pointer vectors.

Parameters
pvThe pointer vector to be swapped.
Returns
void
Exceptions
no-throwguarantee.

Friends And Related Function Documentation

template<typename T, typename D = PtrDelete, typename G = OptimalGrowth>
template<typename L , typename R >
bool operator!= ( const CastIterator< L > &  lhs,
const CastIterator< R > &  rhs 
)
friend

Inequality comparison between two CastIterator objects.

Parameters
lhsThe left hand side cast iterator.
rhsThe right hand side cast iterator.
Returns
true if the iterators don't point to the same element, false if they do.
template<typename T, typename D = PtrDelete, typename G = OptimalGrowth>
template<typename L , typename R >
bool operator!= ( const CastIterator< L > &  lhs,
const ConstCastIterator< R > &  rhs 
)
friend

Inequality comparison between a CastIterator and a ConstCastIterator.

Parameters
lhsThe left hand side cast iterator.
rhsThe right hand side constant cast iterator.
Returns
true if the iterators don't point to the same element, false if they do.
template<typename T, typename D = PtrDelete, typename G = OptimalGrowth>
template<typename L , typename R >
bool operator!= ( const ConstCastIterator< L > &  lhs,
const CastIterator< R > &  rhs 
)
friend

Inequality comparison between a ConstCastIterator and a CastIterator.

Parameters
lhsThe left hand side constant cast iterator.
rhsThe right hand side cast iterator.
Returns
true if the iterators don't point to the same element, false if they do.
template<typename T, typename D = PtrDelete, typename G = OptimalGrowth>
template<typename L , typename R >
bool operator!= ( const ConstCastIterator< L > &  lhs,
const ConstCastIterator< R > &  rhs 
)
friend

Inequality comparison between two ConstCastIterator objects.

Parameters
lhsThe left hand side constant cast iterator.
rhsThe right hand side constant cast iterator.
Returns
true if the iterators don't point to the same element, false if they do.
template<typename T, typename D = PtrDelete, typename G = OptimalGrowth>
template<typename L , typename R >
bool operator== ( const CastIterator< L > &  lhs,
const CastIterator< R > &  rhs 
)
friend

Equality comparison between two CastIterator objects.

Parameters
lhsThe left hand side cast iterator.
rhsThe right hand side cast iterator.
Returns
true if the iterators point to the same element, false if not.
template<typename T, typename D = PtrDelete, typename G = OptimalGrowth>
template<typename L , typename R >
bool operator== ( const CastIterator< L > &  lhs,
const ConstCastIterator< R > &  rhs 
)
friend

Equality comparison between a CastIterator and a ConstCastIterator.

Parameters
lhsThe left hand side cast iterator.
rhsThe right hand side constant cast iterator.
Returns
true if the iterators point to the same element, false if not.
template<typename T, typename D = PtrDelete, typename G = OptimalGrowth>
template<typename L , typename R >
bool operator== ( const ConstCastIterator< L > &  lhs,
const CastIterator< R > &  rhs 
)
friend

Equality comparison between a ConstCastIterator and a CastIterator.

Parameters
lhsThe left hand side constant cast iterator.
rhsThe right hand side cast iterator.
Returns
true if the iterators point to the same element, false if not.
template<typename T, typename D = PtrDelete, typename G = OptimalGrowth>
template<typename L , typename R >
bool operator== ( const ConstCastIterator< L > &  lhs,
const ConstCastIterator< R > &  rhs 
)
friend

Equality comparison between two ConstCastIterator objects.

Parameters
lhsThe left hand side constant cast iterator.
rhsThe right hand side constant cast iterator.
Returns
true if the iterators point to the same element, false if not.

The documentation for this class was generated from the following file: