4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief PacketInterpreter inline template implementation */
31 //#include "PacketInterpreter.ih"
35 #define prefix_ inline
36 //-/////////////////////////////////////////////////////////////////////////////////////////////////
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39 // senf::PacketInterpreterBase
41 // Interpreter chain access
44 prefix_ typename senf::PacketInterpreter<Type>::ptr senf::PacketInterpreterBase::as()
46 // ensure that the template argument is included in the corresponding object file when linking:
47 { static typename PacketInterpreter<Type>::factory_t _ (PacketInterpreter<Type>::factory()); (void) _;}
48 return typename PacketInterpreter<Type>::ptr(
49 static_cast< PacketInterpreter<Type>* >(this));
52 template <class Annotation>
53 prefix_ Annotation & senf::PacketInterpreterBase::annotation()
55 return impl().annotation<Annotation>();
58 //-/////////////////////////////////////////////////////////////////////////////////////////////////
59 // senf::PacketInterpreter<PacketType>
61 template <class PacketType>
62 prefix_ typename senf::PacketInterpreter<PacketType>::factory_t
63 senf::PacketInterpreter<PacketType>::factory()
68 // Create completely new packet
70 template <class PacketType>
71 prefix_ typename senf::PacketInterpreter<PacketType>::ptr
72 senf::PacketInterpreter<PacketType>::create()
74 return create(initSize());
77 template <class PacketType>
78 prefix_ typename senf::PacketInterpreter<PacketType>::ptr
79 senf::PacketInterpreter<PacketType>::create(senf::NoInit_t)
81 return create(0,senf::noinit);
84 template <class PacketType>
85 template <class ForwardReadableRange>
86 prefix_ typename senf::PacketInterpreter<PacketType>::ptr
87 senf::PacketInterpreter<PacketType>::create(ForwardReadableRange const & range)
89 detail::PacketImpl::Guard p (new detail::PacketImpl(boost::begin(range),boost::end(range)));
90 ptr pi (create(p.p,p.p->begin(),p.p->end(),Append));
94 // Create packet as new packet after a given packet
96 template <class PacketType>
97 prefix_ typename senf::PacketInterpreter<PacketType>::ptr
98 senf::PacketInterpreter<PacketType>::createAfter(PacketInterpreterBase::ptr const & packet)
100 return createAfter(packet, initSize());
103 template <class PacketType>
104 prefix_ typename senf::PacketInterpreter<PacketType>::ptr
105 senf::PacketInterpreter<PacketType>::createAfter(PacketInterpreterBase::ptr const & packet, senf::NoInit_t)
107 return createAfter(packet, 0, senf::noinit);
110 // Create clone of current packet
112 template <class PacketType>
113 prefix_ typename senf::PacketInterpreter<PacketType>::ptr
114 senf::PacketInterpreter<PacketType>::clone()
116 return boost::static_pointer_cast<typename ptr::element_type>(PacketInterpreterBase::clone());
119 // Packet field access
121 template <class PacketType>
122 prefix_ typename senf::PacketInterpreter<PacketType>::parser
123 senf::PacketInterpreter<PacketType>::fields()
125 return parser (data().begin(),&data());
128 //-/////////////////////////////////////////////////////////////////////////////////////////////////
133 template <class PacketType>
134 prefix_ typename senf::PacketInterpreter<PacketType>::ptr
135 senf::PacketInterpreter<PacketType>::create(detail::PacketImpl * impl, iterator b, iterator e,
138 return ptr(new PacketInterpreter(impl,b,e,Append));
141 template <class PacketType>
142 prefix_ typename senf::PacketInterpreter<PacketType>::ptr
143 senf::PacketInterpreter<PacketType>::create(detail::PacketImpl * impl, iterator b, iterator e,
146 return ptr(new PacketInterpreter(impl,b,e,Prepend));
149 template <class PacketType>
150 prefix_ typename senf::PacketInterpreter<PacketType>::ptr
151 senf::PacketInterpreter<PacketType>::create(detail::PacketImpl * impl, iterator b, iterator e,
152 PacketInterpreterBase::ptr const & before)
154 return ptr(new PacketInterpreter(impl,b,e,before));
157 template <class PacketType>
158 prefix_ senf::PacketInterpreter<PacketType>::PacketInterpreter(detail::PacketImpl * impl,
159 iterator b, iterator e, Append_t)
160 : PacketInterpreterBase(impl,b,e,Append)
163 template <class PacketType>
164 prefix_ senf::PacketInterpreter<PacketType>::PacketInterpreter(detail::PacketImpl * impl,
165 iterator b, iterator e, Prepend_t)
166 : PacketInterpreterBase(impl,b,e,Prepend)
169 template <class PacketType>
171 senf::PacketInterpreter<PacketType>::PacketInterpreter(detail::PacketImpl * impl, iterator b,
173 PacketInterpreterBase::ptr const & before)
174 : PacketInterpreterBase(impl,b,e,before)
179 template <class PacketType>
180 prefix_ typename senf::PacketInterpreter<PacketType>::size_type
181 senf::PacketInterpreter<PacketType>::initSize()
183 return type::initSize();
186 template <class PacketType>
187 prefix_ typename senf::PacketInterpreter<PacketType>::size_type
188 senf::PacketInterpreter<PacketType>::initHeadSize()
190 size_type sz (type::initHeadSize());
191 return sz == size_type(-1) ? initSize() : sz ;
194 template <class PacketType>
195 prefix_ void senf::PacketInterpreter<PacketType>::init()
197 return type::init(ConcretePacket<PacketType>(ptr(this)));
200 //-/////////////////////////////////////////////////////////////////////////////////////////////////
207 // c-file-style: "senf"
208 // indent-tabs-mode: nil
209 // ispell-local-dictionary: "american"
210 // compile-command: "scons -u test"
211 // comment-column: 40