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 PacketInterpreter inline non-template implementation */
18 #include <senf/Utils/senfassert.hh>
20 #define prefix_ inline
21 //-/////////////////////////////////////////////////////////////////////////////////////////////////
23 //-/////////////////////////////////////////////////////////////////////////////////////////////////
24 // senf::PacketInterpreterBase
26 // Structors and default members
28 prefix_ senf::PacketInterpreterBase::~PacketInterpreterBase()
31 prefix_ senf::PacketInterpreterBase::factory_t senf::PacketInterpreterBase::no_factory()
36 // Interpreter chain access
38 prefix_ senf::PacketInterpreterBase::ptr senf::PacketInterpreterBase::next()
40 return ptr(impl().next(this));
43 prefix_ senf::PacketInterpreterBase::ptr senf::PacketInterpreterBase::prev()
45 return ptr(impl().prev(this));
48 prefix_ senf::PacketInterpreterBase::ptr senf::PacketInterpreterBase::first()
50 return ptr(impl().first());
53 prefix_ senf::PacketInterpreterBase::ptr senf::PacketInterpreterBase::last()
55 return ptr(impl().last());
58 prefix_ senf::PacketInterpreterBase::ptr
59 senf::PacketInterpreterBase::parseNextAs(ptr const & self, factory_t factory, PacketInterpreterBase::optional_range const & range)
61 return factory->parseNext(self, range);
66 prefix_ senf::PacketData & senf::PacketInterpreterBase::data()
71 // Access to the abstract interface
73 prefix_ senf::PacketInterpreterBase::optional_range
74 senf::PacketInterpreterBase::nextPacketRange()
76 return v_nextPacketRange();
79 prefix_ senf::TypeIdValue senf::PacketInterpreterBase::typeId()
84 prefix_ senf::PacketInterpreterBase::factory_t senf::PacketInterpreterBase::factory()
89 prefix_ senf::PacketInterpreterBase::factory_t senf::PacketInterpreterBase::nextPacketType()
91 return v_nextPacketType();
94 prefix_ void senf::PacketInterpreterBase::clearAnnotations()
96 return impl().clearAnnotations();
99 //-/////////////////////////////////////////////////////////////////////////////////////////////////
102 // protected structors
104 prefix_ senf::PacketInterpreterBase::PacketInterpreterBase(detail::PacketImpl * impl,
105 iterator b, iterator e, Append_t)
106 : PacketData(std::distance(impl->begin(),b),
107 std::distance(impl->begin(),e))
109 impl->appendInterpreter(this);
112 prefix_ senf::PacketInterpreterBase::PacketInterpreterBase(detail::PacketImpl * impl,
113 iterator b, iterator e, Prepend_t)
114 : PacketData(std::distance(impl->begin(),b),
115 std::distance(impl->begin(),e))
117 impl->prependInterpreter(this);
120 prefix_ senf::PacketInterpreterBase::PacketInterpreterBase(detail::PacketImpl * impl,
121 iterator b, iterator e, ptr before)
122 : PacketData(std::distance(impl->begin(),b),
123 std::distance(impl->begin(),e))
125 impl->prependInterpreter(this, before.get());
128 prefix_ senf::PacketInterpreterBase::ptr
129 senf::PacketInterpreterBase::appendClone(detail::PacketImpl * impl, iterator base,
132 return v_appendClone(impl,base,new_base);
135 prefix_ senf::PacketInterpreterBase::ptr
136 senf::PacketInterpreterBase::appendClone(detail::PacketImpl * impl, range r)
138 return v_appendClone(impl,r);
141 prefix_ senf::PacketInterpreterBase * senf::PacketInterpreterBase::nextP()
143 // This helper ensures, no temporary smart-pointer is alive after nextP() returns
147 prefix_ senf::PacketInterpreterBase * senf::PacketInterpreterBase::prevP()
149 // This helper ensures, no temporary smart-pointer is alive after prevP() returns
153 prefix_ senf::detail::PacketImpl & senf::PacketInterpreterBase::impl()
156 SENF_ASSERT( is_linked(), "Invalid operation on un-linked PacketInterpreter" );
157 return PacketData::impl();
160 //-/////////////////////////////////////////////////////////////////////////////////////////////////
163 // containment management. Only to be called by PacketImpl.
165 prefix_ void senf::PacketInterpreterBase::assignImpl(detail::PacketImpl * impl)
167 SENF_ASSERT(!impl_, "Internal failure: PacketInterpreter added to two Packets");
173 prefix_ void senf::PacketInterpreterBase::releaseImpl()
175 SENF_ASSERT(impl_, "Internal failure: release of lone PacketInterpreter");
177 detail::PacketImpl * impl (impl_);
178 this->~PacketInterpreterBase();
179 impl->deallocateInterpreter(this);
183 prefix_ void senf::intrusive_ptr_add_ref(PacketInterpreterBase const * p)
186 const_cast<PacketInterpreterBase *>(p)->add_ref();
188 const_cast<PacketInterpreterBase *>(p)->intrusive_refcount_base::add_ref();
191 prefix_ void senf::intrusive_ptr_release(PacketInterpreterBase const * p)
193 if (p->refcount() <= 1)
194 const_cast<PacketInterpreterBase *>(p)->release();
196 const_cast<PacketInterpreterBase *>(p)->intrusive_refcount_base::release();
199 //-/////////////////////////////////////////////////////////////////////////////////////////////////
206 // c-file-style: "senf"
207 // indent-tabs-mode: nil
208 // ispell-local-dictionary: "american"
209 // compile-command: "scons -u test"
210 // comment-column: 40