X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FPacketImpl.hh;h=32ae5a17a0b79eda12fde332d4fe72c231f22bed;hb=fd3a0e8ac95d1158e9ea661ddf9187b67c70169f;hp=5ec43f6ce60ccc1bff2e7575d7d61a6384d21d09;hpb=d084c02e4914da4fa1a4098a33d704f69e8bdedd;p=senf.git diff --git a/Packets/PacketImpl.hh b/Packets/PacketImpl.hh index 5ec43f6..32ae5a1 100644 --- a/Packets/PacketImpl.hh +++ b/Packets/PacketImpl.hh @@ -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 // // This program is free software; you can redistribute it and/or modify @@ -21,23 +23,105 @@ /** \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 +#include #include -#include "Utils/pool_alloc_mixin.hh" +#include +#include +#include +#include +#include "../Utils/pool_alloc_mixin.hh" #include "PacketTypes.hh" +#include "../Utils/singleton.hh" //#include "PacketImpl.mpp" ///////////////////////////////hh.p//////////////////////////////////////// namespace senf { + + /** \brief Marker base-class for complex annotations + + This class is used as a base class to mark an annotation type as complex. A complex + annotation will have it's constructor/destructor called. Non-complex annotations will not + have their constructor called, they will be zero initialized. The destructor of non-complex + annotations is never called. + + An annotation must be marked as complex if it is not POD. Simplified, an + annotation must be marked as ComplexAnnotation, if + + \li it has a (user defined) constructor or destructor + \li it has any data members which have (user defined) constructors or destructors + + \see \ref packet_usage_annotation + */ + struct ComplexAnnotation {}; + namespace detail { - + + struct AnnotationP + { + virtual ~AnnotationP(); + }; + + template + struct TAnnotationP + : public AnnotationP + { + Annotation annotation; + }; + + union AnnotationEntry { + AnnotationP * p; + unsigned long long i; + }; + + struct AnnotationIndexerBase + { + static unsigned maxAnnotations; + static std::vector & small(); + }; + + template + struct AnnotationIndexer + : public senf::singleton< AnnotationIndexer >, + public AnnotationIndexerBase + { + AnnotationIndexer(); + unsigned index_; + static unsigned index(); + static bool const Complex = boost::is_base_of::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::has_trivial_constructor::value + && boost::has_trivial_destructor::value) + || Complex )); + +# endif +# endif + }; + + template ::Small> + struct GetAnnotation + { + static Annotation & get(AnnotationEntry & e); + }; + + template + struct GetAnnotation + { + 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 @@ -45,7 +129,7 @@ namespace detail { 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 { @@ -68,7 +152,7 @@ namespace detail { ~PacketImpl(); // rerference/memory management - + void add_ref(refcount_t n=1); void release(refcount_t n=1); refcount_t refcount() const; @@ -101,6 +185,13 @@ 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 + Annotation & annotation(); + /** \brief Internal: Keep PacketImpl instance alive \internal @@ -119,17 +210,20 @@ namespace detail { refcount_t refcount_; raw_container data_; interpreter_list interpreters_; + + typedef std::vector 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_) -#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"