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 <senf/Utils/senfassert.hh>
28 // #include "PacketInterpreter.hh"
30 #define prefix_ inline
31 ///////////////////////////////cci.p///////////////////////////////////////
33 ///////////////////////////////////////////////////////////////////////////
34 // senf::detail::AnnotationIndexerBase
36 prefix_ senf::detail::AnnotationIndexerBase::~AnnotationIndexerBase()
39 prefix_ std::vector<bool> & senf::detail::AnnotationIndexerBase::small()
41 static std::vector<bool> smalls;
45 prefix_ std::vector<senf::detail::AnnotationIndexerBase*> &
46 senf::detail::AnnotationIndexerBase::registry()
48 static std::vector<AnnotationIndexerBase*> reg;
52 ///////////////////////////////////////////////////////////////////////////
53 // senf::detail::AnnotationP
55 prefix_ senf::detail::AnnotationP::~AnnotationP()
60 // * The PacketImpl destructor will *explicitly* clean-up the interpreters_ list by removing
61 // each element from the list and deleting it if it's (intrusive) refcount is 0
62 // * The PacketInterpreters use safe hooks -> they know wether they are part of a list or not
63 // * PacketHandle has an intrusive_ptr to PacketInterpreterBase. The intrusive_ptr_add_ref
64 // will refcount both the PacketImpl as well as the PacketInterpreterBase
65 // * intrusive_ptr_remove will only delete the object if it's not in a container
66 // * removing an object from the list will decrement the PacketImpl refcount accordingly
67 // * inserting an object into the list will incroment the PacketImpl refcount accordingly
68 // * each PacketInterpreterBase instance holds a *raw* pointer to the PacketImpl
70 // The following operations change refcounts:
72 // * intrusive_ptr_add_ref(PacketInterpreterBase *);
73 // * intrusive_ptr_remove(PacketInterpreterBase *);
74 // * PacketImpl::appendInterpreter();
75 // * PacketImpl::prependInterpreter();
76 // * PacketImpl::truncateInterpreters();
78 // The last three also modify the impl_ member accordingly by calling
79 // PacketInterpreterBase::assign/release
81 ///////////////////////////////////////////////////////////////////////////
82 // senf::detail::PacketImpl
84 prefix_ senf::detail::PacketImpl::PacketImpl()
85 : refcount_(0), annotations_(AnnotationIndexerBase::maxAnnotations)
88 prefix_ senf::detail::PacketImpl::PacketImpl(size_type size, byte initValue)
89 : refcount_(0), data_(size,initValue), annotations_(AnnotationIndexerBase::maxAnnotations)
92 // rerference/memory management
94 prefix_ void senf::detail::PacketImpl::add_ref(refcount_t n)
99 prefix_ senf::detail::PacketImpl::refcount_t senf::detail::PacketImpl::refcount()
107 prefix_ senf::PacketInterpreterBase * senf::detail::PacketImpl::first()
109 return interpreters_.empty() ? 0 : & interpreters_.front();
112 prefix_ senf::PacketInterpreterBase * senf::detail::PacketImpl::last()
114 return interpreters_.empty() ? 0 : & interpreters_.back();
117 prefix_ senf::PacketInterpreterBase * senf::detail::PacketImpl::next(PacketInterpreterBase * p)
119 interpreter_list::iterator i (interpreter_list::current(*p));
120 return (++i == interpreters_.end()) ? 0 : &*i;
123 prefix_ senf::PacketInterpreterBase * senf::detail::PacketImpl::prev(PacketInterpreterBase * p)
125 interpreter_list::iterator i (interpreter_list::current(*p));
126 return (i == interpreters_.begin()) ? 0 : &*(--i);
129 prefix_ void senf::detail::PacketImpl::truncateInterpreters(PacketInterpreterBase * p)
132 eraseInterpreters(interpreter_list::current(*p),interpreters_.end());
135 prefix_ void senf::detail::PacketImpl::truncateInterpretersBackwards(PacketInterpreterBase * p)
138 eraseInterpreters(interpreters_.begin(),boost::next(interpreter_list::current(*p)));
143 prefix_ senf::detail::PacketImpl::iterator senf::detail::PacketImpl::begin()
145 return data_.begin();
148 prefix_ senf::detail::PacketImpl::iterator senf::detail::PacketImpl::end()
153 prefix_ senf::detail::PacketImpl::size_type senf::detail::PacketImpl::size()
158 prefix_ void senf::detail::PacketImpl::insert(PacketData * self, iterator pos, byte v)
160 difference_type ix (std::distance(begin(),pos));
162 updateIterators(self,ix,1);
165 prefix_ void senf::detail::PacketImpl::insert(PacketData * self, iterator pos, size_type n,
168 difference_type ix (std::distance(begin(),pos));
169 data_.insert(pos,n,v);
170 updateIterators(self,ix,n);
173 prefix_ void senf::detail::PacketImpl::erase(PacketData * self, iterator pos)
175 difference_type ix (std::distance(begin(),pos));
177 updateIterators(self,ix,-1);
180 prefix_ void senf::detail::PacketImpl::erase(PacketData * self, iterator first, iterator last)
182 difference_type ix (std::distance(begin(),first));
183 difference_type delta (std::distance(first,last));
184 data_.erase(first,last);
185 updateIterators(self,ix,-delta);
188 prefix_ void senf::detail::PacketImpl::reserve(size_type n)
193 prefix_ senf::detail::PacketImpl::size_type senf::detail::PacketImpl::capacity()
196 return data_.capacity();
199 prefix_ void senf::detail::PacketImpl::dumpAnnotations(std::ostream & os)
201 AnnotationIndexerBase::dump(this, os);
204 // This function has a problem being inlined. Somehow, often when calling this, the size of the
205 // resulting inlined code would be huge?
207 prefix_ void senf::detail::PacketImpl::release(refcount_t n)
209 SENF_ASSERT(refcount_ >= n);
210 // uah ... we need to be extremely careful here. If refcount_ is n, we want to commit suicide,
211 // however the destructor will remove all PacketInterpreters from the list and will thereby
212 // decrement refcount -> only decrenebt refcount_ when *not* caling delete
220 ///////////////////////////////////////////////////////////////////////////
221 // senf::detail::PacketImpl::Guard
223 prefix_ senf::detail::PacketImpl::Guard::Guard(PacketImpl * impl)
229 prefix_ senf::detail::PacketImpl::Guard::~Guard()
234 ///////////////////////////////cci.e///////////////////////////////////////
241 // c-file-style: "senf"
242 // indent-tabs-mode: nil
243 // ispell-local-dictionary: "american"
244 // compile-command: "scons -u test"
245 // comment-column: 40