Packets: fix for natty: Ensure correct linking of all referenced packet types (see...
[senf.git] / senf / Packets / PacketInterpreter.cti
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
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
10 //
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.
14 //
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.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
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.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief PacketInterpreter inline template implementation */
30
31 //#include "PacketInterpreter.ih"
32
33 // Custom includes
34
35 #define prefix_ inline
36 //-/////////////////////////////////////////////////////////////////////////////////////////////////
37
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39 // senf::PacketInterpreterBase
40
41 // Interpreter chain access
42
43 template <class Type>
44 prefix_ bool senf::PacketInterpreterBase::is()
45 {
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 dynamic_cast< PacketInterpreter<Type>* >(this);
49 }
50
51 template <class Type>
52 prefix_ typename senf::PacketInterpreter<Type>::ptr senf::PacketInterpreterBase::as()
53 {
54     // ensure that the template argument is included in the corresponding object file when linking:
55     { static typename PacketInterpreter<Type>::factory_t _ (PacketInterpreter<Type>::factory()); (void) _;}
56     return typename PacketInterpreter<Type>::ptr(
57         static_cast< PacketInterpreter<Type>* >(this));
58 }
59
60 template <class Annotation>
61 prefix_ Annotation & senf::PacketInterpreterBase::annotation()
62 {
63     return impl().annotation<Annotation>();
64 }
65
66 //-/////////////////////////////////////////////////////////////////////////////////////////////////
67 // senf::PacketInterpreter<PacketType>
68
69 template <class PacketType>
70 prefix_ typename senf::PacketInterpreter<PacketType>::factory_t
71 senf::PacketInterpreter<PacketType>::factory()
72 {
73     return & factory_;
74 }
75
76 // Create completely new packet
77
78 template <class PacketType>
79 prefix_ typename senf::PacketInterpreter<PacketType>::ptr
80 senf::PacketInterpreter<PacketType>::create()
81 {
82     return create(initSize());
83 }
84
85 template <class PacketType>
86 prefix_ typename senf::PacketInterpreter<PacketType>::ptr
87 senf::PacketInterpreter<PacketType>::create(senf::NoInit_t)
88 {
89     return create(0,senf::noinit);
90 }
91
92 template <class PacketType>
93 template <class ForwardReadableRange>
94 prefix_ typename senf::PacketInterpreter<PacketType>::ptr
95 senf::PacketInterpreter<PacketType>::create(ForwardReadableRange const & range)
96 {
97     detail::PacketImpl::Guard p (new detail::PacketImpl(boost::begin(range),boost::end(range)));
98     ptr pi (create(p.p,p.p->begin(),p.p->end(),Append));
99     return pi;
100 }
101
102 // Create packet as new packet after a given packet
103
104 template <class PacketType>
105 prefix_ typename senf::PacketInterpreter<PacketType>::ptr
106 senf::PacketInterpreter<PacketType>::createAfter(PacketInterpreterBase::ptr packet)
107 {
108     return createAfter(packet, initSize());
109 }
110
111 template <class PacketType>
112 prefix_ typename senf::PacketInterpreter<PacketType>::ptr
113 senf::PacketInterpreter<PacketType>::createAfter(PacketInterpreterBase::ptr packet, senf::NoInit_t)
114 {
115     return createAfter(packet, 0, senf::noinit);
116 }
117
118 // Create clone of current packet
119
120 template <class PacketType>
121 prefix_ typename senf::PacketInterpreter<PacketType>::ptr
122 senf::PacketInterpreter<PacketType>::clone()
123 {
124     return boost::static_pointer_cast<typename ptr::element_type>(PacketInterpreterBase::clone());
125 }
126
127 // Packet field access
128
129 template <class PacketType>
130 prefix_ typename senf::PacketInterpreter<PacketType>::parser
131 senf::PacketInterpreter<PacketType>::fields()
132 {
133     return parser (data().begin(),&data());
134 }
135
136 //-/////////////////////////////////////////////////////////////////////////////////////////////////
137 // private members
138
139 // Private structors
140
141 template <class PacketType>
142 prefix_ typename senf::PacketInterpreter<PacketType>::ptr
143 senf::PacketInterpreter<PacketType>::create(detail::PacketImpl * impl, iterator b, iterator e,
144                                             Append_t)
145 {
146     return ptr(new PacketInterpreter(impl,b,e,Append));
147 }
148
149 template <class PacketType>
150 prefix_ typename senf::PacketInterpreter<PacketType>::ptr
151 senf::PacketInterpreter<PacketType>::create(detail::PacketImpl * impl, iterator b, iterator e,
152                                             Prepend_t)
153 {
154     return ptr(new PacketInterpreter(impl,b,e,Prepend));
155 }
156
157 template <class PacketType>
158 prefix_ typename senf::PacketInterpreter<PacketType>::ptr
159 senf::PacketInterpreter<PacketType>::create(detail::PacketImpl * impl, iterator b, iterator e,
160                                             PacketInterpreterBase::ptr before)
161 {
162     return ptr(new PacketInterpreter(impl,b,e,before));
163 }
164
165 template <class PacketType>
166 prefix_ senf::PacketInterpreter<PacketType>::PacketInterpreter(detail::PacketImpl * impl,
167                                                                iterator b, iterator e, Append_t)
168     : PacketInterpreterBase(impl,b,e,Append)
169 {}
170
171 template <class PacketType>
172 prefix_ senf::PacketInterpreter<PacketType>::PacketInterpreter(detail::PacketImpl * impl,
173                                                                iterator b, iterator e, Prepend_t)
174     : PacketInterpreterBase(impl,b,e,Prepend)
175 {}
176
177 template <class PacketType>
178 prefix_
179 senf::PacketInterpreter<PacketType>::PacketInterpreter(detail::PacketImpl * impl, iterator b,
180                                                        iterator e,
181                                                        PacketInterpreterBase::ptr before)
182     : PacketInterpreterBase(impl,b,e,before)
183 {}
184
185 // PacketType access
186
187 template <class PacketType>
188 prefix_ typename senf::PacketInterpreter<PacketType>::size_type
189 senf::PacketInterpreter<PacketType>::initSize()
190 {
191     return type::initSize();
192 }
193
194 template <class PacketType>
195 prefix_ typename senf::PacketInterpreter<PacketType>::size_type
196 senf::PacketInterpreter<PacketType>::initHeadSize()
197 {
198     size_type sz (type::initHeadSize());
199     return  sz == size_type(-1) ? initSize() : sz ;
200 }
201
202 template <class PacketType>
203 prefix_ void senf::PacketInterpreter<PacketType>::init()
204 {
205     return type::init(ConcretePacket<PacketType>(ptr(this)));
206 }
207
208 //-/////////////////////////////////////////////////////////////////////////////////////////////////
209 #undef prefix_
210
211 \f
212 // Local Variables:
213 // mode: c++
214 // fill-column: 100
215 // c-file-style: "senf"
216 // indent-tabs-mode: nil
217 // ispell-local-dictionary: "american"
218 // compile-command: "scons -u test"
219 // comment-column: 40
220 // End: