X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FPackets%2FPacketImpl.ih;h=6e3bd7841f8aefae8104b3d867a008d93f3dfe10;hb=refs%2Fheads%2Fmaster;hp=06cb708f70daa970015e03269f1acd8b48e73abe;hpb=943a6b0973f66bc699c6e7b404da256145e93acf;p=senf.git diff --git a/senf/Packets/PacketImpl.ih b/senf/Packets/PacketImpl.ih index 06cb708..6e3bd78 100644 --- a/senf/Packets/PacketImpl.ih +++ b/senf/Packets/PacketImpl.ih @@ -2,23 +2,28 @@ // // Copyright (C) 2010 // 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 -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. +// The contents of this file are subject to the Fraunhofer FOKUS Public License +// Version 1.0 (the "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// http://senf.berlios.de/license.html // -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. +// The Fraunhofer FOKUS Public License Version 1.0 is based on, +// but modifies the Mozilla Public License Version 1.1. +// See the full license text for the amendments. // -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the -// Free Software Foundation, Inc., -// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// Software distributed under the License is distributed on an "AS IS" basis, +// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +// for the specific language governing rights and limitations under the License. +// +// The Original Code is Fraunhofer FOKUS code. +// +// The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. +// (registered association), Hansastraße 27 c, 80686 Munich, Germany. +// All Rights Reserved. +// +// Contributor(s): +// Stefan Bund /** \file \brief PacketImpl internal header */ @@ -28,7 +33,10 @@ // Custom includes #include +#include #include +#include +#include #include #include #include @@ -40,12 +48,11 @@ #include #include -///////////////////////////////ih.p//////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// namespace senf { struct ComplexAnnotation; - void dumpPacketAnnotationRegistry(std::ostream & os); namespace detail { @@ -61,38 +68,13 @@ namespace detail { : public senf::singleton { public: - typedef int key_t; - - using senf::singleton::instance; - - template class RegistrationProxy; - - class EntryBase; - template class Entry; - - template - key_t registerAnnotation(); - - void dump(key_t key, std::ostream & os, void * annotation) const; - std::string name(key_t key) const; - bool isComplex(key_t key) const; - unsigned size(key_t key) const; - - template - static key_t lookup(); - - key_t keyBegin() const; - key_t keyEnd() const; - - void dumpRegistrations(std::ostream & os); + typedef int key_type; private: - AnnotationRegistry(); - struct RegistrationBase { virtual ~RegistrationBase () {}; - key_t key; + key_type key; virtual void v_dump(std::ostream & os, void * annotation) const = 0; virtual std::string v_name() const = 0; virtual bool v_isComplex() const = 0; @@ -113,11 +95,49 @@ namespace detail { { return sizeof(Annotation); } }; - key_t simpleAnnotationCount_; - key_t complexAnnotationCount_; + typedef boost::ptr_map Registry; + // Index must be a multi-map since two identically named classes + // both in the anonymous namespace both have the same demangled name. + // we could sort on the mangled name instead ... + typedef std::multimap Index; + + public: + typedef boost::transform_iterator< ::__gnu_cxx::select2nd, + Index::const_iterator > iterator; + + using senf::singleton::instance; + + template class RegistrationProxy; + + class EntryBase; + template class Entry; + + template + key_type registerAnnotation(); + + void dump(key_type key, std::ostream & os, void * annotation) const; + std::string name(key_type key) const; + bool isComplex(key_type key) const; + unsigned size(key_type key) const; + + template + static key_type lookup(); + + iterator begin() const; + iterator end() const; + + void dumpRegistrations(std::ostream & os); + + private: + AnnotationRegistry(); + + key_type simpleAnnotationCount_; + key_type complexAnnotationCount_; - typedef boost::ptr_map Registry; Registry registry_; + // The index is needed to ensure a persistent and reproducible + // ordering of the annotations when dumping + Index index_; friend class senf::singleton; }; @@ -139,20 +159,29 @@ namespace detail { virtual ~EntryBase() {} virtual void * get() = 0; + + typedef EntryBase * ptr; + virtual ptr clone() const = 0; }; + inline AnnotationRegistry::EntryBase::ptr new_clone( AnnotationRegistry::EntryBase const & entry) + { + return entry.clone(); + } + template class AnnotationRegistry::Entry : public AnnotationRegistry::EntryBase { static RegistrationProxy proxy_; - static AnnotationRegistry::key_t key_; + static AnnotationRegistry::key_type key_; public: // We use this member to force instantiation of proxy_ ... - static AnnotationRegistry::key_t key() + static AnnotationRegistry::key_type key() { senf::IGNORE(&proxy_); return key_; } virtual void * get() { return & annotation_; } + virtual EntryBase::ptr clone() const { return new Entry( *this); } private: Annotation annotation_; @@ -162,7 +191,7 @@ namespace detail { }} -///////////////////////////////ih.e//////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// #endif