Packets: Add ComplexAnnotation check for current (4.3) g++ Versions using boost:...
g0dil [Tue, 4 Nov 2008 13:23:04 +0000 (13:23 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@944 270642c3-0616-0410-b53a-bc976706d245

Packets/Packet.test.cc
Packets/PacketImpl.hh

index 8c28f73..dd8d173 100644 (file)
@@ -28,6 +28,7 @@
 
 // Custom includes
 #include <sstream>
+#include <boost/static_assert.hpp>
 #include "Packets.hh"
 
 #include "../Utils/auto_unit_test.hh"
@@ -126,6 +127,11 @@ namespace {
     struct ComplexEmptyAnnotation : senf::ComplexAnnotation
     {};
 
+    struct InvalidAnnotation
+    {
+        std::string value;
+    };
+
 }
 
 BOOST_AUTO_UNIT_TEST(packet)
@@ -273,6 +279,24 @@ BOOST_AUTO_UNIT_TEST(packetAnnotation)
     BOOST_CHECK( ! senf::detail::AnnotationIndexer<ComplexEmptyAnnotation>::Small );
 }
 
+#ifdef COMPILE_CHECK
+
+COMPILE_FAIL(invalidAnnotation)
+{
+#   ifdef BOOST_HAS_TYPE_TRAITS_INTRINSICS
+
+    senf::Packet packet (FooPacket::create());
+    (void) packet.annotation<InvalidAnnotation>();
+
+#   else
+
+    BOOST_STATIC_ASSERT(( false ));
+
+#   endif
+}
+
+#endif
+
 ///////////////////////////////cc.e////////////////////////////////////////
 #undef prefix_
 
index 4aa2d8c..4b13fdd 100644 (file)
@@ -31,6 +31,7 @@
 #include <vector>
 #include <boost/utility.hpp>
 #include <boost/type_traits/is_base_of.hpp>
+#include <boost/static_assert.hpp>
 #include "../Utils/pool_alloc_mixin.hh"
 #include "PacketTypes.hh"
 #include "../Utils/singleton.hh"
@@ -91,8 +92,14 @@ namespace detail {
         AnnotationIndexer();
         unsigned index_;
         static unsigned index();
-        static bool const Small = (sizeof(Annotation) <= sizeof(AnnotationEntry) 
-                                   && ! boost::is_base_of<ComplexAnnotation, Annotation>::value);
+        static bool const Complex = boost::is_base_of<ComplexAnnotation, Annotation>::value;
+        static bool const Small = (sizeof(Annotation) <= sizeof(AnnotationEntry) && ! Complex);
+
+#       ifdef BOOST_HAS_TYPE_TRAITS_INTRINSICS
+
+        BOOST_STATIC_ASSERT(( boost::is_pod<Annotation>::value || Complex ));
+
+#       endif
     };
 
     template <class Annotation, bool Small = AnnotationIndexer<Annotation>::Small>