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 "PacketImpl.mpp"
34 ///////////////////////////////cc.p////////////////////////////////////////
36 unsigned senf::detail::AnnotationIndexerBase::maxAnnotations (0);
38 ///////////////////////////////////////////////////////////////////////////
39 // senf::detail::PacketImpl
41 prefix_ senf::detail::PacketImpl::~PacketImpl()
43 // We increment refcount_ to ensure, release() won't call delete again
45 eraseInterpreters(interpreters_.begin(), interpreters_.end());
46 Annotations::const_iterator i (annotations_.begin());
47 Annotations::const_iterator const i_end (annotations_.end());
48 std::vector<bool>::iterator small (AnnotationIndexerBase::small().begin());
49 for (; i != i_end; ++i, ++small)
54 // This function has a problem being inlined. Somehow, often when calling this, the size of the
55 // resulting inlined code would be huge. Need to further debug this.
57 prefix_ void senf::detail::PacketImpl::release(refcount_t n)
59 SENF_ASSERT(refcount_ >= n);
60 // uah ... we need to be extremely careful here. If refcount_ is n, we want to commit suicide,
61 // however the destructor will remove all PacketInterpreters from the list and will thereby
62 // decrement refcount -> only decrenebt refcount_ when *not* caling delete
71 prefix_ void senf::detail::PacketImpl::appendInterpreter(PacketInterpreterBase * p)
73 interpreters_.push_back(*p);
77 prefix_ void senf::detail::PacketImpl::prependInterpreter(PacketInterpreterBase * p)
79 interpreters_.push_front(*p);
85 prefix_ void senf::detail::PacketImpl::clear(PacketData * self)
87 PacketInterpreterBase * n (next(static_cast<PacketInterpreterBase*>(self)));
89 truncateInterpreters(n);
90 iterator first (boost::next(begin(),self->begin_));
91 data_.erase(first, boost::next(begin(),self->end_));
92 updateIterators(self,self->begin_,-self->size());
97 prefix_ void senf::detail::PacketImpl::eraseInterpreters(interpreter_list::iterator b,
98 interpreter_list::iterator e)
101 interpreter_list::iterator i (b++);
102 PacketInterpreterBase * p (&(*i));
103 interpreters_.erase(i);
104 p->releaseImpl(); // might call PacketImpl::release and might delete p
108 prefix_ void senf::detail::PacketImpl::updateIterators(PacketData * self, difference_type pos,
111 // I hate to change the PacketData representation from here, I would have preferred to let
112 // PacketData have authority over this but trying that just get's to convoluted so I choose the
113 // simple solution and made PacketImpl a friend of PacketData.
115 interpreter_list::iterator i (interpreters_.begin());
117 // There are three types of packets
118 // a) Those which come before 'self' in the interpreter chain
120 // c) Those that come afterwards
121 // For a), the change must be inside the packet since 'self' must be within those packets
122 // For b), the change must also be within since that's the packet we are changeing
123 // For c), the change must be outside the packet (we don't allow an upper packet to mess with
124 // the the data owned by a packet further down the chain). It can be before or after the
128 for (; &(*i) != static_cast<PacketInterpreterBase*>(self); ++i) i->end_ += n;
134 interpreter_list::iterator const i_end (interpreters_.end());
136 if (pos <= difference_type(i->begin_))
137 // pos is before the packet, it must then be before all futher packets ...
138 for (; i != i_end; ++i) {
142 // else pos is after the packet and we don't need to change anything ...
145 ///////////////////////////////cc.e////////////////////////////////////////
147 //#include "PacketImpl.mpp"
153 // c-file-style: "senf"
154 // indent-tabs-mode: nil
155 // ispell-local-dictionary: "american"
156 // compile-command: "scons -u test"
157 // comment-column: 40