X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FPacketImpl.hh;h=667eebb151ec9e237711d89891ac433b4b6109a9;hb=7a5841bb928db440280cf91bbb3ea0230fd0e911;hp=871b9ec5948f9b377595a8e54be21b78a523f215;hpb=a1a6c76a214ad1935032826713cabaf9ac57bf07;p=senf.git diff --git a/Packets/PacketImpl.hh b/Packets/PacketImpl.hh index 871b9ec..667eebb 100644 --- a/Packets/PacketImpl.hh +++ b/Packets/PacketImpl.hh @@ -28,16 +28,96 @@ // Custom includes #include +#include #include +#include +#include +#include +#include #include "../Utils/pool_alloc_mixin.hh" #include "PacketTypes.hh" +#include "../Utils/singleton.hh" //#include "PacketImpl.mpp" ///////////////////////////////hh.p//////////////////////////////////////// namespace senf { + + /** \brief Marker base-class for complex annotations + + This class is used as a base class to mark an annotation type as complex. A complex + annotation will have it's constructor/destructor called. Non-complex annotations will not + have their constructor called, they will be zero initialized. The destructor of non-complex + annotations is never called. + + An annotation must be marked as complex if it is not POD. Simplified, an + annotation must be marked as ComplexAnnotation, if + + \li it has a (user defined) constructor or destructor + \li it has any data members which have (user defined) constructors or destructors + + \see \ref packet_usage_annotation + */ + struct ComplexAnnotation {}; + namespace detail { + struct AnnotationP + { + virtual ~AnnotationP(); + }; + + template + struct TAnnotationP + : public AnnotationP + { + Annotation annotation; + }; + + union AnnotationEntry { + AnnotationP * p; + unsigned long long i; + }; + + struct AnnotationIndexerBase + { + static unsigned maxAnnotations; + static std::vector & small(); + }; + + template + struct AnnotationIndexer + : public senf::singleton< AnnotationIndexer >, + public AnnotationIndexerBase + { + AnnotationIndexer(); + unsigned index_; + static unsigned index(); + static bool const Complex = boost::is_base_of::value; + static bool const Small = (sizeof(Annotation) <= sizeof(AnnotationEntry) && ! Complex); + +# ifdef BOOST_HAS_TYPE_TRAITS_INTRINSICS + + BOOST_STATIC_ASSERT(( (boost::has_trivial_constructor::value + && boost::has_trivial_destructor::value) + || Complex )); + +# endif + }; + + template ::Small> + struct GetAnnotation + { + static Annotation & get(AnnotationEntry & e); + }; + + template + struct GetAnnotation + { + static Annotation & get(AnnotationEntry & e); + }; + /** \brief Internal: Packet data storage \internal @@ -103,6 +183,10 @@ namespace detail { void erase(PacketData * self, iterator first, iterator last); void clear(PacketData * self); + // Annotations + template + Annotation & annotation(); + /** \brief Internal: Keep PacketImpl instance alive \internal @@ -121,6 +205,9 @@ namespace detail { refcount_t refcount_; raw_container data_; interpreter_list interpreters_; + + typedef std::vector Annotations; + Annotations annotations_; void eraseInterpreters(interpreter_list::iterator b, interpreter_list::iterator e); void updateIterators(PacketData * self, difference_type pos, difference_type n);