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 Packet inline non-template implementation */
32 #include <senf/Utils/senfassert.hh>
34 #define prefix_ inline
35 //-/////////////////////////////////////////////////////////////////////////////////////////////////
37 //-/////////////////////////////////////////////////////////////////////////////////////////////////
42 prefix_ senf::Packet::Packet(PacketInterpreterBase::ptr const & packet)
46 prefix_ senf::PacketInterpreterBase::ptr const & senf::Packet::ptr()
49 SENF_ASSERT(packet_, "Invalid operation (dereferencing) on in-valid() Packet");
55 prefix_ senf::Packet::Packet()
60 prefix_ senf::Packet senf::Packet::clone()
63 return Packet(ptr()->clone());
66 // Interpreter chain access
68 prefix_ senf::Packet senf::Packet::next(NoThrow_t)
71 PacketInterpreterBase::ptr p (ptr()->next());
72 if (p) return Packet(p);
73 PacketInterpreterBase::optional_range r (ptr()->nextPacketRange());
74 return (r && ! r->empty()) ? getNext(r) : Packet();
77 prefix_ senf::Packet senf::Packet::next()
80 Packet p (next(nothrow));
81 if (!p) throw InvalidPacketChainException();
85 prefix_ senf::Packet senf::Packet::prev(NoThrow_t)
88 return Packet(ptr()->prev());
91 prefix_ senf::Packet senf::Packet::prev()
94 Packet p (prev(nothrow));
95 if (!p) throw InvalidPacketChainException();
99 prefix_ senf::Packet senf::Packet::first()
102 return Packet(ptr()->first());
105 prefix_ senf::Packet senf::Packet::last()
108 Packet p (ptr()->last());
109 return p.next(nothrow) ? getLast() : p;
112 prefix_ senf::Packet senf::Packet::parseNextAs(factory_t factory)
115 return Packet(ptr()->parseNextAs(factory, ptr()->nextPacketRange()));
118 prefix_ senf::Packet senf::Packet::parseNextAs(factory_t factory, PacketInterpreterBase::optional_range const & range)
121 return Packet(ptr()->parseNextAs(factory, range));
124 prefix_ senf::Packet senf::Packet::append(Packet const & packet)
127 return Packet(ptr()->append(packet.ptr()));
132 prefix_ senf::PacketData & senf::Packet::data()
135 return ptr()->data();
138 prefix_ senf::Packet::size_type senf::Packet::size()
141 return data().size();
146 prefix_ bool senf::Packet::operator==(Packet const & other)
149 return ptr() == other.ptr();
152 prefix_ void senf::Packet::finalizeThis()
154 ptr()->finalizeThis();
157 prefix_ void senf::Packet::finalizeTo(Packet const & other)
159 ptr()->finalizeTo(other.ptr());
162 prefix_ void senf::Packet::finalizeAll()
164 ptr()->finalizeTo(last().ptr());
167 prefix_ senf::TypeIdValue senf::Packet::typeId()
170 return ptr()->typeId();
173 prefix_ senf::Packet::factory_t senf::Packet::factory()
176 return ptr()->factory();
179 prefix_ unsigned long senf::Packet::id()
182 return reinterpret_cast<unsigned long>(&ptr()->impl());
185 prefix_ bool senf::Packet::boolean_test()
188 return packet_ && packet_->valid();
191 prefix_ bool senf::Packet::valid()
197 prefix_ bool senf::Packet::is_shared()
200 return ptr()->is_shared() || (ptr()->impl().refcount() > 1);
203 prefix_ void senf::Packet::reparse()
209 prefix_ void senf::Packet::clearAnnotations()
211 ptr()->clearAnnotations();
214 template <class PacketType, class Parser>
215 prefix_ Parser senf::operator<<(Parser target, ConcretePacket<PacketType> const & packet)
217 target << packet.parser();
221 //-/////////////////////////////////////////////////////////////////////////////////////////////////
228 // c-file-style: "senf"
229 // indent-tabs-mode: nil
230 // ispell-local-dictionary: "american"
231 // compile-command: "scons -u test"
232 // comment-column: 40