X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FPackets%2FPacketImpl.ih;h=619859fecc17c278621e272da42eefdbc484a06c;hb=57daeae6f2e924ce3f16f9677c3474f531cba9e5;hp=06cb708f70daa970015e03269f1acd8b48e73abe;hpb=943a6b0973f66bc699c6e7b404da256145e93acf;p=senf.git diff --git a/senf/Packets/PacketImpl.ih b/senf/Packets/PacketImpl.ih index 06cb708..619859f 100644 --- a/senf/Packets/PacketImpl.ih +++ b/senf/Packets/PacketImpl.ih @@ -28,7 +28,10 @@ // Custom includes #include +#include #include +#include +#include #include #include #include @@ -40,12 +43,11 @@ #include #include -///////////////////////////////ih.p//////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// namespace senf { struct ComplexAnnotation; - void dumpPacketAnnotationRegistry(std::ostream & os); namespace detail { @@ -61,38 +63,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 +90,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 +154,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 +186,7 @@ namespace detail { }} -///////////////////////////////ih.e//////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// #endif