X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FPacketImpl.hh;h=0ad1e77f847caa6ddc5c7d8585c565af6afaa311;hb=8674fb1d184e7d620eb7c604957b5b4203df37a6;hp=1d1373f0cfe148d8484a069a647e782330b5514e;hpb=9348e1098d66ac2684c8e280abf8d7143c887982;p=senf.git diff --git a/Packets/PacketImpl.hh b/Packets/PacketImpl.hh index 1d1373f..0ad1e77 100644 --- a/Packets/PacketImpl.hh +++ b/Packets/PacketImpl.hh @@ -23,13 +23,17 @@ /** \file \brief PacketImpl public header */ -#ifndef HH_PacketImpl_ -#define HH_PacketImpl_ 1 +#ifndef HH_SENF_Packets_PacketImpl_ +#define HH_SENF_Packets_PacketImpl_ 1 // Custom includes #include #include #include +#include +#include +#include +#include #include "../Utils/pool_alloc_mixin.hh" #include "PacketTypes.hh" #include "../Utils/singleton.hh" @@ -38,12 +42,53 @@ ///////////////////////////////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 { + virtual ~AnnotationIndexerBase(); + virtual void v_dump(PacketImpl * p, std::ostream & os) = 0; + static unsigned maxAnnotations; static std::vector & small(); + static std::vector & registry(); + static void dump(PacketImpl * p, std::ostream & os); }; template @@ -52,36 +97,36 @@ namespace detail { public AnnotationIndexerBase { AnnotationIndexer(); + virtual void v_dump(PacketImpl * p, std::ostream & os); unsigned index_; static unsigned index(); - static bool const Small = (sizeof(Annotation) <= sizeof(void*)); - }; + static bool const Complex = boost::is_base_of::value; + static bool const Small = (sizeof(Annotation) <= sizeof(AnnotationEntry) && ! Complex); - struct AnnotationP - { - virtual ~AnnotationP(); - }; +# if 0 // The test is difficult since it does not work with user-defined trivial constructors +# ifdef BOOST_HAS_TYPE_TRAITS_INTRINSICS - template - struct TAnnotationP - : public AnnotationP - { - Annotation annotation; + BOOST_STATIC_ASSERT(( (boost::has_trivial_constructor::value + && boost::has_trivial_destructor::value) + || Complex )); + +# endif +# endif }; template ::Small> struct GetAnnotation { - static Annotation & get(AnnotationP * & p); + static Annotation & get(AnnotationEntry & e); + static void dump(AnnotationEntry & e, std::ostream & os); }; -/* template struct GetAnnotation { - static Annotation & get(AnnotationP * & p); + static Annotation & get(AnnotationEntry & e); + static void dump(AnnotationEntry & e, std::ostream & os); }; -*/ /** \brief Internal: Packet data storage @@ -148,9 +193,15 @@ namespace detail { void erase(PacketData * self, iterator first, iterator last); void clear(PacketData * self); + void reserve(size_type n); + size_type capacity() const; + // Annotations template Annotation & annotation(); + void dumpAnnotations(std::ostream & os); + template + void dumpAnnotation(std::ostream & os); /** \brief Internal: Keep PacketImpl instance alive @@ -171,7 +222,7 @@ namespace detail { raw_container data_; interpreter_list interpreters_; - typedef std::vector Annotations; + typedef std::vector Annotations; Annotations annotations_; void eraseInterpreters(interpreter_list::iterator b, interpreter_list::iterator e); @@ -182,8 +233,8 @@ namespace detail { ///////////////////////////////hh.e//////////////////////////////////////// #endif -#if !defined(HH_Packets__decls_) && !defined(HH_PacketImpl_i_) -#define HH_PacketImpl_i_ +#if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_PacketImpl_i_) +#define HH_SENF_Packets_PacketImpl_i_ #include "PacketImpl.cci" //#include "PacketImpl.ct" #include "PacketImpl.cti"