PacketVector.cc
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 #include "Packets.hh"
18 //#include "PacketVector.ih"
19 
20 // Custom includes
21 
22 //#include "PacketVector.mpp"
23 #define prefix_
24 
26 #ifndef SENF_PACKET_STD_CONTAINER
27 
28 prefix_ senf::PacketVector::iterator senf::PacketVector::moveGrow(iterator pos, size_type n)
29 {
30  // This is called in two cases:
31  // a) best insertion side is back but there is not enough tailroom
32  // b) a reallocation is needed (neither headroom nor tailroom are sufficient)
33  if (b_ >= data_ + n) {
34  // there is enough headroom. This can only be true if the best insertion side really is
35  // the end but there is not enough tailroom (otherwise moveGrow would not have been called)
36  ::memmove(b_ - n, b_, pos - b_);
37  b_ -= n;
38  return pos - n;
39  }
40  else
41  // otherwise we need a reallocation
42  return grow(pos, n);
43 }
44 
45 prefix_ senf::PacketVector::iterator senf::PacketVector::grow(iterator pos, size_type n)
46 {
47  size_type posIndex (pos - b_);
48  size_type dataSize (e_ - b_);
49  size_type requestSize (allocationSize(dataSize + n));
50  value_type * newData (static_cast<value_type *>(Pool::ordered_malloc(requestSize >> ChunkSizeIndex)));
51  ::memcpy(newData + HeadRoom, b_, posIndex);
52  ::memcpy(newData + HeadRoom + posIndex + n, b_ + posIndex, dataSize - posIndex);
53  if (owner_)
54  Pool::ordered_free(data_, size_ >> ChunkSizeIndex);
55  b_ = newData + HeadRoom;
56  e_ = b_ + dataSize + n;
57  size_ = requestSize;
58  data_ = newData;
59  owner_ = true;
60  return b_ + posIndex;
61 }
62 
63 #endif
64 
66 #undef prefix_
67 //#include "PacketVector.mpp"
68 
69 
70 // Local Variables:
71 // mode: c++
72 // fill-column: 100
73 // comment-column: 40
74 // c-file-style: "senf"
75 // indent-tabs-mode: nil
76 // ispell-local-dictionary: "american"
77 // compile-command: "scons -u test"
78 // End:
Packets public header.
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
static size_type const HeadRoom
Definition: PacketVector.hh:55
raw_container::size_type size_type
Definition: PacketTypes.hh:66
raw_container::iterator iterator
Definition: PacketTypes.hh:69
#define prefix_
Definition: PacketVector.cc:23
static size_type const ChunkSizeIndex
Definition: PacketVector.hh:54