From 7ddb306c65d2787b6138db5f1cb4acbab890cb94 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Thu, 20 Feb 2014 16:30:13 +0400 Subject: [PATCH] Some MSVC related updates and docs improvements --- include/boost/type_index.hpp | 20 ++++++--- .../boost/type_index/ctti_register_class.hpp | 7 ++- .../boost/type_index/stl_register_class.hpp | 45 +++++++++++++++++++ include/boost/type_index/stl_type_index.hpp | 3 +- 4 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 include/boost/type_index/stl_register_class.hpp diff --git a/include/boost/type_index.hpp b/include/boost/type_index.hpp index 036fa88..1e4b143 100644 --- a/include/boost/type_index.hpp +++ b/include/boost/type_index.hpp @@ -25,6 +25,9 @@ # include BOOST_TYPE_INDEX_USER_TYPEINDEX #elif (!defined(BOOST_NO_RTTI) && !defined(BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY)) || defined(BOOST_MSVC) # include +# ifdef BOOST_NO_RTTI +# inlcude +# endif #else # include # include @@ -43,7 +46,11 @@ namespace boost { namespace typeind { // Nothing to do #elif (!defined(BOOST_NO_RTTI) && !defined(BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY)) || defined(BOOST_MSVC) typedef boost::typeind::stl_type_index type_index; -# define BOOST_TYPE_INDEX_REGISTER_CLASS +# ifdef BOOST_NO_RTTI +# define BOOST_TYPE_INDEX_REGISTER_CLASS BOOST_TYPE_INDEX_REGISTER_STL_CLASS +# else +# define BOOST_TYPE_INDEX_REGISTER_CLASS +# endif #else typedef boost::typeind::ctti_type_index type_index; # define BOOST_TYPE_INDEX_REGISTER_CLASS BOOST_TYPE_INDEX_REGISTER_CTTI_CLASS @@ -58,10 +65,12 @@ typedef type_index::type_info_t type_info; #if defined(BOOST_TYPE_INDEX_DOXYGEN_INVOKED) -/// \def BOOST_TYPE_INDEX_USER_TYPEINFO -/// BOOST_TYPE_INDEX_USER_TYPEINFO can be defined to the path to header file +/// \def BOOST_TYPE_INDEX_USER_TYPEINDEX +/// BOOST_TYPE_INDEX_USER_TYPEINDEX can be defined to the path to header file /// with user provided implementation of type_index. -#define BOOST_TYPE_INDEX_USER_TYPEINDEX +/// +/// See "Making own type_index" section of documentation for usage example. +#define BOOST_TYPE_INDEX_USER_TYPEINDEX /// \def BOOST_TYPE_INDEX_REGISTER_CLASS @@ -139,8 +148,7 @@ inline type_index type_id_with_cvr() BOOST_NOEXCEPT { /// /// Retunrs runtime information about specified type. /// -/// \b Requirements: RTTI available or specially designed user type_info class must be provided -/// via BOOST_TYPE_INDEX_USER_TYPEINDEX and BOOST_TYPE_INDEX_USER_TYPEINDEX_NAME macro. +/// \b Requirements: RTTI available or Base and Derived classes must be marked with BOOST_TYPE_INDEX_REGISTER_CLASS. /// /// \b Example: /// \code diff --git a/include/boost/type_index/ctti_register_class.hpp b/include/boost/type_index/ctti_register_class.hpp index 7356a7a..d7a4b7c 100644 --- a/include/boost/type_index/ctti_register_class.hpp +++ b/include/boost/type_index/ctti_register_class.hpp @@ -28,7 +28,12 @@ inline const ctti_data& ctti_construct_typeid_ref(const T*) BOOST_NOEXCEPT { }}} // namespace boost::typeind::detail - +/// \def BOOST_TYPE_INDEX_REGISTER_CTTI_CLASS +/// BOOST_TYPE_INDEX_REGISTER_CTTI_CLASS is used by BOOST_TYPE_INDEX_REGISTER_CLASS when RTTI is off +/// and `typeid()` does not work. +/// +/// BOOST_TYPE_INDEX_REGISTER_CTTI_CLASS macro expands to declaration and implementation of +/// `virtual const detail::ctti_data& type_id_runtime() const` method. #define BOOST_TYPE_INDEX_REGISTER_CTTI_CLASS \ virtual const boost::typeind::detail::ctti_data& type_id_runtime() const BOOST_NOEXCEPT { \ return boost::typeind::detail::ctti_construct_typeid_ref(this); \ diff --git a/include/boost/type_index/stl_register_class.hpp b/include/boost/type_index/stl_register_class.hpp new file mode 100644 index 0000000..e26a347 --- /dev/null +++ b/include/boost/type_index/stl_register_class.hpp @@ -0,0 +1,45 @@ +// +// Copyright (c) Antony Polukhin, 2013-2014. +// +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef BOOST_TYPE_INDEX_STL_REGISTER_CLASS_HPP +#define BOOST_TYPE_INDEX_STL_REGISTER_CLASS_HPP + +// MS compatible compilers support #pragma once +#if defined(_MSC_VER) +# pragma once +#endif + +/// \file stl_register_class.hpp +/// \brief Contains BOOST_TYPE_INDEX_REGISTER_STL_CLASS macro. + +#include + +namespace boost { namespace typeind { namespace detail { + +template +inline const stl_type_index::type_info_t& stl_construct_typeid_ref(const T*) BOOST_NOEXCEPT { + return typeid(T); +} + +}}} // namespace boost::typeind::detail + + +/// \def BOOST_TYPE_INDEX_REGISTER_STL_CLASS +/// BOOST_TYPE_INDEX_REGISTER_STL_CLASS is used by BOOST_TYPE_INDEX_REGISTER_CLASS when RTTI is off +/// and `typeid()` does work. +/// +/// BOOST_TYPE_INDEX_REGISTER_STL_CLASS macro expands to declaration and implementation of +/// `virtual const std::type_info& type_id_runtime() const` method. +#define BOOST_TYPE_INDEX_REGISTER_STL_CLASS \ + virtual const boost::typeind::stl_type_index::type_info_t& type_id_runtime() const BOOST_NOEXCEPT { \ + return boost::typeind::detail::stl_construct_typeid_ref(this); \ + } \ +/**/ + +#endif // BOOST_TYPE_INDEX_STL_REGISTER_CLASS_HPP + diff --git a/include/boost/type_index/stl_type_index.hpp b/include/boost/type_index/stl_type_index.hpp index 26e99e7..eabe366 100644 --- a/include/boost/type_index/stl_type_index.hpp +++ b/include/boost/type_index/stl_type_index.hpp @@ -249,8 +249,7 @@ inline stl_type_index stl_type_index::type_id_with_cvr() BOOST_NOEXCEPT { template inline stl_type_index stl_type_index::type_id_runtime(const T& value) BOOST_NOEXCEPT { #ifdef BOOST_NO_RTTI - BOOST_STATIC_ASSERT_MSG(sizeof(T) && false, - "stl_type_index::type_id_runtime(const T&) require RTTI"); + return value.type_id_runtime(); #endif return typeid(value); }