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
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
15 \brief PacketVector inline non-template implementation */
17 //#include "PacketVector.ih"
21 #include <senf/Utils/senfassert.hh>
23 #define prefix_ inline
24 ///////////////////////////////cci.p///////////////////////////////////////
26 #ifndef SENF_PACKET_STD_CONTAINER
28 prefix_ senf::PacketVector::PacketVector()
30 data_ (static_cast<value_type *>(Pool::ordered_malloc(1))),
31 b_ (data_ + HeadRoom),
36 prefix_ senf::PacketVector::PacketVector(size_type requestSize, value_type initValue)
37 : size_ (allocationSize(requestSize)),
38 data_ (static_cast<value_type *>(Pool::ordered_malloc(size_ >> ChunkSizeIndex))),
39 b_ (data_ + HeadRoom),
40 e_ (b_ + requestSize),
43 ::memset(b_, initValue, requestSize);
46 prefix_ senf::PacketVector::PacketVector(value_type * data, size_type size,
47 size_type chunkSize, size_type offset)
48 : size_ (chunkSize ? chunkSize : size + offset),
55 prefix_ senf::PacketVector::~PacketVector()
58 Pool::ordered_free(data_, size_ >> ChunkSizeIndex);
61 prefix_ senf::PacketVector::iterator senf::PacketVector::begin()
66 prefix_ senf::PacketVector::const_iterator senf::PacketVector::begin()
72 prefix_ senf::PacketVector::iterator senf::PacketVector::end()
77 prefix_ senf::PacketVector::const_iterator senf::PacketVector::end()
83 prefix_ senf::PacketVector::size_type senf::PacketVector::size()
89 prefix_ void senf::PacketVector::clear()
94 prefix_ bool senf::PacketVector::external()
100 prefix_ void senf::PacketVector::releaseExternal()
106 prefix_ void senf::PacketVector::erase(iterator pos)
108 SENF_ASSERT( pos >= b_ && pos < e_, "invalid iterator passed to PacketVector::erase" );
109 ::memmove(pos, pos + 1, e_ - pos - 1);
113 prefix_ void senf::PacketVector::erase(iterator first, iterator last)
115 SENF_ASSERT( first >= b_ && last <= e_ && last >= first,
116 "invalid iterator passed to PacketVector::erase" );
117 ::memmove(first, last, e_ - last);
121 prefix_ void senf::PacketVector::truncateFront(iterator pos)
123 SENF_ASSERT( pos >= b_ && pos <= e_, "invalid iterator passed to PacketVector::truncateFront" );
127 prefix_ void senf::PacketVector::truncateBack(iterator pos)
129 SENF_ASSERT( pos >= b_ && pos <= e_, "invalid iterator passed to PacketVector::truncateBack" );
133 prefix_ void senf::PacketVector::insert(iterator pos, value_type v)
135 SENF_ASSERT( pos >= b_ && pos <= e_, "invalid iterator passed to PacketVector::insert" );
139 prefix_ void senf::PacketVector::insert(iterator pos, size_type n, value_type v)
141 SENF_ASSERT( pos >= b_ && pos <= e_, "invalid iterator passed to PacketVector::insert" );
143 ::memset(move(pos, n), v, n);
146 prefix_ senf::PacketVector::size_type senf::PacketVector::allocationSize(size_type sz)
148 return ((sz + HeadRoom + TailRoom) | (ChunkSize - 1)) + 1;
151 prefix_ senf::PacketVector::iterator senf::PacketVector::move(iterator pos, size_type n)
153 // we check the prevalent cases here and leave the exotic cases to moveGrow
154 if (pos - b_ < e_ - pos && b_ >= data_ + n) {
155 ::memmove(b_ - n, b_, pos - b_);
159 else if (e_ + n <= data_ + size_) {
160 ::memmove(pos + n, pos, e_ - pos);
165 return moveGrow(pos, n);
170 ///////////////////////////////cci.e///////////////////////////////////////
177 // comment-column: 40
178 // c-file-style: "senf"
179 // indent-tabs-mode: nil
180 // ispell-local-dictionary: "american"
181 // compile-command: "scons -u test"