From de0d90eca134a1ab98cc9eebc56588c03eaaac9f Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Sun, 9 Feb 2014 14:16:36 +0400 Subject: [PATCH] More functionality moved to type_index_facade and better documentation for facade. --- include/boost/type_index/ctti_type_index.hpp | 20 ------- .../boost/type_index/type_index_facade.hpp | 55 +++++++++++-------- 2 files changed, 33 insertions(+), 42 deletions(-) diff --git a/include/boost/type_index/ctti_type_index.hpp b/include/boost/type_index/ctti_type_index.hpp index b880a7e..41a2fbb 100644 --- a/include/boost/type_index/ctti_type_index.hpp +++ b/include/boost/type_index/ctti_type_index.hpp @@ -30,7 +30,6 @@ #include #include #include -#include namespace boost { namespace typeind { @@ -60,14 +59,9 @@ public: {} inline const type_info_t& type_info() const BOOST_NOEXCEPT; - inline const char* raw_name() const BOOST_NOEXCEPT; - inline const char* name() const BOOST_NOEXCEPT; inline std::string pretty_name() const; - inline std::size_t hash_code() const BOOST_NOEXCEPT; - inline bool equal(const ctti_type_index& rhs) const BOOST_NOEXCEPT; - inline bool before(const ctti_type_index& rhs) const BOOST_NOEXCEPT; template inline static ctti_type_index construct() BOOST_NOEXCEPT; @@ -120,10 +114,6 @@ inline const char* ctti_type_index::raw_name() const BOOST_NOEXCEPT { } -inline const char* ctti_type_index::name() const BOOST_NOEXCEPT { - return data_->typename_; -} - inline std::string ctti_type_index::pretty_name() const { std::size_t len = std::strlen(raw_name() + detail::ctti_skip_size_at_end); while (raw_name()[len - 1] == ' ') --len; // MSVC sometimes adds whitespaces @@ -131,16 +121,6 @@ inline std::string ctti_type_index::pretty_name() const { } -inline bool ctti_type_index::equal(const ctti_type_index& rhs) const BOOST_NOEXCEPT { - return raw_name() == rhs.raw_name() || !std::strcmp(raw_name(), rhs.raw_name()); -} - - -inline bool ctti_type_index::before(const ctti_type_index& rhs) const BOOST_NOEXCEPT { - return raw_name() != rhs.raw_name() && std::strcmp(raw_name(), rhs.raw_name()) < 0; -} - - inline std::size_t ctti_type_index::hash_code() const BOOST_NOEXCEPT { return boost::hash_range(raw_name(), raw_name() + std::strlen(raw_name() + detail::ctti_skip_size_at_end)); } diff --git a/include/boost/type_index/type_index_facade.hpp b/include/boost/type_index/type_index_facade.hpp index 8d793fe..60fb384 100644 --- a/include/boost/type_index/type_index_facade.hpp +++ b/include/boost/type_index/type_index_facade.hpp @@ -15,7 +15,9 @@ #endif #include +#include #include +#include #if !defined(BOOST_NO_IOSTREAM) #if !defined(BOOST_NO_IOSFWD) @@ -56,56 +58,65 @@ template class type_index_facade { private: /// @cond - Derived& derived() BOOST_NOEXCEPT { - return *static_cast(this); - } - const Derived & derived() const BOOST_NOEXCEPT { return *static_cast(this); } /// @endcond public: typedef TypeInfo type_info_t; - typedef type_index_facade this_type; - const type_info_t& type_info() const BOOST_NOEXCEPT { + /// \b Override: This function \b must be redefined in Derived class. Overrides \b must not throw. + /// \return Const reference to underlying low level type_info_t. + inline const type_info_t& type_info() const BOOST_NOEXCEPT { return derived().type_info(); } + /// \b Override: This function \b must be redefined in Derived class. Overrides \b must not throw. + /// \return Pointer to unredable/raw type name. inline const char* raw_name() const BOOST_NOEXCEPT { return derived().raw_name(); } - inline const char* name() const BOOST_NOEXCEPT { - return derived().name(); - } - + /// \b Override: This function \b must be redefined in Derived class. Overrides may throw. + /// \return Human redable type name. inline std::string pretty_name() const { return derived().pretty_name(); } + /// \b Override: This function \b may be redefined in Derived class. Overrides \b must not throw. + /// \return Name of a type. By default retuns raw_name(). + inline const char* name() const BOOST_NOEXCEPT { + return raw_name(); + } + + /// \b Override: This function \b may be redefined in Derived class. Overrides \b must not throw. + /// \return True if two types are equal. By default compares types by raw_name(). + inline bool equal(const Derived& rhs) const BOOST_NOEXCEPT { + return raw_name() == rhs.raw_name() || !std::strcmp(raw_name(), rhs.raw_name()); + } + + /// \b Override: This function \b may be redefined in Derived class. Overrides \b must not throw. + /// \return True if rhs is greater than this. By default compares types by raw_name(). + inline bool before(const Derived& rhs) const BOOST_NOEXCEPT { + return raw_name() != rhs.raw_name() && std::strcmp(raw_name(), rhs.raw_name()) < 0; + } + + /// \b Override: This function \b may be redefined in Derived class. Overrides \b must not throw. + /// \return Hash code of a type. By default hashes types by raw_name(). inline std::size_t hash_code() const BOOST_NOEXCEPT { - return derived().hash_code(); - } - - inline bool equal(const this_type& rhs) const BOOST_NOEXCEPT { - return derived().equal(rhs.derived()); - } - - inline bool before(const this_type& rhs) const BOOST_NOEXCEPT { - return derived().before(rhs.derived()); + return boost::hash_range(raw_name(), raw_name() + std::strlen(raw_name())); } }; /// @cond template inline bool operator == (const type_index_facade& lhs, const type_index_facade& rhs) BOOST_NOEXCEPT { - return lhs.equal(rhs); + return static_cast(lhs).equal(static_cast(rhs)); } template inline bool operator < (const type_index_facade& lhs, const type_index_facade& rhs) BOOST_NOEXCEPT { - return lhs.before(rhs); + return static_cast(lhs).before(static_cast(rhs));; } @@ -235,7 +246,7 @@ inline std::basic_ostream& operator<<( /// This free function is used by Boost's unordered containers. template inline std::size_t hash_value(const type_index_facade& lhs) BOOST_NOEXCEPT { - return lhs.hash_code(); + return static_cast(lhs).hash_code(); } }} // namespace boost::typeind