Packet.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 Packet inline non-template implementation */
16 
17 // Custom includes
18 #include <senf/Utils/senfassert.hh>
19 #include <senf/Utils/senflikely.hh>
20 
21 #define prefix_ inline
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
23 
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 // senf::Packet
26 
27 // protected members
28 
29 prefix_ senf::Packet::Packet(PacketInterpreterBase::ptr const & packet)
30  : packet_(packet)
31 {
32 #ifdef SENF_DEBUG
33  pktCount_++;
34 #endif
35 }
36 
37 prefix_ senf::PacketInterpreterBase::ptr const & senf::Packet::ptr()
38  const
39 {
40  SENF_ASSERT(packet_, "Invalid operation (dereferencing) on invalid Packet");
41  return packet_;
42 }
43 
44 // public constructors
45 
46 prefix_ senf::Packet::Packet(Packet const & other)
47  : packet_(other.packet_)
48 {
49 #ifdef SENF_DEBUG
50  pktCount_++;
51 #endif
52 }
53 
54 prefix_ senf::Packet & senf::Packet::operator=(Packet const & other)
55 {
56  if (SENF_LIKELY(this != &other))
57  packet_ = other.packet_;
58  return *this;
59 }
60 
61 prefix_ senf::Packet::Packet(Packet && other)
62  noexcept
63  : packet_(std::move(other.packet_))
64 {
65 #ifdef SENF_DEBUG
66  pktCount_--;
67 #endif
68 }
69 
70 prefix_ senf::Packet::Packet()
71 {
72 #ifdef SENF_DEBUG
73  pktCount_++;
74 #endif
75 }
76 
77 prefix_ senf::Packet::~Packet()
78 {
79 #ifdef SENF_DEBUG
80  pktCount_--;
81 #endif
82 }
83 
84 
85 // public members
86 
87 prefix_ senf::Packet senf::Packet::clone()
88  const
89 {
90  return Packet(ptr()->clone());
91 }
92 
93 // Interpreter chain access
94 
95 prefix_ senf::Packet senf::Packet::next(NoThrow_t)
96  const
97 {
98  PacketInterpreterBase::ptr p (ptr()->next());
99  if (SENF_LIKELY(p)) return Packet(p);
100  PacketInterpreterBase::optional_range r (ptr()->nextPacketRange());
101  return SENF_LIKELY(r && ! r->empty()) ? Packet(getNext(r)) : Packet();
102 }
103 
104 prefix_ senf::Packet senf::Packet::next()
105  const
106 {
107  Packet p (next(nothrow));
108  if (!p) throw InvalidPacketChainException();
109  return p;
110 }
111 
112 prefix_ senf::Packet senf::Packet::prev(NoThrow_t)
113  const
114 {
115  return Packet(ptr()->prev());
116 }
117 
118 prefix_ senf::Packet senf::Packet::prev()
119  const
120 {
121  Packet p (prev(nothrow));
122  if (!p) throw InvalidPacketChainException();
123  return p;
124 }
125 
126 prefix_ senf::Packet senf::Packet::first()
127  const
128 {
129  return Packet(ptr()->first());
130 }
131 
132 prefix_ senf::Packet senf::Packet::last()
133  const
134 {
135  Packet p (ptr()->last());
136  return p.next(nothrow) ? getLast() : p;
137 }
138 
139 prefix_ senf::Packet senf::Packet::parseNextAs(factory_t factory)
140  const
141 {
142  return Packet(ptr()->parseNextAs(ptr(), factory, ptr()->nextPacketRange()));
143 }
144 
145 prefix_ senf::PacketInterpreterBase::ptr
146 senf::Packet::parseNextAs(factory_t factory, PacketInterpreterBase::optional_range const & range)
147  const
148 {
149  return ptr()->parseNextAs(ptr(), factory, range);
150 }
151 
152 prefix_ senf::Packet senf::Packet::append(Packet const & packet)
153  const
154 {
155  return Packet(ptr()->append(packet.ptr()));
156 }
157 
158 // Data access
159 
160 prefix_ senf::PacketData & senf::Packet::data()
161  const
162 {
163  return ptr()->data();
164 }
165 
166 prefix_ senf::Packet::size_type senf::Packet::size()
167  const
168 {
169  return data().size();
170 }
171 
172 // Other methods
173 
174 prefix_ bool senf::Packet::operator==(Packet const & other)
175  const
176 {
177  return ptr() == other.ptr();
178 }
179 
180 prefix_ void senf::Packet::finalizeThis()
181 {
182  ptr()->finalizeThis();
183 }
184 
185 prefix_ void senf::Packet::finalizeTo(Packet const & other)
186 {
187  ptr()->finalizeTo(other.ptr());
188 }
189 
190 prefix_ void senf::Packet::finalizeAll()
191 {
192  ptr()->finalizeTo(last().ptr());
193 }
194 
195 prefix_ senf::TypeIdValue senf::Packet::typeId()
196  const
197 {
198  return ptr()->typeId();
199 }
200 
201 prefix_ senf::Packet::factory_t senf::Packet::factory()
202  const
203 {
204  return ptr()->factory();
205 }
206 
207 prefix_ unsigned long senf::Packet::id()
208  const
209 {
210  return reinterpret_cast<unsigned long>(&ptr()->impl());
211 }
212 
213 prefix_ bool senf::Packet::boolean_test()
214  const
215 {
216  return packet_.get() != nullptr;
217 }
218 
219 prefix_ bool senf::Packet::is_shared()
220  const
221 {
222  return ptr()->is_shared() || (ptr()->impl().refcount() > 1);
223 }
224 
225 prefix_ void senf::Packet::reparse()
226  const
227 {
228  ptr()->reparse();
229 }
230 
231 prefix_ void senf::Packet::clearAnnotations()
232 {
233  ptr()->clearAnnotations();
234 }
235 
236 //-/////////////////////////////////////////////////////////////////////////////////////////////////
237 #undef prefix_
238 
239 
240 // Local Variables:
241 // mode: c++
242 // fill-column: 100
243 // c-file-style: "senf"
244 // indent-tabs-mode: nil
245 // ispell-local-dictionary: "american"
246 // compile-command: "scons -u test"
247 // comment-column: 40
248 // End: