PcapPlusPlus  Next
DeviceListBase.h
1 #pragma once
2 #include "PointerVector.h"
3 
4 namespace pcpp
5 {
6  namespace internal
7  {
9  template <typename T, typename Deleter = std::default_delete<T>> class DeviceListBase
10  {
11  protected:
12  DeviceListBase() = default;
13 
14  explicit DeviceListBase(PointerVector<T, Deleter> devices) : m_DeviceList(std::move(devices))
15  {}
16 
17  DeviceListBase(DeviceListBase const&) = default;
18  DeviceListBase(DeviceListBase&&) = default;
19  // Protected destructor to disallow deletion of derived class through a base class pointer
20  ~DeviceListBase() = default;
21 
22  DeviceListBase& operator=(DeviceListBase const&) = default;
23  DeviceListBase& operator=(DeviceListBase&&) = default;
24 
25  public:
26  using size_type = std::size_t;
27 
28  using iterator = typename PointerVector<T, Deleter>::VectorIterator;
29  using const_iterator = typename PointerVector<T, Deleter>::ConstVectorIterator;
30 
32  iterator begin()
33  {
34  return m_DeviceList.begin();
35  }
36 
38  const_iterator begin() const
39  {
40  return m_DeviceList.begin();
41  }
42 
44  const_iterator cbegin() const
45  {
46  return m_DeviceList.cbegin();
47  }
48 
50  iterator end()
51  {
52  return m_DeviceList.end();
53  }
54 
56  const_iterator end() const
57  {
58  return m_DeviceList.end();
59  }
60 
62  const_iterator cend() const
63  {
64  return m_DeviceList.cend();
65  }
66 
69  bool empty() const
70  {
71  return m_DeviceList.empty();
72  }
73 
76  size_type size() const
77  {
78  return m_DeviceList.size();
79  }
80 
81  protected:
82  PointerVector<T, Deleter> m_DeviceList;
83  };
84  } // namespace internal
85 } // namespace pcpp
Definition: PointerVector.h:50
typename std::vector< T * >::iterator VectorIterator
Iterator object that is used for iterating all elements in the vector.
Definition: PointerVector.h:53
typename std::vector< T * >::const_iterator ConstVectorIterator
Const iterator object that is used for iterating all elements in a constant vector.
Definition: PointerVector.h:56
A base class for device lists, providing common functionality for managing a list of devices.
Definition: DeviceListBase.h:10
iterator begin()
Get an iterator to the beginning of the device list.
Definition: DeviceListBase.h:32
const_iterator begin() const
Get an iterator to the beginning of the device list.
Definition: DeviceListBase.h:38
iterator end()
Get an iterator to the end of the device list.
Definition: DeviceListBase.h:50
bool empty() const
Check if the device list is empty.
Definition: DeviceListBase.h:69
const_iterator cend() const
Get a const iterator to the end of the device list.
Definition: DeviceListBase.h:62
const_iterator cbegin() const
Get a const iterator to the beginning of the device list.
Definition: DeviceListBase.h:44
size_type size() const
Get the number of devices in the list.
Definition: DeviceListBase.h:76
const_iterator end() const
Get an iterator to the end of the device list.
Definition: DeviceListBase.h:56
The main namespace for the PcapPlusPlus lib.