// $Id$ // // 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. // // 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. // // 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. /** \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: