2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
15 \brief PacketImpl inline template implementation */
17 #include "PacketImpl.ih"
21 #define prefix_ inline
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 // senf::detail::AnnotationRegistry
27 template <class Annotation>
28 prefix_ senf::detail::AnnotationRegistry::key_type
29 senf::detail::AnnotationRegistry::registerAnnotation()
31 #ifndef SENF_PACKET_NO_COMPLEX_ANNOTATIONS
32 key_type key (simpleAnnotationCount_ >= SENF_PACKET_ANNOTATION_SLOTS
33 || IsComplexAnnotation<Annotation>::value
34 ? - ++complexAnnotationCount_
35 : simpleAnnotationCount_ ++);
37 key_type key (simpleAnnotationCount_ ++);
38 SENF_ASSERT(simpleAnnotationCount_ <= SENF_PACKET_ANNOTATION_SLOTS,
39 "to many annotations defined and complex annotations disabled");
40 SENF_STATIC_ASSERT(! IsComplexAnnotation<Annotation>::value,
41 annotation_is_complex_but_complex_annotations_disabled);
43 std::pair<Registry::iterator, bool> reg (
44 registry_.insert(key, new Registration<Annotation>()));
45 SENF_ASSERT(reg.second, "internal error: duplicate annotation key");
46 index_.insert(std::make_pair(reg.first->second->v_name(), key));
50 template <class Annotation>
51 prefix_ senf::detail::AnnotationRegistry::key_type senf::detail::AnnotationRegistry::lookup()
53 #ifndef SENF_PACKET_NO_COMPLEX_ANNOTATIONS
55 -instance().complexAnnotationCount_ <= AnnotationRegistry::Entry<Annotation>::key()
56 && AnnotationRegistry::Entry<Annotation>::key() < instance().simpleAnnotationCount_,
57 "internal error: annotation key not registered" );
59 AnnotationRegistry::Entry<Annotation>::key() < 0
60 || ! IsComplexAnnotation<Annotation>::value,
61 "internal error: complex annotation registered with invalid key" );
64 AnnotationRegistry::Entry<Annotation>::key() >= 0,
65 "internal error: annotation key out of valid range" );
68 AnnotationRegistry::Entry<Annotation>::key() < SENF_PACKET_ANNOTATION_SLOTS,
69 "internal error: annotation key out of valid range" );
70 return AnnotationRegistry::Entry<Annotation>::key();
73 //-/////////////////////////////////////////////////////////////////////////////////////////////////
74 // senf::detail::PacketImpl
78 template <class ForwardIterator>
79 prefix_ void senf::detail::PacketImpl::insert(PacketData * self, iterator pos, ForwardIterator f,
82 difference_type ix (std::distance(begin(),pos));
83 data_.insert(pos,f,l);
84 updateIterators(self,ix,std::distance(f,l));
87 template <class InputIterator>
88 prefix_ senf::detail::PacketImpl::PacketImpl(InputIterator first, InputIterator last)
89 : refcount_(0), data_(first,last)
90 #ifdef SENF_PACKET_ALTERNATIVE_PREALLOC
91 , preallocHigh_(0), preallocFree_(0)
93 , preallocFree_(prealloc_)
95 #ifndef SENF_PACKET_NO_HEAP_INTERPRETERS
96 , preallocHeapcount_(0)
99 ::memset(simpleAnnotations_, 0, sizeof(simpleAnnotations_));
100 #ifndef SENF_PACKET_ALTERNATIVE_PREALLOC
101 ::memset(prealloc_, 0, sizeof(prealloc_));
107 template <class Annotation>
108 prefix_ Annotation & senf::detail::PacketImpl::annotation()
110 AnnotationRegistry::key_type key (AnnotationRegistry::lookup<Annotation>());
111 #ifndef SENF_PACKET_NO_COMPLEX_ANNOTATIONS
112 void * antn (key >= 0 ? & simpleAnnotations_[key] : complexAnnotation<Annotation>());
114 void * antn (& simpleAnnotations_[key]);
116 SENF_ASSERT( antn, "internal error: null annotation pointer" );
117 return * static_cast<Annotation*>(antn);
120 //-/////////////////////////////////////////////////////////////////////////////////////////////////
127 // c-file-style: "senf"
128 // indent-tabs-mode: nil
129 // ispell-local-dictionary: "american"
130 // compile-command: "scons -u test"
131 // comment-column: 40