PcapPlusPlus  23.09
pcpp::PointerVector< T > Class Template Reference

#include <PointerVector.h>

Public Types

typedef std::vector< T * >::iterator VectorIterator
 
typedef std::vector< T * >::const_iterator ConstVectorIterator
 

Public Member Functions

 PointerVector ()
 
 ~PointerVector ()
 
 PointerVector (const PointerVector &other)
 
void clear ()
 
void pushBack (T *element)
 
VectorIterator begin ()
 
ConstVectorIterator begin () const
 
VectorIterator end ()
 
ConstVectorIterator end () const
 
size_t size () const
 
T * front ()
 
VectorIterator erase (VectorIterator position)
 
T * getAndRemoveFromVector (VectorIterator &position)
 
T * at (int index)
 
const T * at (int index) const
 

Detailed Description

template<typename T>
class pcpp::PointerVector< T >

A template class for representing a std::vector of pointers. Once (a pointer to) an element is added to this vector, the element responsibility moves to the vector, meaning the PointerVector will free the object once it's removed from the vector This class wraps std::vector and adds the capability of freeing objects once they're removed from it

Member Typedef Documentation

◆ ConstVectorIterator

template<typename T>
typedef std::vector<T*>::const_iterator pcpp::PointerVector< T >::ConstVectorIterator

Const iterator object that is used for iterating all elements in a constant vector

◆ VectorIterator

template<typename T>
typedef std::vector<T*>::iterator pcpp::PointerVector< T >::VectorIterator

Iterator object that is used for iterating all elements in the vector

Constructor & Destructor Documentation

◆ PointerVector() [1/2]

template<typename T>
pcpp::PointerVector< T >::PointerVector ( )
inline

A constructor that create an empty instance of this object

◆ ~PointerVector()

template<typename T>
pcpp::PointerVector< T >::~PointerVector ( )
inline

A destructor for this class. The destructor frees all elements that are binded to the vector

◆ PointerVector() [2/2]

template<typename T>
pcpp::PointerVector< T >::PointerVector ( const PointerVector< T > &  other)
inline

Copy constructor. Once a vector is copied from another vector, all elements inside it are copied, meaning the new vector will contain pointers to copied elements, not pointers to the elements of the original vector

Member Function Documentation

◆ at() [1/2]

template<typename T>
T* pcpp::PointerVector< T >::at ( int  index)
inline

Return a pointer to the element in a certain index

Parameters
[in]indexThe index to retrieve the element from
Returns
The element at the specified position in the vector

◆ at() [2/2]

template<typename T>
const T* pcpp::PointerVector< T >::at ( int  index) const
inline

Return a const pointer to the element in a certain index

Parameters
[in]indexThe index to retrieve the element from
Returns
The element at the specified position in the vector

◆ begin() [1/2]

template<typename T>
VectorIterator pcpp::PointerVector< T >::begin ( )
inline

Get the first element of the vector

Returns
An iterator object pointing to the first element of the vector

◆ begin() [2/2]

template<typename T>
ConstVectorIterator pcpp::PointerVector< T >::begin ( ) const
inline

Get the first element of a constant vector

Returns
A const iterator object pointing to the first element of the vector

◆ clear()

template<typename T>
void pcpp::PointerVector< T >::clear ( )
inline

Clears all elements of the vector while freeing them

◆ end() [1/2]

template<typename T>
VectorIterator pcpp::PointerVector< T >::end ( )
inline

Get the last element of the vector

Returns
An iterator object pointing to the last element of the vector

◆ end() [2/2]

template<typename T>
ConstVectorIterator pcpp::PointerVector< T >::end ( ) const
inline

Get the last element of a constant vector

Returns
A const iterator object pointing to the last element of the vector

◆ erase()

template<typename T>
VectorIterator pcpp::PointerVector< T >::erase ( VectorIterator  position)
inline

Removes from the vector a single element (position). Once the element is erased, it's also freed

Parameters
[in]positionThe position of the element to erase
Returns
An iterator pointing to the new location of the element that followed the last element erased by the function call

◆ front()

template<typename T>
T* pcpp::PointerVector< T >::front ( )
inline

Returns a pointer of the first element in the vector

Returns
A pointer of the first element in the vector

◆ getAndRemoveFromVector()

template<typename T>
T* pcpp::PointerVector< T >::getAndRemoveFromVector ( VectorIterator position)
inline

Remove an element from the vector without freeing it param[in] position The position of the element to remove from the vector

Returns
A pointer to the element which is no longer managed by the vector. It's user responsibility to free it

◆ pushBack()

template<typename T>
void pcpp::PointerVector< T >::pushBack ( T *  element)
inline

Add a new (pointer to an) element to the vector

◆ size()

template<typename T>
size_t pcpp::PointerVector< T >::size ( ) const
inline

Get number of elements in the vector

Returns
The number of elements in the vector