-// 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
// Custom includes
#include <memory>
+#include <vector>
#include <boost/utility.hpp>
-#include "Utils/pool_alloc_mixin.hh"
+#include <boost/type_traits/is_base_of.hpp>
+#include "../Utils/pool_alloc_mixin.hh"
#include "PacketTypes.hh"
+#include "../Utils/singleton.hh"
//#include "PacketImpl.mpp"
///////////////////////////////hh.p////////////////////////////////////////
namespace senf {
+
+ struct ComplexAnnotation {};
+
namespace detail {
-
+
+ struct AnnotationP
+ {
+ virtual ~AnnotationP();
+ };
+
+ template <class Annotation>
+ struct TAnnotationP
+ : public AnnotationP
+ {
+ Annotation annotation;
+ };
+
+ union AnnotationEntry {
+ AnnotationP * p;
+ unsigned long long i;
+ };
+
+ struct AnnotationIndexerBase
+ {
+ static unsigned maxAnnotations;
+ static std::vector<bool> & small();
+ };
+
+ template <class Annotation>
+ struct AnnotationIndexer
+ : public senf::singleton< AnnotationIndexer<Annotation> >,
+ public AnnotationIndexerBase
+ {
+ AnnotationIndexer();
+ unsigned index_;
+ static unsigned index();
+ static bool const Small = (sizeof(Annotation) <= sizeof(AnnotationEntry)
+ && ! boost::is_base_of<ComplexAnnotation, Annotation>::value);
+ };
+
+ template <class Annotation, bool Small = AnnotationIndexer<Annotation>::Small>
+ struct GetAnnotation
+ {
+ static Annotation & get(AnnotationEntry & e);
+ };
+
+ template <class Annotation>
+ struct GetAnnotation<Annotation, true>
+ {
+ static Annotation & get(AnnotationEntry & e);
+ };
+
/** \brief Internal: Packet data storage
-
+
\internal
This is the class holding the packet data and the interpreter chain. All manipulations of
PacketImpl will update the interpreters (that is the vector indices stored therein) whenever
the data is changed.
*/
- class PacketImpl
+ class PacketImpl
: boost::noncopyable,
public pool_alloc_mixin<PacketImpl>
{
~PacketImpl();
// rerference/memory management
-
+
void add_ref(refcount_t n=1);
void release(refcount_t n=1);
refcount_t refcount() const;
void erase(PacketData * self, iterator first, iterator last);
void clear(PacketData * self);
+ // Annotations
+ template <class Annotation>
+ Annotation & annotation();
+
/** \brief Internal: Keep PacketImpl instance alive
\internal
refcount_t refcount_;
raw_container data_;
interpreter_list interpreters_;
+
+ typedef std::vector<AnnotationEntry> Annotations;
+ Annotations annotations_;
void eraseInterpreters(interpreter_list::iterator b, interpreter_list::iterator e);
- void updateIterators(PacketData * self, iterator pos, difference_type n);
+ void updateIterators(PacketData * self, difference_type pos, difference_type n);
};
}}
///////////////////////////////hh.e////////////////////////////////////////
#endif
-#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_PacketImpl_i_)
+#if !defined(HH_Packets__decls_) && !defined(HH_PacketImpl_i_)
#define HH_PacketImpl_i_
#include "PacketImpl.cci"
//#include "PacketImpl.ct"