Utils/Daemon: Add warning when the scheduler has registered events at a fork()
[senf.git] / Packets / PacketImpl.cti
index aae7612..21956f1 100644 (file)
@@ -1,6 +1,8 @@
-// Copyright (C) 2007 
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
+// $Id$
+//
+// Copyright (C) 2007
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
 //     Stefan Bund <g0dil@berlios.de>
 //
 // This program is free software; you can redistribute it and/or modify
 ///////////////////////////////cti.p///////////////////////////////////////
 
 ///////////////////////////////////////////////////////////////////////////
+// senf::detail::AnnotationIndexer<Annotation>
+
+template <class Annotation>
+prefix_ senf::detail::AnnotationIndexer<Annotation>::AnnotationIndexer()
+    : index_ (maxAnnotations++)
+{
+    small().push_back(Small);
+}
+
+template <class Annotation>
+prefix_ unsigned senf::detail::AnnotationIndexer<Annotation>::index()
+{
+    return AnnotationIndexer::instance().index_;
+}
+
+///////////////////////////////////////////////////////////////////////////
+// senf::detail::GetAnnotation<Annotation,Small>
+
+template <class Annotation, bool Small>
+prefix_ Annotation & senf::detail::GetAnnotation<Annotation,Small>::get(AnnotationP * & p)
+{
+    if (!p)
+        p = new TAnnotationP<Annotation>();
+    return static_cast< TAnnotationP<Annotation>* >(p)->annotation;
+}
+
+/*
+template <class Annotation>
+prefix_ Annotation & senf::detail::GetAnnotation<Annotation, true>::get(AnnotationP * & p)
+{
+    return * reinterpret_cast<Annotation*>(p);
+}
+*/
+
+///////////////////////////////////////////////////////////////////////////
 // senf::detail::PacketImpl
 
 // Data container
@@ -37,15 +74,25 @@ template <class ForwardIterator>
 prefix_ void senf::detail::PacketImpl::insert(PacketData * self, iterator pos, ForwardIterator f,
                                               ForwardIterator l)
 {
+    difference_type ix (std::distance(begin(),pos));
     data_.insert(pos,f,l);
-    updateIterators(self,pos,std::distance(f,l));
+    updateIterators(self,ix,std::distance(f,l));
 }
 
 template <class InputIterator>
 prefix_ senf::detail::PacketImpl::PacketImpl(InputIterator first, InputIterator last)
-    : refcount_(0), data_(first,last)
+    : refcount_(0), data_(first,last), annotations_(AnnotationIndexerBase::maxAnnotations, 0)
 {}
 
+// Annotations
+
+template <class Annotation>
+prefix_ Annotation & senf::detail::PacketImpl::annotation()
+{
+    return GetAnnotation<Annotation>::get(
+        annotations_[AnnotationIndexer<Annotation>::index()]);
+}
+
 ///////////////////////////////cti.e///////////////////////////////////////
 #undef prefix_
 
@@ -56,4 +103,6 @@ prefix_ senf::detail::PacketImpl::PacketImpl(InputIterator first, InputIterator
 // c-file-style: "senf"
 // indent-tabs-mode: nil
 // ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
 // End: