4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief PacketImpl non-inline non-template implementation */
26 #include "PacketImpl.ih"
32 #include <boost/format.hpp>
33 #include <senf/Utils/String.hh>
36 //#include "PacketImpl.mpp"
38 ///////////////////////////////cc.p////////////////////////////////////////
40 ///////////////////////////////////////////////////////////////////////////
41 // senf::detail::PacketImpl
43 prefix_ senf::detail::PacketImpl::~PacketImpl()
45 // We increment refcount_ to ensure, release() won't call delete again
47 eraseInterpreters(interpreters_.begin(), interpreters_.end());
52 prefix_ void senf::detail::PacketImpl::appendInterpreter(PacketInterpreterBase * p)
54 interpreters_.push_back(*p);
58 prefix_ void senf::detail::PacketImpl::prependInterpreter(PacketInterpreterBase * p)
60 interpreters_.push_front(*p);
64 prefix_ void senf::detail::PacketImpl::prependInterpreter(PacketInterpreterBase * p,
65 PacketInterpreterBase * before)
67 interpreter_list::iterator i (interpreter_list::current(*before));
68 interpreters_.insert(i, *p);
74 prefix_ void senf::detail::PacketImpl::clear(PacketData * self)
76 PacketInterpreterBase * n (next(static_cast<PacketInterpreterBase*>(self)));
78 truncateInterpreters(n);
79 iterator first (boost::next(begin(),self->begin_));
80 data_.erase(first, boost::next(begin(),self->end_));
81 updateIterators(self,self->begin_,-self->size());
86 prefix_ void senf::detail::PacketImpl::eraseInterpreters(interpreter_list::iterator b,
87 interpreter_list::iterator e)
90 interpreter_list::iterator i (b++);
91 PacketInterpreterBase * p (&(*i));
92 interpreters_.erase(i);
93 p->releaseImpl(); // might call PacketImpl::release and might delete p
97 prefix_ void senf::detail::PacketImpl::updateIterators(PacketData * self, difference_type pos,
100 // I hate to change the PacketData representation from here, I would have preferred to let
101 // PacketData have authority over this but trying that just get's to convoluted so I choose the
102 // simple solution and made PacketImpl a friend of PacketData.
104 interpreter_list::iterator i (interpreters_.begin());
106 // There are three types of packets
107 // a) Those which come before 'self' in the interpreter chain
109 // c) Those that come afterwards
110 // For a), the change must be inside the packet since 'self' must be within those packets
111 // For b), the change must also be within since that's the packet we are changing
112 // For c), the change must be outside the packet (we don't allow an upper packet to mess with
113 // the the data owned by a packet further down the chain). It can be before or after the
117 for (; &(*i) != static_cast<PacketInterpreterBase*>(self); ++i) i->end_ += n;
123 interpreter_list::iterator const i_end (interpreters_.end());
125 if (pos <= difference_type(i->begin_))
126 // pos is before the packet, it must then be before all further packets ...
127 for (; i != i_end; ++i) {
131 // else pos is after the packet and we don't need to change anything ...
136 prefix_ void senf::detail::PacketImpl::dumpAnnotations(std::ostream & os)
138 for (AnnotationRegistry::iterator i (AnnotationRegistry::instance().begin());
139 i != AnnotationRegistry::instance().end(); ++i) {
140 void * antn (annotation(*i));
142 AnnotationRegistry::instance().dump(*i, os, antn);
146 prefix_ void * senf::detail::PacketImpl::complexAnnotation(AnnotationRegistry::key_type key)
148 SENF_ASSERT( key < 0, "complexAnnotation called with invalid key");
149 return (ComplexAnnotations::size_type(-key-1) >= complexAnnotations_.size()
150 || complexAnnotations_.is_null(-key-1))
151 ? 0 : complexAnnotations_[-key-1].get();
154 ///////////////////////////////////////////////////////////////////////////
155 // senf::detail::AnnotationRegistry
157 prefix_ void senf::detail::AnnotationRegistry::dumpRegistrations(std::ostream & os)
159 boost::format fmt ("%-56.56s %-4.4s %-7.7s %5d\n");
160 os << "SENF_PACKET_ANNOTATION_SLOTS = " << SENF_PACKET_ANNOTATION_SLOTS << "\n"
161 << "SENF_PACKET_ANNOTATION_SLOTSIZE = " << SENF_PACKET_ANNOTATION_SLOTSIZE << "\n";
162 os << fmt % "TYPE" % "FAST" % "COMPLEX" % "SIZE";
164 for (Index::const_iterator i (index_.begin()), i_end (index_.end()); i != i_end; ++i) {
165 key_type key (i->second);
166 std::string nm (i->first);
167 if (nm.size() > 56) nm.erase(nm.begin(), nm.begin()+nm.size()-32);
170 % (key >= 0 ? "yes" : "no")
171 % (isComplex(key) ? "yes" : "no")
176 prefix_ void senf::dumpPacketAnnotationRegistry(std::ostream & os)
178 senf::detail::AnnotationRegistry::instance().dumpRegistrations(os);
181 /////////////////////////////cc.e////////////////////////////////////////
183 //#include "PacketImpl.mpp"
189 // c-file-style: "senf"
190 // indent-tabs-mode: nil
191 // ispell-local-dictionary: "american"
192 // compile-command: "scons -u test"
193 // comment-column: 40