PacketVector.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
17 #ifndef HH_SENF_Packets_PacketVector_
18 #define HH_SENF_Packets_PacketVector_ 1
19 
20 // Custom includes
21 #include <boost/noncopyable.hpp>
22 #include <boost/cstdint.hpp>
23 #include <boost/pool/singleton_pool.hpp>
24 #include <senf/config.hh>
25 #include <cstddef>
26 
27 //#include "PacketVector.mpp"
29 
30 #ifndef SENF_PACKET_STD_CONTAINER
31 
32 namespace senf {
33 
37  : boost::noncopyable
38  {
39  struct PacketVectorPoolTag {};
40  typedef boost::singleton_pool<
41  PacketVectorPoolTag, 1u << SENF_PACKET_VECTOR_SIZE_INDEX> Pool;
42 
43  public:
45  // Types
46 
47  typedef boost::uint8_t value_type;
48  typedef std::size_t size_type;
49  typedef std::ptrdiff_t difference_type;
50  typedef value_type * iterator;
51  typedef value_type const * const_iterator;
52 
53  static size_type const ChunkSize = 1u << SENF_PACKET_VECTOR_SIZE_INDEX;
54  static size_type const ChunkSizeIndex = SENF_PACKET_VECTOR_SIZE_INDEX;
55  static size_type const HeadRoom = SENF_PACKET_VECTOR_HEADROOM;
56  static size_type const TailRoom = SENF_PACKET_VECTOR_TAILROOM;
57 
61 
62  // my default constructor
63  // disabled copy constructor
64  // disabled copy assignment
65  // my destructor
66 
67  PacketVector();
68  PacketVector(size_type requestSize, value_type initValue);
69  template <class ForwardIterator>
70  PacketVector(ForwardIterator f, ForwardIterator l);
71  PacketVector(value_type * data, size_type size,
72  size_type chunkSize = 0u, size_type offset = 0u);
73 
74  ~PacketVector();
75 
76  // no conversion constructors
77 
80 
81  iterator begin();
82  iterator end();
83  const_iterator begin() const;
84  const_iterator end() const;
85 
86  size_type size() const;
87  void clear();
88 
89  bool external() const;
90  void releaseExternal();
91 
92  void erase(iterator pos);
93  void erase(iterator first, iterator last);
94  void truncateFront(iterator pos);
95  void truncateBack(iterator pos);
96 
97  void insert(iterator pos, value_type v);
98  void insert(iterator pos, size_type n, value_type v);
99  template <class ForwardIterator>
100  void insert(iterator pos, ForwardIterator f, ForwardIterator l);
101 
102  protected:
103 
104  private:
105  static size_type allocationSize(size_type sz);
106  iterator move(iterator pos, size_type n);
107  iterator moveGrow(iterator pos, size_type n);
108  iterator grow(iterator pos, size_type n);
109 
110  size_type size_;
111  value_type * data_;
112  iterator b_;
113  iterator e_;
114  bool owner_;
115  };
116 
117 }
118 
119 #endif
120 
122 #include "PacketVector.cci"
123 //#include "PacketVector.ct"
124 #include "PacketVector.cti"
125 #endif
126 
127 
128 // Local Variables:
129 // mode: c++
130 // fill-column: 100
131 // comment-column: 40
132 // c-file-style: "senf"
133 // indent-tabs-mode: nil
134 // ispell-local-dictionary: "american"
135 // compile-command: "scons -u test"
136 // End:
static size_type const TailRoom
Definition: PacketVector.hh:56
bool external() const
std::ptrdiff_t difference_type
Definition: PacketVector.hh:49
void insert(iterator pos, value_type v)
size_type size() const
std::size_t size_type
Definition: PacketVector.hh:48
value_type * iterator
Definition: PacketVector.hh:50
boost::uint8_t value_type
Definition: PacketVector.hh:47
void erase(iterator pos)
static size_type const HeadRoom
Definition: PacketVector.hh:55
static size_type const ChunkSize
Definition: PacketVector.hh:53
void truncateFront(iterator pos)
void truncateBack(iterator pos)
value_type const * const_iterator
Definition: PacketVector.hh:51
static size_type const ChunkSizeIndex
Definition: PacketVector.hh:54