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 template implementation */
26 #include "PacketImpl.ih"
30 #define prefix_ inline
31 ///////////////////////////////cti.p///////////////////////////////////////
33 ///////////////////////////////////////////////////////////////////////////
34 // senf::detail::AnnotationRegistry
36 template <class Annotation>
37 prefix_ key_t senf::detail::AnnotationRegistry::registerAnnotation()
39 key_t key (simpleAnnotationCount_ >= SENF_PACKET_ANNOTATION_SLOTS
40 || IsComplexAnnotation<Annotation>::value
41 ? - ++complexAnnotationCount_
42 : simpleAnnotationCount_ ++);
43 registry_.insert(key, new Registration<Annotation>());
44 std::cerr << ">> allocated key " << key
45 << " for " << prettyName(typeid(Annotation))
46 << "(complex: " << IsComplexAnnotation<Annotation>::value
47 << ", convertible: " << boost::is_convertible<Annotation*, ComplexAnnotation*>::value
48 << ", size: " << sizeof(Annotation)
49 << ", max: " << SENF_PACKET_ANNOTATION_SLOTSIZE << ")" << std::endl;
53 template <class Annotation>
54 prefix_ key_t senf::detail::AnnotationRegistry::lookup()
56 SENF_ASSERT( instance().keyBegin() <= AnnotationRegistry::Entry<Annotation>::key()
57 && AnnotationRegistry::Entry<Annotation>::key() < instance().keyEnd(),
58 "internal error: annotation key not registered" );
59 SENF_ASSERT( AnnotationRegistry::Entry<Annotation>::key() < 0
60 || ! IsComplexAnnotation<Annotation>::value,
61 "internal error: complex annotation registered with invalid key" );
62 SENF_ASSERT( AnnotationRegistry::Entry<Annotation>::key() < SENF_PACKET_ANNOTATION_SLOTS,
63 "internal error: annotation key out of valid range" );
64 return AnnotationRegistry::Entry<Annotation>::key();
67 prefix_ key_t senf::detail::AnnotationRegistry::keyBegin()
70 return -complexAnnotationCount_;
73 prefix_ key_t senf::detail::AnnotationRegistry::keyEnd()
76 return simpleAnnotationCount_;
79 ///////////////////////////////////////////////////////////////////////////
80 // senf::detail::PacketImpl
84 template <class ForwardIterator>
85 prefix_ void senf::detail::PacketImpl::insert(PacketData * self, iterator pos, ForwardIterator f,
88 difference_type ix (std::distance(begin(),pos));
89 data_.insert(pos,f,l);
90 updateIterators(self,ix,std::distance(f,l));
93 template <class InputIterator>
94 prefix_ senf::detail::PacketImpl::PacketImpl(InputIterator first, InputIterator last)
95 : refcount_(0), data_(first,last)
97 ::memset(simpleAnnotations_, 0, sizeof(simpleAnnotations_));
102 template <class Annotation>
103 prefix_ Annotation & senf::detail::PacketImpl::annotation()
105 AnnotationRegistry::key_t key (AnnotationRegistry::lookup<Annotation>());
106 void * antn (key >= 0 ? & simpleAnnotations_[key] : complexAnnotation<Annotation>());
107 SENF_ASSERT( antn, "internal error: null annotation pointer" );
108 return * static_cast<Annotation*>(antn);
111 ///////////////////////////////cti.e///////////////////////////////////////
118 // c-file-style: "senf"
119 // indent-tabs-mode: nil
120 // ispell-local-dictionary: "american"
121 // compile-command: "scons -u test"
122 // comment-column: 40