// $Id$ // // Copyright (C) 2010 // Fraunhofer Institute for Open Communication Systems (FOKUS) // // 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 // // 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. // // 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 */ #ifndef IH_SENF_senf_Packets_PacketImpl_ #define IH_SENF_senf_Packets_PacketImpl_ 1 // Custom includes #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //-///////////////////////////////////////////////////////////////////////////////////////////////// namespace senf { struct ComplexAnnotation; namespace detail { template struct IsComplexAnnotation : public boost::mpl::or_< boost::is_convertible, boost::mpl::greater< boost::mpl::sizeof_, boost::mpl::int_ > > {}; class AnnotationRegistry : public senf::singleton { public: typedef int key_type; private: struct RegistrationBase { virtual ~RegistrationBase () {}; 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; virtual unsigned v_size() const = 0; }; template struct Registration : public RegistrationBase { void v_dump(std::ostream & os, void * annotation) const { os << * static_cast(annotation); } std::string v_name() const { return prettyName(typeid(Annotation)); } bool v_isComplex() const { return boost::is_convertible::value; } unsigned v_size() const { return sizeof(Annotation); } }; 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_; Registry registry_; // The index is needed to ensure a persistent and reproducible // ordering of the annotations when dumping Index index_; friend class senf::singleton; }; template class AnnotationRegistry::RegistrationProxy { public: RegistrationProxy() { AnnotationRegistry::Entry::key_ = AnnotationRegistry::instance().registerAnnotation(); } }; class AnnotationRegistry::EntryBase { public: 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_type key_; public: // We use this member to force instantiation of proxy_ ... 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_; friend class AnnotationRegistry::RegistrationProxy; }; }} //-///////////////////////////////////////////////////////////////////////////////////////////////// #endif // Local Variables: // mode: c++ // fill-column: 100 // comment-column: 40 // c-file-style: "senf" // indent-tabs-mode: nil // ispell-local-dictionary: "american" // compile-command: "scons -u test" // End: