63 other.m_Vector.clear();
71 freeVectorUnsafe(m_Vector);
83 auto oldValues = m_Vector;
86 m_Vector = deepCopyUnsafe(other.m_Vector);
89 catch (
const std::exception&)
91 m_Vector = std::move(oldValues);
95 freeVectorUnsafe(oldValues);
110 m_Vector = std::move(other.m_Vector);
112 other.m_Vector.clear();
121 freeVectorUnsafe(m_Vector);
128 void pushBack(std::nullptr_t element,
bool freeElementOnError =
true) =
delete;
136 void pushBack(T* element,
bool freeElementOnError =
true)
138 if (element ==
nullptr)
140 throw std::invalid_argument(
"Element is nullptr");
145 m_Vector.push_back(element);
147 catch (
const std::exception&)
149 if (freeElementOnError)
167 throw std::invalid_argument(
"Element is nullptr");
173 m_Vector.push_back(element.get());
183 return m_Vector.begin();
192 return m_Vector.begin();
201 return m_Vector.end();
210 return m_Vector.end();
219 return m_Vector.size();
227 return m_Vector.front();
235 return m_Vector.front();
243 return m_Vector.back();
249 T
const*
back()
const
251 return m_Vector.back();
263 return m_Vector.erase(position);
274 PCPP_DEPRECATED(
"Please use the memory safe 'getAndDetach' instead.")
277 T* result = *position;
278 position = m_Vector.erase(position);
300 std::unique_ptr<T> result(*position);
301 position = m_Vector.erase(position);
312 std::unique_ptr<T> result(*position);
313 m_Vector.erase(position);
324 return m_Vector.at(index);
332 const T*
at(
int index)
const
334 return m_Vector.at(index);
343 static std::vector<T*> deepCopyUnsafe(std::vector<T*>
const& origin)
345 std::vector<T*> copyVec;
349 for (
const auto iter : origin)
351 T* objCopy =
new T(*iter);
354 copyVec.push_back(objCopy);
356 catch (
const std::exception&)
363 catch (
const std::exception&)
365 for (
auto obj : copyVec)
381 static void freeVectorUnsafe(std::vector<T*>
const& origin)
383 for (
auto& obj : origin)
389 std::vector<T*> m_Vector;
Definition: PointerVector.h:29
VectorIterator begin()
Definition: PointerVector.h:181
PointerVector()
Definition: PointerVector.h:44
ConstVectorIterator end() const
Definition: PointerVector.h:208
typename std::vector< T * >::const_iterator ConstVectorIterator
Definition: PointerVector.h:39
std::unique_ptr< T > getAndDetach(size_t index)
Definition: PointerVector.h:287
T * getAndRemoveFromVector(VectorIterator &position)
Definition: PointerVector.h:275
void pushBack(std::unique_ptr< T > element)
Definition: PointerVector.h:163
VectorIterator erase(VectorIterator position)
Definition: PointerVector.h:260
PointerVector(const PointerVector &other)
Definition: PointerVector.h:54
PointerVector & operator=(const PointerVector &other)
Definition: PointerVector.h:80
std::unique_ptr< T > getAndDetach(VectorIterator const &position)
Definition: PointerVector.h:310
~PointerVector()
Definition: PointerVector.h:69
T const * front() const
Definition: PointerVector.h:233
void pushBack(T *element, bool freeElementOnError=true)
Definition: PointerVector.h:136
T * back()
Definition: PointerVector.h:241
T * at(int index)
Definition: PointerVector.h:322
size_t size() const
Definition: PointerVector.h:217
const T * at(int index) const
Definition: PointerVector.h:332
T * front()
Definition: PointerVector.h:225
PointerVector(PointerVector &&other) noexcept
Definition: PointerVector.h:61
void pushBack(std::nullptr_t element, bool freeElementOnError=true)=delete
ConstVectorIterator begin() const
Definition: PointerVector.h:190
typename std::vector< T * >::iterator VectorIterator
Definition: PointerVector.h:34
void clear()
Definition: PointerVector.h:119
PointerVector & operator=(PointerVector &&other) noexcept
Definition: PointerVector.h:105
std::unique_ptr< T > getAndDetach(VectorIterator &position)
Definition: PointerVector.h:298
VectorIterator end()
Definition: PointerVector.h:199
The main namespace for the PcapPlusPlus lib.