PacketData.cci
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 
14 /** \file
15  \brief PacketData inline non-template implementation */
16 
17 // Custom includes
18 #include <senf/Utils/senfassert.hh>
19 #include <iterator>
20 #include "PacketImpl.hh"
21 // #include "PacketParser.hh"
22 
23 #define prefix_ inline
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 
26 //-/////////////////////////////////////////////////////////////////////////////////////////////////
27 // senf::PacketData
28 
29 prefix_ senf::detail::PacketImpl & senf::PacketData::impl()
30  const
31 {
32  SENF_ASSERT(
33  impl_,
34  "Internal failure: PacketData (PacketInterpreter) instance not part of any Packet?");
35  return *impl_;
36 }
37 
38 prefix_ senf::PacketData::iterator senf::PacketData::begin()
39  const
40 {
41  SENF_ASSERT(begin_ <= impl().size(),
42  "Internal failure: PacketInterpreter range outside of data container");
43  return boost::next(impl().begin(),begin_);
44 }
45 
46 prefix_ senf::PacketData::iterator senf::PacketData::end()
47  const
48 {
49  SENF_ASSERT(end_ <= impl().size(),
50  "Internal failure: PacketInterpreter range outside of data container");
51  return boost::next(impl().begin(),end_);
52 }
53 
54 prefix_ senf::PacketData::size_type senf::PacketData::size()
55  const
56 {
57  return end_ - begin_;
58 }
59 
60 prefix_ bool senf::PacketData::empty()
61  const
62 {
63  return begin_ == end_;
64 }
65 
66 prefix_ senf::PacketData::byte senf::PacketData::operator[](size_type n)
67  const
68 {
69  SENF_ASSERT( n < size(), "Access out of container range" );
70  return *( boost::next(begin(),n) );
71 }
72 
73 prefix_ senf::PacketData::byte & senf::PacketData::operator[](size_type n)
74 {
75  SENF_ASSERT( n < size(), "Access out of container range" );
76  return *( boost::next(begin(),n) );
77 }
78 
79 // Modifying the raw packet data
80 
81 prefix_ void senf::PacketData::insert(iterator pos, byte v)
82 {
83  impl().insert(this,pos,v);
84 }
85 
86 prefix_ void senf::PacketData::insert(iterator pos, size_type n, byte v)
87 {
88  impl().insert(this,pos,n,v);
89 }
90 
91 prefix_ void senf::PacketData::erase(iterator pos)
92 {
93  impl().erase(this,pos);
94 }
95 
96 prefix_ void senf::PacketData::erase(iterator first, iterator last)
97 {
98  impl().erase(this,first,last);
99 }
100 
101 prefix_ void senf::PacketData::clear()
102 {
103  impl().clear(this);
104 }
105 
106 prefix_ void senf::PacketData::zero(iterator first, iterator last)
107 {
108  ::memset(first, 0, last-first);
109 }
110 
111 prefix_ bool senf::PacketData::usingExternalMemory()
112  const
113 {
114  return impl().usingExternalMemory();
115 }
116 
117 prefix_ void senf::PacketData::releaseExternalMemory()
118 {
119  impl().releaseExternalMemory();
120 }
121 
122 prefix_ bool senf::PacketData::valid()
123 {
124  return impl_;
125 }
126 
127 // protected members
128 
129 prefix_ senf::PacketData::PacketData(size_type b, size_type e)
130  : impl_(), begin_(b), end_(e)
131 {}
132 
133 //-/////////////////////////////////////////////////////////////////////////////////////////////////
134 #undef prefix_
135 
136 
137 // Local Variables:
138 // mode: c++
139 // fill-column: 100
140 // c-file-style: "senf"
141 // indent-tabs-mode: nil
142 // ispell-local-dictionary: "american"
143 // compile-command: "scons -u test"
144 // comment-column: 40
145 // End: