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 Packet inline non-template implementation */
18 #include <senf/Utils/senfassert.hh>
19 #include <senf/Utils/senflikely.hh>
21 #define prefix_ inline
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
29 prefix_ senf::Packet::Packet(PacketInterpreterBase::ptr const & packet)
37 prefix_ senf::PacketInterpreterBase::ptr const & senf::Packet::ptr()
40 SENF_ASSERT(packet_, "Invalid operation (dereferencing) on invalid Packet");
44 // public constructors
46 prefix_ senf::Packet::Packet(Packet const & other)
47 : packet_(other.packet_)
54 prefix_ senf::Packet & senf::Packet::operator=(Packet const & other)
56 if (SENF_LIKELY(this != &other))
57 packet_ = other.packet_;
61 prefix_ senf::Packet::Packet(Packet && other)
63 : packet_(std::move(other.packet_))
70 prefix_ senf::Packet::Packet()
77 prefix_ senf::Packet::~Packet()
87 prefix_ senf::Packet senf::Packet::clone()
90 return Packet(ptr()->clone());
93 // Interpreter chain access
95 prefix_ senf::Packet senf::Packet::next(NoThrow_t)
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();
104 prefix_ senf::Packet senf::Packet::next()
107 Packet p (next(nothrow));
108 if (!p) throw InvalidPacketChainException();
112 prefix_ senf::Packet senf::Packet::prev(NoThrow_t)
115 return Packet(ptr()->prev());
118 prefix_ senf::Packet senf::Packet::prev()
121 Packet p (prev(nothrow));
122 if (!p) throw InvalidPacketChainException();
126 prefix_ senf::Packet senf::Packet::first()
129 return Packet(ptr()->first());
132 prefix_ senf::Packet senf::Packet::last()
135 Packet p (ptr()->last());
136 return p.next(nothrow) ? getLast() : p;
139 prefix_ senf::Packet senf::Packet::parseNextAs(factory_t factory)
142 return Packet(ptr()->parseNextAs(ptr(), factory, ptr()->nextPacketRange()));
145 prefix_ senf::PacketInterpreterBase::ptr
146 senf::Packet::parseNextAs(factory_t factory, PacketInterpreterBase::optional_range const & range)
149 return ptr()->parseNextAs(ptr(), factory, range);
152 prefix_ senf::Packet senf::Packet::append(Packet const & packet)
155 return Packet(ptr()->append(packet.ptr()));
160 prefix_ senf::PacketData & senf::Packet::data()
163 return ptr()->data();
166 prefix_ senf::Packet::size_type senf::Packet::size()
169 return data().size();
174 prefix_ bool senf::Packet::operator==(Packet const & other)
177 return ptr() == other.ptr();
180 prefix_ void senf::Packet::finalizeThis()
182 ptr()->finalizeThis();
185 prefix_ void senf::Packet::finalizeTo(Packet const & other)
187 ptr()->finalizeTo(other.ptr());
190 prefix_ void senf::Packet::finalizeAll()
192 ptr()->finalizeTo(last().ptr());
195 prefix_ senf::TypeIdValue senf::Packet::typeId()
198 return ptr()->typeId();
201 prefix_ senf::Packet::factory_t senf::Packet::factory()
204 return ptr()->factory();
207 prefix_ unsigned long senf::Packet::id()
210 return reinterpret_cast<unsigned long>(&ptr()->impl());
213 prefix_ bool senf::Packet::boolean_test()
216 return packet_.get() != nullptr;
219 prefix_ bool senf::Packet::is_shared()
222 return ptr()->is_shared() || (ptr()->impl().refcount() > 1);
225 prefix_ void senf::Packet::reparse()
231 prefix_ void senf::Packet::clearAnnotations()
233 ptr()->clearAnnotations();
236 //-/////////////////////////////////////////////////////////////////////////////////////////////////
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