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 inline non-template implementation */
25 #include "PacketInterpreter.hh"
27 #define prefix_ inline
28 ///////////////////////////////cci.p///////////////////////////////////////
32 // * The PacketImpl destructor will *explicitly* clean-up the interpreters_ list by removing
33 // each element from the list and deleting it if it's (intrusive) refcount is 0
34 // * The PacketInterpreters use safe hooks -> they know wether they are part of a list or not
35 // * PacketHandle has an intrusive_ptr to PacketInterpreterBase. The intrusive_ptr_add_ref
36 // will refcount both the PacketImpl as well as the PacketInterpreterBase
37 // * intrusive_ptr_remove will only delete the object if it's not in a container
38 // * removing an object from the list will decrement the PacketImpl refcount accordingly
39 // * inserting an object into the list will incroment the PacketImpl refcount accordingly
40 // * each PacketInterpreterBase instance holds a *raw* pointer to the PacketImpl
42 // The following operations change refcounts:
44 // * intrusive_ptr_add_ref(PacketInterpreterBase *);
45 // * intrusive_ptr_remove(PacketInterpreterBase *);
46 // * PacketImpl::appendInterpreter();
47 // * PacketImpl::prependInterpreter();
48 // * PacketImpl::truncateInterpreters();
50 // The last three also modify the impl_ member accordingly by calling
51 // PacketInterpreterBase::assign/release
53 ///////////////////////////////////////////////////////////////////////////
54 // senf::detail::PacketImpl
56 prefix_ senf::detail::PacketImpl::PacketImpl()
60 prefix_ senf::detail::PacketImpl::PacketImpl(size_type size, byte initValue)
61 : refcount_(0), data_(size,initValue)
64 prefix_ senf::detail::PacketImpl::~PacketImpl()
66 // We increment refcount_ to ensure, release() won't call delete again
68 eraseInterpreters(interpreters_.begin(), interpreters_.end());
71 // rerference/memory management
73 prefix_ void senf::detail::PacketImpl::add_ref(refcount_t n)
78 prefix_ void senf::detail::PacketImpl::release(refcount_t n)
80 BOOST_ASSERT(refcount_ >= n);
81 // uah ... we need to be extremely careful here. If refcount_ is n, we want to commit suicide,
82 // however the destructor will remove all PacketInterpreters from the list and will thereby
83 // decrement refcount -> only decrenebt refcount_ when *not* caling delete
90 prefix_ senf::detail::PacketImpl::refcount_t senf::detail::PacketImpl::refcount()
98 prefix_ senf::PacketInterpreterBase * senf::detail::PacketImpl::first()
100 return interpreters_.empty() ? 0 : & interpreters_.front();
103 prefix_ senf::PacketInterpreterBase * senf::detail::PacketImpl::last()
105 return interpreters_.empty() ? 0 : & interpreters_.back();
108 prefix_ senf::PacketInterpreterBase * senf::detail::PacketImpl::next(PacketInterpreterBase * p)
110 interpreter_list::iterator i (interpreter_list::current(*p));
111 return (++i == interpreters_.end()) ? 0 : &*i;
114 prefix_ senf::PacketInterpreterBase * senf::detail::PacketImpl::prev(PacketInterpreterBase * p)
116 interpreter_list::iterator i (interpreter_list::current(*p));
117 return (i == interpreters_.begin()) ? 0 : &*(--i);
120 prefix_ void senf::detail::PacketImpl::truncateInterpreters(PacketInterpreterBase * p)
123 eraseInterpreters(interpreter_list::current(*p),interpreters_.end());
126 prefix_ void senf::detail::PacketImpl::truncateInterpretersBackwards(PacketInterpreterBase * p)
129 eraseInterpreters(interpreters_.begin(),boost::next(interpreter_list::current(*p)));
134 prefix_ senf::detail::PacketImpl::iterator senf::detail::PacketImpl::begin()
136 return data_.begin();
139 prefix_ senf::detail::PacketImpl::iterator senf::detail::PacketImpl::end()
144 prefix_ senf::detail::PacketImpl::size_type senf::detail::PacketImpl::size()
149 prefix_ void senf::detail::PacketImpl::insert(PacketData * self, iterator pos, byte v)
152 updateIterators(self,pos,1);
155 prefix_ void senf::detail::PacketImpl::insert(PacketData * self, iterator pos, size_type n,
158 data_.insert(pos,n,v);
159 updateIterators(self,pos,n);
162 prefix_ void senf::detail::PacketImpl::erase(PacketData * self, iterator pos)
165 updateIterators(self,pos,-1);
168 prefix_ void senf::detail::PacketImpl::erase(PacketData * self, iterator first, iterator last)
170 data_.erase(first,last);
171 updateIterators(self,first,-std::distance(first,last));
174 ///////////////////////////////////////////////////////////////////////////
175 // senf::detail::PacketImpl::Guard
177 prefix_ senf::detail::PacketImpl::Guard::Guard(PacketImpl * impl)
183 prefix_ senf::detail::PacketImpl::Guard::~Guard()
188 ///////////////////////////////cci.e///////////////////////////////////////
195 // c-file-style: "senf"
196 // indent-tabs-mode: nil
197 // ispell-local-dictionary: "american"
198 // compile-command: "scons -u test"
199 // comment-column: 40