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///////////////////////////////////////
33 ///////////////////////////////////////////////////////////////////////////
34 // senf::detail::AnnotationIndexerBase
36 prefix_ std::vector<bool> & senf::detail::AnnotationIndexerBase::small()
38 static std::vector<bool> smalls;
42 ///////////////////////////////////////////////////////////////////////////
43 // senf::detail::AnnotationP
45 prefix_ senf::detail::AnnotationP::~AnnotationP()
50 // * The PacketImpl destructor will *explicitly* clean-up the interpreters_ list by removing
51 // each element from the list and deleting it if it's (intrusive) refcount is 0
52 // * The PacketInterpreters use safe hooks -> they know wether they are part of a list or not
53 // * PacketHandle has an intrusive_ptr to PacketInterpreterBase. The intrusive_ptr_add_ref
54 // will refcount both the PacketImpl as well as the PacketInterpreterBase
55 // * intrusive_ptr_remove will only delete the object if it's not in a container
56 // * removing an object from the list will decrement the PacketImpl refcount accordingly
57 // * inserting an object into the list will incroment the PacketImpl refcount accordingly
58 // * each PacketInterpreterBase instance holds a *raw* pointer to the PacketImpl
60 // The following operations change refcounts:
62 // * intrusive_ptr_add_ref(PacketInterpreterBase *);
63 // * intrusive_ptr_remove(PacketInterpreterBase *);
64 // * PacketImpl::appendInterpreter();
65 // * PacketImpl::prependInterpreter();
66 // * PacketImpl::truncateInterpreters();
68 // The last three also modify the impl_ member accordingly by calling
69 // PacketInterpreterBase::assign/release
71 ///////////////////////////////////////////////////////////////////////////
72 // senf::detail::PacketImpl
74 prefix_ senf::detail::PacketImpl::PacketImpl()
75 : refcount_(0), annotations_(AnnotationIndexerBase::maxAnnotations)
78 prefix_ senf::detail::PacketImpl::PacketImpl(size_type size, byte initValue)
79 : refcount_(0), data_(size,initValue), annotations_(AnnotationIndexerBase::maxAnnotations)
82 // rerference/memory management
84 prefix_ void senf::detail::PacketImpl::add_ref(refcount_t n)
89 prefix_ senf::detail::PacketImpl::refcount_t senf::detail::PacketImpl::refcount()
97 prefix_ senf::PacketInterpreterBase * senf::detail::PacketImpl::first()
99 return interpreters_.empty() ? 0 : & interpreters_.front();
102 prefix_ senf::PacketInterpreterBase * senf::detail::PacketImpl::last()
104 return interpreters_.empty() ? 0 : & interpreters_.back();
107 prefix_ senf::PacketInterpreterBase * senf::detail::PacketImpl::next(PacketInterpreterBase * p)
109 interpreter_list::iterator i (interpreter_list::current(*p));
110 return (++i == interpreters_.end()) ? 0 : &*i;
113 prefix_ senf::PacketInterpreterBase * senf::detail::PacketImpl::prev(PacketInterpreterBase * p)
115 interpreter_list::iterator i (interpreter_list::current(*p));
116 return (i == interpreters_.begin()) ? 0 : &*(--i);
119 prefix_ void senf::detail::PacketImpl::truncateInterpreters(PacketInterpreterBase * p)
122 eraseInterpreters(interpreter_list::current(*p),interpreters_.end());
125 prefix_ void senf::detail::PacketImpl::truncateInterpretersBackwards(PacketInterpreterBase * p)
128 eraseInterpreters(interpreters_.begin(),boost::next(interpreter_list::current(*p)));
133 prefix_ senf::detail::PacketImpl::iterator senf::detail::PacketImpl::begin()
135 return data_.begin();
138 prefix_ senf::detail::PacketImpl::iterator senf::detail::PacketImpl::end()
143 prefix_ senf::detail::PacketImpl::size_type senf::detail::PacketImpl::size()
148 prefix_ void senf::detail::PacketImpl::insert(PacketData * self, iterator pos, byte v)
150 difference_type ix (std::distance(begin(),pos));
152 updateIterators(self,ix,1);
155 prefix_ void senf::detail::PacketImpl::insert(PacketData * self, iterator pos, size_type n,
158 difference_type ix (std::distance(begin(),pos));
159 data_.insert(pos,n,v);
160 updateIterators(self,ix,n);
163 prefix_ void senf::detail::PacketImpl::erase(PacketData * self, iterator pos)
165 difference_type ix (std::distance(begin(),pos));
167 updateIterators(self,ix,-1);
170 prefix_ void senf::detail::PacketImpl::erase(PacketData * self, iterator first, iterator last)
172 difference_type ix (std::distance(begin(),first));
173 difference_type delta (std::distance(first,last));
174 data_.erase(first,last);
175 updateIterators(self,ix,-delta);
178 prefix_ void senf::detail::PacketImpl::reserve(size_type n)
183 prefix_ senf::detail::PacketImpl::size_type senf::detail::PacketImpl::capacity()
186 return data_.capacity();
189 ///////////////////////////////////////////////////////////////////////////
190 // senf::detail::PacketImpl::Guard
192 prefix_ senf::detail::PacketImpl::Guard::Guard(PacketImpl * impl)
198 prefix_ senf::detail::PacketImpl::Guard::~Guard()
203 ///////////////////////////////cci.e///////////////////////////////////////
210 // c-file-style: "senf"
211 // indent-tabs-mode: nil
212 // ispell-local-dictionary: "american"
213 // compile-command: "scons -u test"
214 // comment-column: 40