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 non-inline non-template implementation */
31 //#include "PacketInterpreter.ih"
36 //#include "PacketInterpreter.mpp"
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
40 //-/////////////////////////////////////////////////////////////////////////////////////////////////
41 // senf::PacketInterpreterBase
43 // structors and default members
45 prefix_ senf::PacketInterpreterBase::~PacketInterpreterBase()
48 prefix_ senf::PacketInterpreterBase::ptr senf::PacketInterpreterBase::clone()
50 detail::PacketImpl::Guard p (new detail::PacketImpl(begin(),end()));
51 ptr pi (appendClone(p.p,begin(),p.p->begin()));
52 for (ptr i (next()); i; i = i->next())
53 i->appendClone(p.p,begin(),p.p->begin());
54 pi->impl().assignAnnotations( impl());
58 // Interpreter chain access
60 prefix_ senf::PacketInterpreterBase::ptr senf::PacketInterpreterBase::append(ptr packet)
63 impl().truncateInterpreters(next().get());
65 optional_range r (nextPacketRange());
67 throw InvalidPacketChainException();
69 ptr rv (packet->appendClone(&impl(), *r));
70 rv->data().resize(packet->data().size());
71 std::copy(packet->data().begin(), packet->data().end(), rv->data().begin());
73 for (ptr p (packet->next()) ; p ; p = p->next())
74 p->appendClone(&impl(), packet->data().begin(), rv->data().begin());
79 prefix_ void senf::PacketInterpreterBase::reparse()
82 impl().truncateInterpreters(next().get());
85 // Access to the abstract interface
87 prefix_ void senf::PacketInterpreterBase::dump(std::ostream & os)
90 if (detail::AnnotationRegistry::instance().begin()
91 != detail::AnnotationRegistry::instance().end()) {
92 os << "Annotations:\n";
93 impl().dumpAnnotations(os);
96 for (ptr i (next()); i; i = i->next())
99 catch (senf::Exception & e) {
100 os << "[Exception: " << e.message() << "]\n";
104 prefix_ void senf::PacketInterpreterBase::finalizeThis()
109 prefix_ void senf::PacketInterpreterBase::finalizeTo(ptr other)
111 for (ptr i (other); i.get() != this && i.get(); i = i->prev())
116 // reference/memory management
118 prefix_ void senf::PacketInterpreterBase::add_ref()
120 if (impl_ && !refcount())
122 intrusive_refcount_t<PacketInterpreterBase>::add_ref();
125 prefix_ void senf::PacketInterpreterBase::release()
127 if (impl_ && refcount()==1)
128 // This call will set impl_ to 0 if we just removed the last reference ...
130 if (intrusive_refcount_t<PacketInterpreterBase>::release() && !impl_)
134 //-/////////////////////////////////////////////////////////////////////////////////////////////////
135 // senf::PacketInterpreterBase::Factory
137 prefix_ senf::PacketInterpreterBase::Factory::~Factory()
140 //-/////////////////////////////////////////////////////////////////////////////////////////////////
142 //#include "PacketInterpreter.mpp"
148 // c-file-style: "senf"
149 // indent-tabs-mode: nil
150 // ispell-local-dictionary: "american"
151 // compile-command: "scons -u test"
152 // comment-column: 40