summaryrefslogtreecommitdiff
path: root/boost/type_index
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2017-09-13 11:08:07 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2017-09-13 11:09:00 +0900
commitb5c87084afaef42b2d058f68091be31988a6a874 (patch)
treeadef9a65870a41181687e11d57fdf98e7629de3c /boost/type_index
parent34bd32e225e2a8a94104489b31c42e5801cc1f4a (diff)
downloadboost-b5c87084afaef42b2d058f68091be31988a6a874.tar.gz
boost-b5c87084afaef42b2d058f68091be31988a6a874.tar.bz2
boost-b5c87084afaef42b2d058f68091be31988a6a874.zip
Imported Upstream version 1.64.0upstream/1.64.0
Change-Id: Id9212edd016dd55f21172c427aa7894d1d24148b Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'boost/type_index')
-rw-r--r--boost/type_index/runtime_cast/register_runtime_class.hpp62
-rw-r--r--boost/type_index/stl_type_index.hpp4
2 files changed, 58 insertions, 8 deletions
diff --git a/boost/type_index/runtime_cast/register_runtime_class.hpp b/boost/type_index/runtime_cast/register_runtime_class.hpp
index 37ce686e32..995007487b 100644
--- a/boost/type_index/runtime_cast/register_runtime_class.hpp
+++ b/boost/type_index/runtime_cast/register_runtime_class.hpp
@@ -10,7 +10,8 @@
#define BOOST_TYPE_INDEX_RUNTIME_CAST_REGISTER_RUNTIME_CLASS_HPP
/// \file register_runtime_class.hpp
-/// \brief Contains the macro BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS
+/// \brief Contains the macros BOOST_TYPE_INDEX_IMPLEMENT_RUNTIME_CAST and
+/// BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS
#include <boost/type_index.hpp>
#include <boost/preprocessor/seq/for_each.hpp>
@@ -29,6 +30,8 @@ inline type_index runtime_class_construct_type_id(T const*) {
} // namespace detail
+}} // namespace boost::typeindex
+
/// @cond
#define BOOST_TYPE_INDEX_CHECK_BASE_(r, data, Base) \
@@ -44,6 +47,11 @@ inline type_index runtime_class_construct_type_id(T const*) {
/// boost::typeindex::runtime_cast to accurately convert between dynamic types of instances of
/// the current class.
///
+/// BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS also adds support for boost::typeindex::type_id_runtime
+/// by including BOOST_TYPE_INDEX_REGISTER_CLASS. It is typical that these features are used together,
+/// but in the event that BOOST_TYPE_INDEX_REGISTER_CLASS is undesirable in the current class,
+/// BOOST_TYPE_INDEX_IMPLEMENT_RUNTIME_CAST is provided.
+///
/// \b Example:
/// \code
/// struct base1 {
@@ -67,22 +75,64 @@ inline type_index runtime_class_construct_type_id(T const*) {
/// ...
///
/// base1* pb1 = get_object();
-/// if(derived2* pb2 = boost::typeindex::runtime_cast<derived2*>(pb1))
-/// { /* ... */ }
+/// if(derived2* pb2 = boost::typeindex::runtime_cast<derived2*>(pb1)) {
+/// assert(boost::typeindex::type_id_runtime(*pb1)) == boost::typeindex::type_id<derived2>());
+/// }
/// \endcode
///
/// \param base_class_seq A Boost.Preprocessor sequence of the current class' direct bases, or
-/// BOOST_PP_SEQ_NIL if this class has no direct base classes.
+/// BOOST_TYPE_INDEX_NO_BASE_CLASS if this class has no direct base classes.
#define BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS(base_class_seq) \
- BOOST_TYPE_INDEX_REGISTER_CLASS \
+ BOOST_TYPE_INDEX_REGISTER_CLASS \
+ BOOST_TYPE_INDEX_IMPLEMENT_RUNTIME_CAST(base_class_seq)
+
+/// \def BOOST_TYPE_INDEX_IMPLEMENT_RUNTIME_CAST
+/// \brief Macro used to make a class compatible with boost::typeindex::runtime_cast without including
+/// support for boost::typeindex::type_id_runtime.
+///
+/// BOOST_TYPE_INDEX_IMPLEMENT_RUNTIME_CAST is provided as an alternative to BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS
+/// in the event that support for boost::typeindex::type_id_runtime is undesirable.
+///
+/// \b Example:
+/// \code
+/// struct base1 {
+/// BOOST_TYPE_INDEX_IMPLEMENT_RUNTIME_CAST(BOOST_TYPE_INDEX_NO_BASE_CLASS)
+/// virtual ~base1();
+/// };
+///
+/// struct base2 {
+/// BOOST_TYPE_INDEX_IMPLEMENT_RUNTIME_CAST(BOOST_TYPE_INDEX_NO_BASE_CLASS)
+/// virtual ~base2();
+/// };
+///
+/// struct derived1 : base1 {
+/// BOOST_TYPE_INDEX_IMPLEMENT_RUNTIME_CAST((base1))
+/// };
+///
+/// struct derived2 : base1, base2 {
+/// BOOST_TYPE_INDEX_IMPLEMENT_RUNTIME_CAST((base1)(base2))
+/// };
+///
+/// ...
+///
+/// base1* pb1 = get_object();
+/// if(derived2* pb2 = boost::typeindex::runtime_cast<derived2*>(pb1))
+/// { /* can't call boost::typeindex::type_id_runtime(*pb1) here */ }
+/// \endcode
+///
+/// \param base_class_seq A Boost.Preprocessor sequence of the current class' direct bases, or
+/// BOOST_TYPE_INDEX_NO_BASE_CLASS if this class has no direct base classes.
+#define BOOST_TYPE_INDEX_IMPLEMENT_RUNTIME_CAST(base_class_seq) \
virtual void const* boost_type_index_find_instance_(boost::typeindex::type_index const& idx) const BOOST_NOEXCEPT { \
if(idx == boost::typeindex::detail::runtime_class_construct_type_id(this)) \
return this; \
BOOST_PP_SEQ_FOR_EACH(BOOST_TYPE_INDEX_CHECK_BASE_, _, base_class_seq) \
return NULL; \
}
-}} // namespace boost::typeindex
+/// \def BOOST_TYPE_INDEX_NO_BASE_CLASS
+/// \brief Instructs BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS and BOOST_TYPE_INDEX_IMPLEMENT_RUNTIME_CAST
+/// that this class has no base classes.
#define BOOST_TYPE_INDEX_NO_BASE_CLASS BOOST_PP_SEQ_NIL
#endif // BOOST_TYPE_INDEX_RUNTIME_CAST_REGISTER_RUNTIME_CLASS_HPP
diff --git a/boost/type_index/stl_type_index.hpp b/boost/type_index/stl_type_index.hpp
index a5add88716..be28889962 100644
--- a/boost/type_index/stl_type_index.hpp
+++ b/boost/type_index/stl_type_index.hpp
@@ -1,5 +1,5 @@
//
-// Copyright (c) Antony Polukhin, 2013-2015.
+// Copyright (c) Antony Polukhin, 2013-2017.
//
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
@@ -174,7 +174,7 @@ inline std::string stl_type_index::pretty_name() const {
inline std::size_t stl_type_index::hash_code() const BOOST_NOEXCEPT {
-#if _MSC_VER > 1600 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5 && defined(__GXX_EXPERIMENTAL_CXX0X__))
+#if (defined(_MSC_VER) && _MSC_VER > 1600) || (__GNUC__ == 4 && __GNUC_MINOR__ > 5 && defined(__GXX_EXPERIMENTAL_CXX0X__))
return data_->hash_code();
#else
return boost::hash_range(raw_name(), raw_name() + std::strlen(raw_name()));