PcapPlusPlus  21.05
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 
128  VectorIterator erase(VectorIterator position)
129  {
130  delete (*position);
131  return m_Vector.erase(position);
132  }
133 
139  T* getAndRemoveFromVector(VectorIterator& position)
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 */
ConstVectorIterator end() const
Definition: PointerVector.h:106
The main namespace for the PcapPlusPlus lib.
T * front()
Definition: PointerVector.h:121
Definition: PointerVector.h:24
std::vector< T * >::const_iterator ConstVectorIterator
Definition: PointerVector.h:35
ConstVectorIterator begin() const
Definition: PointerVector.h:94
const T * at(int index) const
Definition: PointerVector.h:163
PointerVector(const PointerVector &other)
Definition: PointerVector.h:57
std::vector< T * >::iterator VectorIterator
Definition: PointerVector.h:30
void pushBack(T *element)
Definition: PointerVector.h:82
void clear()
Definition: PointerVector.h:69
T * at(int index)
Definition: PointerVector.h:153
VectorIterator erase(VectorIterator position)
Definition: PointerVector.h:128
~PointerVector()
Definition: PointerVector.h:45
PointerVector()
Definition: PointerVector.h:40
size_t size() const
Definition: PointerVector.h:115
VectorIterator begin()
Definition: PointerVector.h:88
VectorIterator end()
Definition: PointerVector.h:100
T * getAndRemoveFromVector(VectorIterator &position)
Definition: PointerVector.h:139