PcapPlusPlus
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  inline void pushBack(T* element) { m_Vector.push_back(element); }
83 
88  inline VectorIterator begin() { return m_Vector.begin(); }
89 
94  inline ConstVectorIterator begin() const { return m_Vector.begin(); }
95 
100  inline VectorIterator end() { return m_Vector.end(); }
101 
106  inline ConstVectorIterator end() const { return m_Vector.end(); }
107 
108 
109  //inline size_t size() { return m_Vector.size(); }
110 
115  inline size_t size() const { return m_Vector.size(); }
116 
121  inline T* front() { return m_Vector.front(); }
122 
128  inline VectorIterator erase(VectorIterator position)
129  {
130  delete (*position);
131  return m_Vector.erase(position);
132  }
133 
139  inline 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  inline T* at(int index)
154  {
155  return m_Vector.at(index);
156  }
157 
158  private:
159  std::vector<T*> m_Vector;
160  };
161 
162 } // namespace pcpp
163 
164 #endif /* PCAPPP_POINTER_VECTOR */
VectorIterator erase(VectorIterator position)
Definition: PointerVector.h:128
size_t size() const
Definition: PointerVector.h:115
VectorIterator end()
Definition: PointerVector.h:100
Definition: PointerVector.h:24
T * getAndRemoveFromVector(VectorIterator &position)
Definition: PointerVector.h:139
T * at(int index)
Definition: PointerVector.h:153
ConstVectorIterator begin() const
Definition: PointerVector.h:94
ConstVectorIterator end() const
Definition: PointerVector.h:106
std::vector< T * >::const_iterator ConstVectorIterator
Definition: PointerVector.h:35
PointerVector(const PointerVector &other)
Definition: PointerVector.h:57
~PointerVector()
Definition: PointerVector.h:45
PointerVector()
Definition: PointerVector.h:40
void clear()
Definition: PointerVector.h:69
VectorIterator begin()
Definition: PointerVector.h:88
T * front()
Definition: PointerVector.h:121
std::vector< T * >::iterator VectorIterator
Definition: PointerVector.h:30
void pushBack(T *element)
Definition: PointerVector.h:82
The main namespace for the PcapPlusPlus lib.