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 inline non-template implementation */
27 #include "../Utils/senfassert.hh"
28 // #include "PacketInterpreter.hh"
30 #define prefix_ inline
31 ///////////////////////////////cci.p///////////////////////////////////////
35 // * The PacketImpl destructor will *explicitly* clean-up the interpreters_ list by removing
36 // each element from the list and deleting it if it's (intrusive) refcount is 0
37 // * The PacketInterpreters use safe hooks -> they know wether they are part of a list or not
38 // * PacketHandle has an intrusive_ptr to PacketInterpreterBase. The intrusive_ptr_add_ref
39 // will refcount both the PacketImpl as well as the PacketInterpreterBase
40 // * intrusive_ptr_remove will only delete the object if it's not in a container
41 // * removing an object from the list will decrement the PacketImpl refcount accordingly
42 // * inserting an object into the list will incroment the PacketImpl refcount accordingly
43 // * each PacketInterpreterBase instance holds a *raw* pointer to the PacketImpl
45 // The following operations change refcounts:
47 // * intrusive_ptr_add_ref(PacketInterpreterBase *);
48 // * intrusive_ptr_remove(PacketInterpreterBase *);
49 // * PacketImpl::appendInterpreter();
50 // * PacketImpl::prependInterpreter();
51 // * PacketImpl::truncateInterpreters();
53 // The last three also modify the impl_ member accordingly by calling
54 // PacketInterpreterBase::assign/release
56 ///////////////////////////////////////////////////////////////////////////
57 // senf::detail::PacketImpl
59 prefix_ senf::detail::PacketImpl::PacketImpl()
63 prefix_ senf::detail::PacketImpl::PacketImpl(size_type size, byte initValue)
64 : refcount_(0), data_(size,initValue)
67 prefix_ senf::detail::PacketImpl::~PacketImpl()
69 // We increment refcount_ to ensure, release() won't call delete again
71 eraseInterpreters(interpreters_.begin(), interpreters_.end());
74 // rerference/memory management
76 prefix_ void senf::detail::PacketImpl::add_ref(refcount_t n)
81 prefix_ senf::detail::PacketImpl::refcount_t senf::detail::PacketImpl::refcount()
89 prefix_ senf::PacketInterpreterBase * senf::detail::PacketImpl::first()
91 return interpreters_.empty() ? 0 : & interpreters_.front();
94 prefix_ senf::PacketInterpreterBase * senf::detail::PacketImpl::last()
96 return interpreters_.empty() ? 0 : & interpreters_.back();
99 prefix_ senf::PacketInterpreterBase * senf::detail::PacketImpl::next(PacketInterpreterBase * p)
101 interpreter_list::iterator i (interpreter_list::current(*p));
102 return (++i == interpreters_.end()) ? 0 : &*i;
105 prefix_ senf::PacketInterpreterBase * senf::detail::PacketImpl::prev(PacketInterpreterBase * p)
107 interpreter_list::iterator i (interpreter_list::current(*p));
108 return (i == interpreters_.begin()) ? 0 : &*(--i);
111 prefix_ void senf::detail::PacketImpl::truncateInterpreters(PacketInterpreterBase * p)
114 eraseInterpreters(interpreter_list::current(*p),interpreters_.end());
117 prefix_ void senf::detail::PacketImpl::truncateInterpretersBackwards(PacketInterpreterBase * p)
120 eraseInterpreters(interpreters_.begin(),boost::next(interpreter_list::current(*p)));
125 prefix_ senf::detail::PacketImpl::iterator senf::detail::PacketImpl::begin()
127 return data_.begin();
130 prefix_ senf::detail::PacketImpl::iterator senf::detail::PacketImpl::end()
135 prefix_ senf::detail::PacketImpl::size_type senf::detail::PacketImpl::size()
140 prefix_ void senf::detail::PacketImpl::insert(PacketData * self, iterator pos, byte v)
142 difference_type ix (std::distance(begin(),pos));
144 updateIterators(self,ix,1);
147 prefix_ void senf::detail::PacketImpl::insert(PacketData * self, iterator pos, size_type n,
150 difference_type ix (std::distance(begin(),pos));
151 data_.insert(pos,n,v);
152 updateIterators(self,ix,n);
155 prefix_ void senf::detail::PacketImpl::erase(PacketData * self, iterator pos)
157 difference_type ix (std::distance(begin(),pos));
159 updateIterators(self,ix,-1);
162 prefix_ void senf::detail::PacketImpl::erase(PacketData * self, iterator first, iterator last)
164 difference_type ix (std::distance(begin(),first));
165 difference_type delta (std::distance(first,last));
166 data_.erase(first,last);
167 updateIterators(self,ix,-delta);
170 ///////////////////////////////////////////////////////////////////////////
171 // senf::detail::PacketImpl::Guard
173 prefix_ senf::detail::PacketImpl::Guard::Guard(PacketImpl * impl)
179 prefix_ senf::detail::PacketImpl::Guard::~Guard()
184 ///////////////////////////////cci.e///////////////////////////////////////
191 // c-file-style: "senf"
192 // indent-tabs-mode: nil
193 // ispell-local-dictionary: "american"
194 // compile-command: "scons -u test"
195 // comment-column: 40