00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00026 #include "PacketImpl.ih"
00027
00028
00029
00030 #define prefix_ inline
00031
00032
00033
00034
00035
00036 template <class Annotation>
00037 prefix_ senf::detail::AnnotationRegistry::key_type
00038 senf::detail::AnnotationRegistry::registerAnnotation()
00039 {
00040 key_type key (simpleAnnotationCount_ >= SENF_PACKET_ANNOTATION_SLOTS
00041 || IsComplexAnnotation<Annotation>::value
00042 ? - ++complexAnnotationCount_
00043 : simpleAnnotationCount_ ++);
00044 std::pair<Registry::iterator, bool> reg (
00045 registry_.insert(key, new Registration<Annotation>()));
00046 SENF_ASSERT(reg.second, "internal error: duplicate annotation key");
00047 index_.insert(std::make_pair(reg.first->second->v_name(), key));
00048 return key;
00049 }
00050
00051 template <class Annotation>
00052 prefix_ senf::detail::AnnotationRegistry::key_type senf::detail::AnnotationRegistry::lookup()
00053 {
00054 SENF_ASSERT(
00055 -instance().complexAnnotationCount_ <= AnnotationRegistry::Entry<Annotation>::key()
00056 && AnnotationRegistry::Entry<Annotation>::key() < instance().simpleAnnotationCount_,
00057 "internal error: annotation key not registered" );
00058 SENF_ASSERT(
00059 AnnotationRegistry::Entry<Annotation>::key() < 0
00060 || ! IsComplexAnnotation<Annotation>::value,
00061 "internal error: complex annotation registered with invalid key" );
00062 SENF_ASSERT(
00063 AnnotationRegistry::Entry<Annotation>::key() < SENF_PACKET_ANNOTATION_SLOTS,
00064 "internal error: annotation key out of valid range" );
00065 return AnnotationRegistry::Entry<Annotation>::key();
00066 }
00067
00068
00069
00070
00071
00072
00073 template <class ForwardIterator>
00074 prefix_ void senf::detail::PacketImpl::insert(PacketData * self, iterator pos, ForwardIterator f,
00075 ForwardIterator l)
00076 {
00077 difference_type ix (std::distance(begin(),pos));
00078 data_.insert(pos,f,l);
00079 updateIterators(self,ix,std::distance(f,l));
00080 }
00081
00082 template <class InputIterator>
00083 prefix_ senf::detail::PacketImpl::PacketImpl(InputIterator first, InputIterator last)
00084 : refcount_(0), data_(first,last)
00085 {
00086 ::memset(simpleAnnotations_, 0, sizeof(simpleAnnotations_));
00087 }
00088
00089
00090
00091 template <class Annotation>
00092 prefix_ Annotation & senf::detail::PacketImpl::annotation()
00093 {
00094 AnnotationRegistry::key_type key (AnnotationRegistry::lookup<Annotation>());
00095 void * antn (key >= 0 ? & simpleAnnotations_[key] : complexAnnotation<Annotation>());
00096 SENF_ASSERT( antn, "internal error: null annotation pointer" );
00097 return * static_cast<Annotation*>(antn);
00098 }
00099
00100
00101 #undef prefix_
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112