PacketInterpreter.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 PacketInterpreter inline non-template implementation */
16 
17 // Custom includes
18 #include <senf/Utils/senfassert.hh>
19 
20 #define prefix_ inline
21 //-/////////////////////////////////////////////////////////////////////////////////////////////////
22 
23 //-/////////////////////////////////////////////////////////////////////////////////////////////////
24 // senf::PacketInterpreterBase
25 
26 // Structors and default members
27 
28 prefix_ senf::PacketInterpreterBase::~PacketInterpreterBase()
29 {}
30 
31 prefix_ senf::PacketInterpreterBase::factory_t senf::PacketInterpreterBase::no_factory()
32 {
33  return nullptr;
34 }
35 
36 // Interpreter chain access
37 
38 prefix_ senf::PacketInterpreterBase::ptr senf::PacketInterpreterBase::next()
39 {
40  return ptr(impl().next(this));
41 }
42 
43 prefix_ senf::PacketInterpreterBase::ptr senf::PacketInterpreterBase::prev()
44 {
45  return ptr(impl().prev(this));
46 }
47 
48 prefix_ senf::PacketInterpreterBase::ptr senf::PacketInterpreterBase::first()
49 {
50  return ptr(impl().first());
51 }
52 
53 prefix_ senf::PacketInterpreterBase::ptr senf::PacketInterpreterBase::last()
54 {
55  return ptr(impl().last());
56 }
57 
58 prefix_ senf::PacketInterpreterBase::ptr
59 senf::PacketInterpreterBase::parseNextAs(ptr const & self, factory_t factory, PacketInterpreterBase::optional_range const & range)
60 {
61  return factory->parseNext(self, range);
62 }
63 
64 // Data access
65 
66 prefix_ senf::PacketData & senf::PacketInterpreterBase::data()
67 {
68  return (*this);
69 }
70 
71 // Access to the abstract interface
72 
73 prefix_ senf::PacketInterpreterBase::optional_range
74 senf::PacketInterpreterBase::nextPacketRange()
75 {
76  return v_nextPacketRange();
77 }
78 
79 prefix_ senf::TypeIdValue senf::PacketInterpreterBase::typeId()
80 {
81  return v_type();
82 }
83 
84 prefix_ senf::PacketInterpreterBase::factory_t senf::PacketInterpreterBase::factory()
85 {
86  return v_factory();
87 }
88 
89 prefix_ senf::PacketInterpreterBase::factory_t senf::PacketInterpreterBase::nextPacketType()
90 {
91  return v_nextPacketType();
92 }
93 
94 prefix_ void senf::PacketInterpreterBase::clearAnnotations()
95 {
96  return impl().clearAnnotations();
97 }
98 
99 //-/////////////////////////////////////////////////////////////////////////////////////////////////
100 // protected members
101 
102 // protected structors
103 
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))
108 {
109  impl->appendInterpreter(this);
110 }
111 
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))
116 {
117  impl->prependInterpreter(this);
118 }
119 
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))
124 {
125  impl->prependInterpreter(this, before.get());
126 }
127 
128 prefix_ senf::PacketInterpreterBase::ptr
129 senf::PacketInterpreterBase::appendClone(detail::PacketImpl * impl, iterator base,
130  iterator new_base)
131 {
132  return v_appendClone(impl,base,new_base);
133 }
134 
135 prefix_ senf::PacketInterpreterBase::ptr
136 senf::PacketInterpreterBase::appendClone(detail::PacketImpl * impl, range r)
137 {
138  return v_appendClone(impl,r);
139 }
140 
141 prefix_ senf::PacketInterpreterBase * senf::PacketInterpreterBase::nextP()
142 {
143  // This helper ensures, no temporary smart-pointer is alive after nextP() returns
144  return next().get();
145 }
146 
147 prefix_ senf::PacketInterpreterBase * senf::PacketInterpreterBase::prevP()
148 {
149  // This helper ensures, no temporary smart-pointer is alive after prevP() returns
150  return prev().get();
151 }
152 
153 prefix_ senf::detail::PacketImpl & senf::PacketInterpreterBase::impl()
154  const
155 {
156  SENF_ASSERT( is_linked(), "Invalid operation on un-linked PacketInterpreter" );
157  return PacketData::impl();
158 }
159 
160 //-/////////////////////////////////////////////////////////////////////////////////////////////////
161 // private members
162 
163 // containment management. Only to be called by PacketImpl.
164 
165 prefix_ void senf::PacketInterpreterBase::assignImpl(detail::PacketImpl * impl)
166 {
167  SENF_ASSERT(!impl_, "Internal failure: PacketInterpreter added to two Packets");
168  impl_ = impl;
169  if (refcount())
170  impl_->add_ref();
171 }
172 
173 prefix_ void senf::PacketInterpreterBase::releaseImpl()
174 {
175  SENF_ASSERT(impl_, "Internal failure: release of lone PacketInterpreter");
176  if (! refcount()) {
177  detail::PacketImpl * impl (impl_);
178  this->~PacketInterpreterBase();
179  impl->deallocateInterpreter(this);
180  }
181 }
182 
183 prefix_ void senf::intrusive_ptr_add_ref(PacketInterpreterBase const * p)
184 {
185  if (! p->refcount())
186  const_cast<PacketInterpreterBase *>(p)->add_ref();
187  else
188  const_cast<PacketInterpreterBase *>(p)->intrusive_refcount_base::add_ref();
189 }
190 
191 prefix_ void senf::intrusive_ptr_release(PacketInterpreterBase const * p)
192 {
193  if (p->refcount() <= 1)
194  const_cast<PacketInterpreterBase *>(p)->release();
195  else
196  const_cast<PacketInterpreterBase *>(p)->intrusive_refcount_base::release();
197 }
198 
199 //-/////////////////////////////////////////////////////////////////////////////////////////////////
200 #undef prefix_
201 
202 
203 // Local Variables:
204 // mode: c++
205 // fill-column: 100
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
211 // End: