Utils/Console: Add ValueRange utility
[senf.git] / Packets / PacketImpl.cti
index 21956f1..e3ec1ea 100644 (file)
@@ -38,6 +38,21 @@ prefix_ senf::detail::AnnotationIndexer<Annotation>::AnnotationIndexer()
     : index_ (maxAnnotations++)
 {
     small().push_back(Small);
+    registry().push_back(this);
+}
+
+///////////////////////////////////////////////////////////////////////////
+// senf::detail::AnnotationIndexer<Annotation>
+
+
+template <class Annotation>
+prefix_ void senf::detail::AnnotationIndexer<Annotation>::v_dump(PacketImpl * p,
+                                                                 std::ostream & os)
+{
+
+    os << "  " << senf::prettyName(typeid(Annotation)) << ": ";
+    p->dumpAnnotation<Annotation>(os);
+    os << "\n";
 }
 
 template <class Annotation>
@@ -50,20 +65,33 @@ prefix_ unsigned senf::detail::AnnotationIndexer<Annotation>::index()
 // senf::detail::GetAnnotation<Annotation,Small>
 
 template <class Annotation, bool Small>
-prefix_ Annotation & senf::detail::GetAnnotation<Annotation,Small>::get(AnnotationP * & p)
+prefix_ Annotation & senf::detail::GetAnnotation<Annotation,Small>::get(AnnotationEntry & e)
 {
-    if (!p)
-        p = new TAnnotationP<Annotation>();
-    return static_cast< TAnnotationP<Annotation>* >(p)->annotation;
+    if (!e.p)
+        e.p = new TAnnotationP<Annotation>();
+    return static_cast< TAnnotationP<Annotation>* >(e.p)->annotation;
+}
+
+template <class Annotation, bool Small>
+prefix_ void senf::detail::GetAnnotation<Annotation,Small>::dump(AnnotationEntry & e,
+                                                                 std::ostream & os)
+{
+    if (!e.p) os << "no value";
+    else      os << get(e);
+}
+
+template <class Annotation>
+prefix_ Annotation & senf::detail::GetAnnotation<Annotation, true>::get(AnnotationEntry & e)
+{
+    return * static_cast<Annotation*>(static_cast<void*>(& e.i));
 }
 
-/*
 template <class Annotation>
-prefix_ Annotation & senf::detail::GetAnnotation<Annotation, true>::get(AnnotationP * & p)
+prefix_ void senf::detail::GetAnnotation<Annotation, true>::dump(AnnotationEntry & e,
+                                                                 std::ostream & os)
 {
-    return * reinterpret_cast<Annotation*>(p);
+    os << get(e);
 }
-*/
 
 ///////////////////////////////////////////////////////////////////////////
 // senf::detail::PacketImpl
@@ -81,7 +109,7 @@ prefix_ void senf::detail::PacketImpl::insert(PacketData * self, iterator pos, F
 
 template <class InputIterator>
 prefix_ senf::detail::PacketImpl::PacketImpl(InputIterator first, InputIterator last)
-    : refcount_(0), data_(first,last), annotations_(AnnotationIndexerBase::maxAnnotations, 0)
+    : refcount_(0), data_(first,last), annotations_(AnnotationIndexerBase::maxAnnotations)
 {}
 
 // Annotations
@@ -93,6 +121,13 @@ prefix_ Annotation & senf::detail::PacketImpl::annotation()
         annotations_[AnnotationIndexer<Annotation>::index()]);
 }
 
+template <class Annotation>
+prefix_ void senf::detail::PacketImpl::dumpAnnotation(std::ostream & os)
+{
+    GetAnnotation<Annotation>::dump(
+        annotations_[AnnotationIndexer<Annotation>::index()], os);
+}
+
 ///////////////////////////////cti.e///////////////////////////////////////
 #undef prefix_