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::ptr senf::PacketInterpreterBase::clone()
47 detail::PacketImpl::Guard p (new detail::PacketImpl(begin(),end()));
48 ptr pi (appendClone(p.p,begin(),p.p->begin()));
49 for (ptr i (next()); i; i = i->next())
50 i->appendClone(p.p,begin(),p.p->begin());
51 pi->impl().assignAnnotations( impl());
55 // Interpreter chain access
57 prefix_ senf::PacketInterpreterBase::ptr senf::PacketInterpreterBase::append(ptr packet)
60 impl().truncateInterpreters(next().get());
62 optional_range r (nextPacketRange());
64 throw InvalidPacketChainException();
66 ptr rv (packet->appendClone(&impl(), *r));
67 rv->data().resize(packet->data().size());
68 std::copy(packet->data().begin(), packet->data().end(), rv->data().begin());
70 for (ptr p (packet->next()) ; p ; p = p->next())
71 p->appendClone(&impl(), packet->data().begin(), rv->data().begin());
76 prefix_ void senf::PacketInterpreterBase::reparse()
79 impl().truncateInterpreters(next().get());
82 // Access to the abstract interface
84 prefix_ void senf::PacketInterpreterBase::dump(std::ostream & os)
87 if (detail::AnnotationRegistry::instance().begin()
88 != detail::AnnotationRegistry::instance().end()) {
89 os << "Annotations:\n";
90 impl().dumpAnnotations(os);
93 for (ptr i (next()); i; i = i->next())
96 catch (senf::Exception & e) {
97 os << "[Exception: " << e.message() << "]\n";
101 prefix_ void senf::PacketInterpreterBase::finalizeThis()
106 prefix_ void senf::PacketInterpreterBase::finalizeTo(ptr other)
108 for (ptr i (other); i.get() != this && i.get(); i = i->prev())
113 // reference/memory management
115 prefix_ void senf::PacketInterpreterBase::add_ref()
117 if (impl_ && !refcount())
119 intrusive_refcount_t<PacketInterpreterBase>::add_ref();
122 prefix_ void senf::PacketInterpreterBase::release()
124 if (impl_ && refcount()==1)
125 // This call will set impl_ to 0 if we just removed the last reference ...
127 if (intrusive_refcount_t<PacketInterpreterBase>::release() && !impl_)
131 //-/////////////////////////////////////////////////////////////////////////////////////////////////
132 // senf::PacketInterpreterBase::Factory
134 prefix_ senf::PacketInterpreterBase::Factory::~Factory()
137 //-/////////////////////////////////////////////////////////////////////////////////////////////////
139 //#include "PacketInterpreter.mpp"
145 // c-file-style: "senf"
146 // indent-tabs-mode: nil
147 // ispell-local-dictionary: "american"
148 // compile-command: "scons -u test"
149 // comment-column: 40