PcapPlusPlus  19.12
PointerVector.h
Go to the documentation of this file.
1 #ifndef PCAPPP_POINTER_VECTOR
2 #define PCAPPP_POINTER_VECTOR
3 
4 #include <stdio.h>
5 #include <stdint.h>
6 #include <vector>
7 
9 
14 namespace pcpp
15 {
16 
23  template<typename T>
25  {
26  public:
30  typedef typename std::vector<T*>::iterator VectorIterator;
31 
35  typedef typename std::vector<T*>::const_iterator ConstVectorIterator;
36 
41 
46  {
47  for (VectorIterator iter = m_Vector.begin(); iter != m_Vector.end(); iter++)
48  {
49  delete (*iter);
50  }
51  }
52 
58  {
59  for (ConstVectorIterator iter = other.begin(); iter != other.end(); iter++)
60  {
61  T* objCopy = new T(**iter);
62  m_Vector.push_back(objCopy);
63  }
64  }
65 
69  void clear()
70  {
71  for (VectorIterator iter = m_Vector.begin(); iter != m_Vector.end(); iter++)
72  {
73  delete (*iter);
74  }
75 
76  m_Vector.clear();
77  }
78 
82  void pushBack(T* element) { m_Vector.push_back(element); }
83 
88  VectorIterator begin() { return m_Vector.begin(); }
89 
94  ConstVectorIterator begin() const { return m_Vector.begin(); }
95 
100  VectorIterator end() { return m_Vector.end(); }
101 
106  ConstVectorIterator end() const { return m_Vector.end(); }
107 
108 
109  //inline size_t size() { return m_Vector.size(); }
110 
115  size_t size() const { return m_Vector.size(); }
116 
121  T* front() { return m_Vector.front(); }
122 
129  {
130  delete (*position);
131  return m_Vector.erase(position);
132  }
133 
140  {
141  T* result = (*position);
142  VectorIterator tempPos = position;
143  tempPos = m_Vector.erase(tempPos);
144  position = tempPos;
145  return result;
146  }
147 
153  T* at(int index)
154  {
155  return m_Vector.at(index);
156  }
157 
163  const T* at(int index) const
164  {
165  return m_Vector.at(index);
166  }
167 
168  private:
169  std::vector<T*> m_Vector;
170  };
171 
172 } // namespace pcpp
173 
174 #endif /* PCAPPP_POINTER_VECTOR */
pcpp::PointerVector::begin
VectorIterator begin()
Definition: PointerVector.h:88
pcpp::PointerVector::end
VectorIterator end()
Definition: PointerVector.h:100
pcpp::PointerVector::end
ConstVectorIterator end() const
Definition: PointerVector.h:106
pcpp::PointerVector::front
T * front()
Definition: PointerVector.h:121
pcpp::PointerVector::ConstVectorIterator
std::vector< T * >::const_iterator ConstVectorIterator
Definition: PointerVector.h:35
pcpp::PointerVector::begin
ConstVectorIterator begin() const
Definition: PointerVector.h:94
pcpp::PointerVector::at
const T * at(int index) const
Definition: PointerVector.h:163
pcpp::PointerVector::PointerVector
PointerVector(const PointerVector &other)
Definition: PointerVector.h:57
pcpp
The main namespace for the PcapPlusPlus lib.
pcpp::PointerVector::size
size_t size() const
Definition: PointerVector.h:115
pcpp::PointerVector::~PointerVector
~PointerVector()
Definition: PointerVector.h:45
pcpp::PointerVector
Definition: PointerVector.h:24
pcpp::PointerVector::PointerVector
PointerVector()
Definition: PointerVector.h:40
pcpp::PointerVector::getAndRemoveFromVector
T * getAndRemoveFromVector(VectorIterator &position)
Definition: PointerVector.h:139
pcpp::PointerVector::VectorIterator
std::vector< T * >::iterator VectorIterator
Definition: PointerVector.h:30
pcpp::PointerVector::pushBack
void pushBack(T *element)
Definition: PointerVector.h:82
pcpp::PointerVector::clear
void clear()
Definition: PointerVector.h:69
pcpp::PointerVector::at
T * at(int index)
Definition: PointerVector.h:153
pcpp::PointerVector::erase
VectorIterator erase(VectorIterator position)
Definition: PointerVector.h:128