PPI: BUGFIX: Duplicate connector registration
[senf.git] / Packets / PacketImpl.hh
index 4b13fdd..0ad1e77 100644 (file)
 /** \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 <memory>
 #include <vector>
 #include <boost/utility.hpp>
 #include <boost/type_traits/is_base_of.hpp>
+#include <boost/type_traits/has_trivial_constructor.hpp>
+#include <boost/type_traits/has_trivial_destructor.hpp>
 #include <boost/static_assert.hpp>
 #include "../Utils/pool_alloc_mixin.hh"
 #include "PacketTypes.hh"
@@ -80,8 +82,13 @@ namespace detail {
 
     struct AnnotationIndexerBase
     {
+        virtual ~AnnotationIndexerBase();
+        virtual void v_dump(PacketImpl * p, std::ostream & os) = 0;
+
         static unsigned maxAnnotations;
         static std::vector<bool> & small();
+        static std::vector<AnnotationIndexerBase*> & registry();
+        static void dump(PacketImpl * p, std::ostream & os);
     };
 
     template <class Annotation>
@@ -90,28 +97,35 @@ namespace detail {
           public AnnotationIndexerBase
     {
         AnnotationIndexer();
+        virtual void v_dump(PacketImpl * p, std::ostream & os);
         unsigned index_;
         static unsigned index();
         static bool const Complex = boost::is_base_of<ComplexAnnotation, Annotation>::value;
         static bool const Small = (sizeof(Annotation) <= sizeof(AnnotationEntry) && ! Complex);
 
+#       if 0 // The test is difficult since it does not work with user-defined trivial constructors
 #       ifdef BOOST_HAS_TYPE_TRAITS_INTRINSICS
 
-        BOOST_STATIC_ASSERT(( boost::is_pod<Annotation>::value || Complex ));
+        BOOST_STATIC_ASSERT(( (boost::has_trivial_constructor<Annotation>::value 
+                               && boost::has_trivial_destructor<Annotation>::value)
+                              || Complex ));
 
 #       endif
+#       endif
     };
 
     template <class Annotation, bool Small = AnnotationIndexer<Annotation>::Small>
     struct GetAnnotation
     {
         static Annotation & get(AnnotationEntry & e);
+        static void dump(AnnotationEntry & e, std::ostream & os);
     };
 
     template <class Annotation>
     struct GetAnnotation<Annotation, true>
     {
         static Annotation & get(AnnotationEntry & e);
+        static void dump(AnnotationEntry & e, std::ostream & os);
     };
 
     /** \brief Internal: Packet data storage
@@ -179,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 <class Annotation>
         Annotation & annotation();
+        void dumpAnnotations(std::ostream & os);
+        template <class Annotation>
+        void dumpAnnotation(std::ostream & os);
 
         /** \brief Internal: Keep PacketImpl instance alive
 
@@ -213,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"