28 template <
class T,
class Enable =
void>
struct Copier
30 std::unique_ptr<T> operator()(
const T& obj)
const
32 return std::unique_ptr<T>(
new T(obj));
40 template <
class T>
struct Copier<T, typename std::enable_if<std::is_polymorphic<T>::value>::type>
42 std::unique_ptr<T> operator()(
const T& obj)
const
45 return std::unique_ptr<T>(std::move(obj.clone()));
92 other.m_Vector.clear();
100 freeVectorUnsafe(m_Vector);
112 auto oldValues = m_Vector;
115 m_Vector = deepCopyUnsafe(other.m_Vector);
118 catch (
const std::exception&)
120 m_Vector = std::move(oldValues);
124 freeVectorUnsafe(oldValues);
139 m_Vector = std::move(other.m_Vector);
141 other.m_Vector.clear();
150 freeVectorUnsafe(m_Vector);
157 void pushBack(std::nullptr_t element,
bool freeElementOnError =
true) =
delete;
165 void pushBack(T* element,
bool freeElementOnError =
true)
167 if (element ==
nullptr)
169 throw std::invalid_argument(
"Element is nullptr");
174 m_Vector.push_back(element);
176 catch (
const std::exception&)
178 if (freeElementOnError)
196 throw std::invalid_argument(
"Element is nullptr");
202 m_Vector.push_back(element.get());
212 return m_Vector.begin();
221 return m_Vector.begin();
230 return m_Vector.end();
239 return m_Vector.end();
248 return m_Vector.size();
256 return m_Vector.front();
264 return m_Vector.front();
272 return m_Vector.back();
278 T
const*
back()
const
280 return m_Vector.back();
292 return m_Vector.erase(position);
303 PCPP_DEPRECATED(
"Please use the memory safe 'getAndDetach' instead.")
306 T* result = *position;
307 position = m_Vector.erase(position);
329 std::unique_ptr<T> result(*position);
330 position = m_Vector.erase(position);
341 std::unique_ptr<T> result(*position);
342 m_Vector.erase(position);
353 return m_Vector.at(index);
361 const T*
at(
int index)
const
363 return m_Vector.at(index);
372 static std::vector<T*> deepCopyUnsafe(std::vector<T*>
const& origin)
374 std::vector<T*> copyVec;
376 copyVec.reserve(origin.size());
380 for (
const auto iter : origin)
384 copyVec.push_back(objCopy.release());
387 catch (
const std::exception&)
389 for (
auto obj : copyVec)
405 static void freeVectorUnsafe(std::vector<T*>
const& origin)
407 for (
auto& obj : origin)
413 std::vector<T*> m_Vector;
Definition: PointerVector.h:58
VectorIterator begin()
Definition: PointerVector.h:210
PointerVector()
Definition: PointerVector.h:73
ConstVectorIterator end() const
Definition: PointerVector.h:237
typename std::vector< T * >::const_iterator ConstVectorIterator
Definition: PointerVector.h:68
std::unique_ptr< T > getAndDetach(size_t index)
Definition: PointerVector.h:316
T * getAndRemoveFromVector(VectorIterator &position)
Definition: PointerVector.h:304
void pushBack(std::unique_ptr< T > element)
Definition: PointerVector.h:192
VectorIterator erase(VectorIterator position)
Definition: PointerVector.h:289
PointerVector(const PointerVector &other)
Definition: PointerVector.h:83
PointerVector & operator=(const PointerVector &other)
Definition: PointerVector.h:109
std::unique_ptr< T > getAndDetach(VectorIterator const &position)
Definition: PointerVector.h:339
~PointerVector()
Definition: PointerVector.h:98
T const * front() const
Definition: PointerVector.h:262
void pushBack(T *element, bool freeElementOnError=true)
Definition: PointerVector.h:165
T * back()
Definition: PointerVector.h:270
T * at(int index)
Definition: PointerVector.h:351
size_t size() const
Definition: PointerVector.h:246
const T * at(int index) const
Definition: PointerVector.h:361
T * front()
Definition: PointerVector.h:254
PointerVector(PointerVector &&other) noexcept
Definition: PointerVector.h:90
void pushBack(std::nullptr_t element, bool freeElementOnError=true)=delete
ConstVectorIterator begin() const
Definition: PointerVector.h:219
typename std::vector< T * >::iterator VectorIterator
Definition: PointerVector.h:63
void clear()
Definition: PointerVector.h:148
PointerVector & operator=(PointerVector &&other) noexcept
Definition: PointerVector.h:134
std::unique_ptr< T > getAndDetach(VectorIterator &position)
Definition: PointerVector.h:327
VectorIterator end()
Definition: PointerVector.h:228
The main namespace for the PcapPlusPlus lib.
A helper struct to facilitate the creation of a copy of an object.
Definition: PointerVector.h:29