2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
4 // Stefan Bund <g0dil@berlios.de>
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 \brief PacketImpl non-inline non-template implementation */
24 #include "PacketImpl.hh"
25 //#include "PacketImpl.ih"
29 #include "PacketInterpreter.hh"
31 //#include "PacketImpl.mpp"
33 ///////////////////////////////cc.p////////////////////////////////////////
35 ///////////////////////////////////////////////////////////////////////////
36 // senf::detail::PacketImpl
40 prefix_ void senf::detail::PacketImpl::appendInterpreter(PacketInterpreterBase * p)
42 interpreters_.push_back(*p);
46 prefix_ void senf::detail::PacketImpl::prependInterpreter(PacketInterpreterBase * p)
48 interpreters_.push_front(*p);
54 prefix_ void senf::detail::PacketImpl::clear(PacketData * self)
56 PacketInterpreterBase * n (next(static_cast<PacketInterpreterBase*>(self)));
58 truncateInterpreters(n);
59 iterator first (boost::next(begin(),self->begin_));
60 data_.erase(first, boost::next(begin(),self->end_));
61 updateIterators(self,first,-self->size());
66 prefix_ void senf::detail::PacketImpl::eraseInterpreters(interpreter_list::iterator b,
67 interpreter_list::iterator e)
70 interpreter_list::iterator i (b++);
71 PacketInterpreterBase * p (&(*i));
72 interpreters_.erase(i);
73 p->releaseImpl(); // might call PacketImpl::release and might delete p
77 prefix_ void senf::detail::PacketImpl::updateIterators(PacketData * self, iterator pos,
80 // I hate to change the PacketData representation from here, I would have preferred to let
81 // PacketData have authority over this but trying that just get's to convoluted so I choose the
82 // simple solution and made PacketImpl a friend of PacketData.
84 interpreter_list::iterator i (interpreters_.begin());
86 // There are three types of packets
87 // a) Those which come before 'self' in the interpreter chain
89 // c) Those that come afterwards
90 // For a), the change must be inside the packet since 'self' must be within those packets
91 // For b), the change must also be within since that's the packet we are changeing
92 // For c), the change must be outside the packet (we don't allow an upper packet to mess with
93 // the the data owned by a packet further down the chain). It can be before or after the
97 for (; &(*i) != static_cast<PacketInterpreterBase*>(self); ++i) i->end_ += n;
103 interpreter_list::iterator const i_end (interpreters_.end());
105 if (std::distance(begin(), pos) < difference_type(i->begin_))
106 // pos is before the packet, it must then be before all futher packets ...
107 for (; i != i_end; ++i) {
111 // else pos is after the packet and we don't need to change anything ...
114 ///////////////////////////////cc.e////////////////////////////////////////
116 //#include "PacketImpl.mpp"
122 // c-file-style: "senf"
123 // indent-tabs-mode: nil
124 // ispell-local-dictionary: "american"
125 // compile-command: "scons -u test"
126 // comment-column: 40