4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief PacketImpl inline non-template implementation */
33 #define prefix_ inline
34 //-/////////////////////////////////////////////////////////////////////////////////////////////////
36 //-/////////////////////////////////////////////////////////////////////////////////////////////////
37 // senf::detail::AnnotationRegistry
39 prefix_ std::string senf::detail::AnnotationRegistry::name(key_type key)
42 Registry::const_iterator i (registry_.find(key));
43 return i == registry_.end() ? "" : i->second->v_name();
46 prefix_ bool senf::detail::AnnotationRegistry::isComplex(key_type key)
49 Registry::const_iterator i (registry_.find(key));
50 return i != registry_.end() && i->second->v_isComplex();
53 prefix_ unsigned senf::detail::AnnotationRegistry::size(key_type key)
56 Registry::const_iterator i (registry_.find(key));
57 return i == registry_.end() ? 0 : i->second->v_size();
60 prefix_ senf::detail::AnnotationRegistry::iterator senf::detail::AnnotationRegistry::begin()
63 return boost::make_transform_iterator(index_.begin(),
64 __gnu_cxx::select2nd<Index::value_type>());
67 prefix_ senf::detail::AnnotationRegistry::iterator senf::detail::AnnotationRegistry::end()
70 return boost::make_transform_iterator(index_.end(),
71 __gnu_cxx::select2nd<Index::value_type>());
74 prefix_ senf::detail::AnnotationRegistry::AnnotationRegistry()
75 : simpleAnnotationCount_ (0), complexAnnotationCount_ (0)
78 //-/////////////////////////////////////////////////////////////////////////////////////////////////
82 // * The PacketImpl destructor will *explicitly* clean-up the interpreters_ list by removing
83 // each element from the list and deleting it if it's (intrusive) refcount is 0
84 // * The PacketInterpreters use safe hooks -> they know whether they are part of a list or not
85 // * PacketHandle has an intrusive_ptr to PacketInterpreterBase. The intrusive_ptr_add_ref
86 // will refcount both the PacketImpl as well as the PacketInterpreterBase
87 // * intrusive_ptr_remove will only delete the object if it's not in a container
88 // * removing an object from the list will decrement the PacketImpl refcount accordingly
89 // * inserting an object into the list will increment the PacketImpl refcount accordingly
90 // * each PacketInterpreterBase instance holds a *raw* pointer to the PacketImpl
92 // The following operations change refcounts:
94 // * intrusive_ptr_add_ref(PacketInterpreterBase *);
95 // * intrusive_ptr_remove(PacketInterpreterBase *);
96 // * PacketImpl::appendInterpreter();
97 // * PacketImpl::prependInterpreter();
98 // * PacketImpl::truncateInterpreters();
100 // The last three also modify the impl_ member accordingly by calling
101 // PacketInterpreterBase::assign/release
103 //-/////////////////////////////////////////////////////////////////////////////////////////////////
104 // senf::detail::PacketImpl
106 prefix_ senf::detail::PacketImpl::PacketImpl()
109 ::memset(simpleAnnotations_, 0, sizeof(simpleAnnotations_));
112 prefix_ senf::detail::PacketImpl::PacketImpl(size_type size, byte initValue)
113 : refcount_(0), data_(size,initValue)
115 ::memset(simpleAnnotations_, 0, sizeof(simpleAnnotations_));
118 // reference/memory management
120 prefix_ void senf::detail::PacketImpl::add_ref()
125 prefix_ senf::detail::PacketImpl::refcount_t senf::detail::PacketImpl::refcount()
133 prefix_ senf::PacketInterpreterBase * senf::detail::PacketImpl::first()
135 return interpreters_.empty() ? 0 : & interpreters_.front();
138 prefix_ senf::PacketInterpreterBase * senf::detail::PacketImpl::last()
140 return interpreters_.empty() ? 0 : & interpreters_.back();
143 prefix_ senf::PacketInterpreterBase * senf::detail::PacketImpl::next(PacketInterpreterBase * p)
145 interpreter_list::iterator i (interpreter_list::current(*p));
146 return (++i == interpreters_.end()) ? 0 : &*i;
149 prefix_ senf::PacketInterpreterBase * senf::detail::PacketImpl::prev(PacketInterpreterBase * p)
151 interpreter_list::iterator i (interpreter_list::current(*p));
152 return (i == interpreters_.begin()) ? 0 : &*(--i);
155 prefix_ void senf::detail::PacketImpl::truncateInterpreters(PacketInterpreterBase * p)
158 eraseInterpreters(interpreter_list::current(*p),interpreters_.end());
161 prefix_ void senf::detail::PacketImpl::truncateInterpretersBackwards(PacketInterpreterBase * p)
164 eraseInterpreters(interpreters_.begin(),boost::next(interpreter_list::current(*p)));
169 prefix_ senf::detail::PacketImpl::iterator senf::detail::PacketImpl::begin()
171 return data_.begin();
174 prefix_ senf::detail::PacketImpl::iterator senf::detail::PacketImpl::end()
179 prefix_ senf::detail::PacketImpl::size_type senf::detail::PacketImpl::size()
184 prefix_ void senf::detail::PacketImpl::insert(PacketData * self, iterator pos, byte v)
186 difference_type ix (std::distance(begin(),pos));
188 updateIterators(self,ix,1);
191 prefix_ void senf::detail::PacketImpl::insert(PacketData * self, iterator pos, size_type n,
194 difference_type ix (std::distance(begin(),pos));
195 data_.insert(pos,n,v);
196 updateIterators(self,ix,n);
199 prefix_ void senf::detail::PacketImpl::erase(PacketData * self, iterator pos)
201 difference_type ix (std::distance(begin(),pos));
203 updateIterators(self,ix,-1);
206 prefix_ void senf::detail::PacketImpl::erase(PacketData * self, iterator first, iterator last)
208 difference_type ix (std::distance(begin(),first));
209 difference_type delta (std::distance(first,last));
210 data_.erase(first,last);
211 updateIterators(self,ix,-delta);
214 prefix_ void senf::detail::PacketImpl::reserve(size_type n)
219 prefix_ senf::detail::PacketImpl::size_type senf::detail::PacketImpl::capacity()
222 return data_.capacity();
227 prefix_ void * senf::detail::PacketImpl::annotation(AnnotationRegistry::key_type key)
229 return key >= 0 ? & simpleAnnotations_[key] : complexAnnotation(key);
232 //-/////////////////////////////////////////////////////////////////////////////////////////////////
233 // senf::detail::PacketImpl::Guard
235 prefix_ senf::detail::PacketImpl::Guard::Guard(PacketImpl * impl)
241 prefix_ senf::detail::PacketImpl::Guard::~Guard()
246 //-/////////////////////////////////////////////////////////////////////////////////////////////////
253 // c-file-style: "senf"
254 // indent-tabs-mode: nil
255 // ispell-local-dictionary: "american"
256 // compile-command: "scons -u test"
257 // comment-column: 40