diff --git a/doc/type_index.qbk b/doc/type_index.qbk index d985c21..539fc83 100644 --- a/doc/type_index.qbk +++ b/doc/type_index.qbk @@ -246,7 +246,7 @@ Depending on the `typeid()` availability TypeIndex library will choose an optima [macroref BOOST_TYPE_INDEX_REGISTER_CLASS] macro is a helper macro that places some virtual helper functions or expands to nothing. -[macroref BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS] macro is a helper macro that places the same +[macroref BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS] macro is a helper macro that places the same helpers as BOOST_TYPE_INDEX_REGISTER_CLASS plus some additional helpers for boost::typeindex::runtime_cast to function. diff --git a/examples/runtime_cast.cpp b/examples/runtime_cast.cpp index 73125b6..43e7aa7 100644 --- a/examples/runtime_cast.cpp +++ b/examples/runtime_cast.cpp @@ -29,11 +29,11 @@ struct B { {} }; -struct C : A { - BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS((A)) +struct C : A { + BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS((A)) }; -struct D : B { +struct D : B { BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS((B)) }; @@ -46,7 +46,7 @@ int main() { A* a = &c; if(C* cp = boost::typeindex::runtime_cast(a)) { - std::cout << "Yes, a points to a C: " + std::cout << "Yes, a points to a C: " << a << "->" << cp << '\n'; } else { @@ -54,7 +54,7 @@ int main() { } if(E* ce = boost::typeindex::runtime_cast(a)) { - std::cout << "Error: Expected a to not points to an E: " + std::cout << "Error: Expected a to not points to an E: " << a << "->" << ce << '\n'; } else { @@ -64,7 +64,7 @@ int main() { E e; C* cp2 = &e; if(D* dp = boost::typeindex::runtime_cast(cp2)) { - std::cout << "Yes, we can cross-cast from a C* to a D* when we actually have an E: " + std::cout << "Yes, we can cross-cast from a C* to a D* when we actually have an E: " << cp2 << "->" << dp << '\n'; } else { diff --git a/include/boost/type_index/runtime_cast.hpp b/include/boost/type_index/runtime_cast.hpp index 692cd1b..c72b119 100644 --- a/include/boost/type_index/runtime_cast.hpp +++ b/include/boost/type_index/runtime_cast.hpp @@ -25,4 +25,4 @@ # pragma once #endif -#endif // BOOST_TYPE_INDEX_RUNTIME_CAST_HPP \ No newline at end of file +#endif // BOOST_TYPE_INDEX_RUNTIME_CAST_HPP diff --git a/include/boost/type_index/runtime_cast/boost_shared_ptr_cast.hpp b/include/boost/type_index/runtime_cast/boost_shared_ptr_cast.hpp index cdde1fb..e31f19d 100644 --- a/include/boost/type_index/runtime_cast/boost_shared_ptr_cast.hpp +++ b/include/boost/type_index/runtime_cast/boost_shared_ptr_cast.hpp @@ -23,15 +23,15 @@ namespace boost { namespace typeindex { -/// \brief Creates a new instance of std::shared_ptr whose stored pointer is obtained from u's +/// \brief Creates a new instance of std::shared_ptr whose stored pointer is obtained from u's /// stored pointer using a runtime_cast. /// -/// The new shared_ptr will share ownership with u, except that it is empty if the runtime_cast +/// The new shared_ptr will share ownership with u, except that it is empty if the runtime_cast /// performed by runtime_pointer_cast returns a null pointer. /// \tparam T The desired target type to return a pointer of. /// \tparam U A complete class type of the source instance pointed to from u. -/// \return If there exists a valid conversion from U* to T*, returns a boost::shared_ptr -/// that points to an address suitably offset from u. +/// \return If there exists a valid conversion from U* to T*, returns a boost::shared_ptr +/// that points to an address suitably offset from u. /// If no such conversion exists, returns boost::shared_ptr(); template boost::shared_ptr runtime_pointer_cast(boost::shared_ptr const& u) { @@ -39,8 +39,8 @@ boost::shared_ptr runtime_pointer_cast(boost::shared_ptr const& u) { if(value) return boost::shared_ptr(u, value); return boost::shared_ptr(); -} +} }} // namespace boost::typeindex -#endif // BOOST_TYPE_INDEX_RUNTIME_CAST_BOOST_SHARED_PTR_CAST_HPP \ No newline at end of file +#endif // BOOST_TYPE_INDEX_RUNTIME_CAST_BOOST_SHARED_PTR_CAST_HPP diff --git a/include/boost/type_index/runtime_cast/detail/runtime_cast_impl.hpp b/include/boost/type_index/runtime_cast/detail/runtime_cast_impl.hpp index 32bfffe..8164eda 100644 --- a/include/boost/type_index/runtime_cast/detail/runtime_cast_impl.hpp +++ b/include/boost/type_index/runtime_cast/detail/runtime_cast_impl.hpp @@ -31,7 +31,7 @@ namespace detail { template T* runtime_cast_impl(U* u, boost::true_type) BOOST_NOEXCEPT { return u; -} +} template T const* runtime_cast_impl(U const* u, boost::true_type) BOOST_NOEXCEPT { @@ -43,7 +43,7 @@ T* runtime_cast_impl(U* u, boost::false_type) BOOST_NOEXCEPT { return const_cast(static_cast( u->boost_type_index_find_instance_(boost::typeindex::type_id()) )); -} +} template T const* runtime_cast_impl(U const* u, boost::false_type) BOOST_NOEXCEPT { @@ -54,4 +54,4 @@ T const* runtime_cast_impl(U const* u, boost::false_type) BOOST_NOEXCEPT { }} // namespace boost::typeindex -#endif // BOOST_TYPE_INDEX_RUNTIME_CAST_DETAIL_RUNTIME_CAST_IMPL_HPP \ No newline at end of file +#endif // BOOST_TYPE_INDEX_RUNTIME_CAST_DETAIL_RUNTIME_CAST_IMPL_HPP diff --git a/include/boost/type_index/runtime_cast/pointer_cast.hpp b/include/boost/type_index/runtime_cast/pointer_cast.hpp index 8f6c3d4..49a7613 100644 --- a/include/boost/type_index/runtime_cast/pointer_cast.hpp +++ b/include/boost/type_index/runtime_cast/pointer_cast.hpp @@ -32,7 +32,7 @@ template T runtime_cast(U* u) BOOST_NOEXCEPT { typedef typename boost::remove_pointer::type impl_type; return detail::runtime_cast_impl(u, boost::is_base_and_derived()); -} +} /// \brief Safely converts pointers to classes up, down, and sideways along the inheritance hierarchy. /// \tparam T The desired target type. Like dynamic_cast, must be a pointer to complete class type. @@ -45,24 +45,24 @@ T runtime_cast(U const* u) BOOST_NOEXCEPT { return detail::runtime_cast_impl(u, boost::is_base_and_derived()); } -/// \brief Safely converts pointers to classes up, down, and sideways along the inheritance +/// \brief Safely converts pointers to classes up, down, and sideways along the inheritance /// hierarchy. /// \tparam T The desired target type to return a pointer to. /// \tparam U A complete class type of the source instance, u. -/// \return If there exists a valid conversion from U const* to T*, returns a T* -/// that points to an address suitably offset from u. +/// \return If there exists a valid conversion from U const* to T*, returns a T* +/// that points to an address suitably offset from u. /// If no such conversion exists, returns NULL. template T* runtime_pointer_cast(U* u) BOOST_NOEXCEPT { return detail::runtime_cast_impl(u, boost::is_base_and_derived()); -} +} -/// \brief Safely converts pointers to classes up, down, and sideways along the inheritance +/// \brief Safely converts pointers to classes up, down, and sideways along the inheritance /// hierarchy. /// \tparam T The desired target type to return a pointer to. /// \tparam U A complete class type of the source instance, u. -/// \return If there exists a valid conversion from U const* to T const*, returns a T const* -/// that points to an address suitably offset from u. +/// \return If there exists a valid conversion from U const* to T const*, returns a T const* +/// that points to an address suitably offset from u. /// If no such conversion exists, returns NULL. template T const* runtime_pointer_cast(U const* u) BOOST_NOEXCEPT { @@ -71,4 +71,4 @@ T const* runtime_pointer_cast(U const* u) BOOST_NOEXCEPT { }} // namespace boost::typeindex -#endif // BOOST_TYPE_INDEX_RUNTIME_CAST_POINTER_CAST_HPP \ No newline at end of file +#endif // BOOST_TYPE_INDEX_RUNTIME_CAST_POINTER_CAST_HPP diff --git a/include/boost/type_index/runtime_cast/reference_cast.hpp b/include/boost/type_index/runtime_cast/reference_cast.hpp index 6f30b50..10b5dc1 100644 --- a/include/boost/type_index/runtime_cast/reference_cast.hpp +++ b/include/boost/type_index/runtime_cast/reference_cast.hpp @@ -33,7 +33,7 @@ struct bad_runtime_cast : std::exception /// \brief Safely converts references to classes up, down, and sideways along the inheritance hierarchy. /// \tparam T The desired target type. Like dynamic_cast, must be a pointer to complete class type. /// \tparam U A complete class type of the source instance, u. -/// \return If there exists a valid conversion from U& to T, returns a T that references an address +/// \return If there exists a valid conversion from U& to T, returns a T that references an address /// suitably offset from u. If no such conversion exists, throws boost::typeindex::bad_runtime_cast. template T& runtime_cast(U& u) { @@ -43,12 +43,12 @@ T& runtime_cast(U& u) { if(!value) BOOST_THROW_EXCEPTION(bad_runtime_cast()); return *value; -} +} /// \brief Safely converts references to classes up, down, and sideways along the inheritance hierarchy. /// \tparam T The desired target type. Like dynamic_cast, must be a pointer to complete class type. /// \tparam U A complete class type of the source instance, u. -/// \return If there exists a valid conversion from U const& to T const, returns a T const that references an address +/// \return If there exists a valid conversion from U const& to T const, returns a T const that references an address /// suitably offset from u. If no such conversion exists, throws boost::typeindex::bad_runtime_cast. template T const& runtime_cast(U const& u) { @@ -62,4 +62,4 @@ T const& runtime_cast(U const& u) { }} // namespace boost::typeindex -#endif // BOOST_TYPE_INDEX_RUNTIME_CAST_REFERENCE_CAST_HPP \ No newline at end of file +#endif // BOOST_TYPE_INDEX_RUNTIME_CAST_REFERENCE_CAST_HPP diff --git a/include/boost/type_index/runtime_cast/register_runtime_class.hpp b/include/boost/type_index/runtime_cast/register_runtime_class.hpp index cd0e8dd..37ce686 100644 --- a/include/boost/type_index/runtime_cast/register_runtime_class.hpp +++ b/include/boost/type_index/runtime_cast/register_runtime_class.hpp @@ -39,39 +39,39 @@ inline type_index runtime_class_construct_type_id(T const*) { /// \def BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS /// \brief Macro used to make a class compatible with boost::typeindex::runtime_cast /// -/// BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS generates a virtual function +/// BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS generates a virtual function /// in the current class that, when combined with the supplied base class information, allows /// boost::typeindex::runtime_cast to accurately convert between dynamic types of instances of /// the current class. -/// +/// /// \b Example: /// \code /// struct base1 { -/// BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS(BOOST_TYPE_INDEX_NO_BASE_CLASS) -/// virtual ~base1(); +/// BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS(BOOST_TYPE_INDEX_NO_BASE_CLASS) +/// virtual ~base1(); /// }; /// -/// struct base2 { +/// struct base2 { /// BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS(BOOST_TYPE_INDEX_NO_BASE_CLASS) /// virtual ~base2(); /// }; /// /// struct derived1 : base1 { -/// BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS((base1)) -/// }; +/// BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS((base1)) +/// }; /// -/// struct derived2 : base1, base2 { -/// BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS((base1)(base2)) +/// struct derived2 : base1, base2 { +/// BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS((base1)(base2)) /// }; /// /// ... -/// +/// /// base1* pb1 = get_object(); /// if(derived2* pb2 = boost::typeindex::runtime_cast(pb1)) /// { /* ... */ } /// \endcode /// -/// \param base_class_seq A Boost.Preprocessor sequence of the current class' direct bases, or +/// \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. #define BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS(base_class_seq) \ BOOST_TYPE_INDEX_REGISTER_CLASS \ @@ -80,9 +80,9 @@ inline type_index runtime_class_construct_type_id(T const*) { return this; \ BOOST_PP_SEQ_FOR_EACH(BOOST_TYPE_INDEX_CHECK_BASE_, _, base_class_seq) \ return NULL; \ - } + } }} // namespace boost::typeindex #define BOOST_TYPE_INDEX_NO_BASE_CLASS BOOST_PP_SEQ_NIL -#endif // BOOST_TYPE_INDEX_RUNTIME_CAST_REGISTER_RUNTIME_CLASS_HPP \ No newline at end of file +#endif // BOOST_TYPE_INDEX_RUNTIME_CAST_REGISTER_RUNTIME_CLASS_HPP diff --git a/include/boost/type_index/runtime_cast/std_shared_ptr_cast.hpp b/include/boost/type_index/runtime_cast/std_shared_ptr_cast.hpp index 12e8f1c..277a524 100644 --- a/include/boost/type_index/runtime_cast/std_shared_ptr_cast.hpp +++ b/include/boost/type_index/runtime_cast/std_shared_ptr_cast.hpp @@ -23,15 +23,15 @@ namespace boost { namespace typeindex { -/// \brief Creates a new instance of std::shared_ptr whose stored pointer is obtained from u's +/// \brief Creates a new instance of std::shared_ptr whose stored pointer is obtained from u's /// stored pointer using a runtime_cast. /// -/// The new shared_ptr will share ownership with u, except that it is empty if the runtime_cast +/// The new shared_ptr will share ownership with u, except that it is empty if the runtime_cast /// performed by runtime_pointer_cast returns a null pointer. /// \tparam T The desired target type to return a pointer of. /// \tparam U A complete class type of the source instance pointed to from u. -/// \return If there exists a valid conversion from U* to T*, returns a std::shared_ptr -/// that points to an address suitably offset from u. +/// \return If there exists a valid conversion from U* to T*, returns a std::shared_ptr +/// that points to an address suitably offset from u. /// If no such conversion exists, returns std::shared_ptr(); template std::shared_ptr runtime_pointer_cast(std::shared_ptr const& u) { @@ -39,8 +39,8 @@ std::shared_ptr runtime_pointer_cast(std::shared_ptr const& u) { if(value) return std::shared_ptr(u, value); return std::shared_ptr(); -} +} }} // namespace boost::typeindex -#endif // BOOST_TYPE_INDEX_RUNTIME_CAST_STD_SHARED_PTR_CAST_HPP \ No newline at end of file +#endif // BOOST_TYPE_INDEX_RUNTIME_CAST_STD_SHARED_PTR_CAST_HPP diff --git a/test/type_index_runtime_cast_test.cpp b/test/type_index_runtime_cast_test.cpp index 56ebe71..c64222a 100644 --- a/test/type_index_runtime_cast_test.cpp +++ b/test/type_index_runtime_cast_test.cpp @@ -180,8 +180,8 @@ void reference_interface() using namespace boost::typeindex; single_derived d; base& b = d; - single_derived& d2 = runtime_cast(b); - BOOST_TEST_EQ(d2.name, "single_derived"); + single_derived& d2 = runtime_cast(b); + BOOST_TEST_EQ(d2.name, "single_derived"); try { unrelated& u = runtime_cast(b); @@ -211,8 +211,8 @@ void const_reference_interface() using namespace boost::typeindex; const single_derived d; base const& b = d; - single_derived const& d2 = runtime_cast(b); - BOOST_TEST_EQ(d2.name, "single_derived"); + single_derived const& d2 = runtime_cast(b); + BOOST_TEST_EQ(d2.name, "single_derived"); try { unrelated const& u = runtime_cast(b); @@ -233,7 +233,7 @@ void diamond_non_virtual() level1_a* l1a = &inst; base* b1 = l1a; level1_b* l1_b = runtime_cast(b1); - BOOST_TEST_EQ(l1_b->name, "level1_b"); + BOOST_TEST_EQ(l1_b->name, "level1_b"); BOOST_TEST_NE(l1_b, (level1_b*)NULL); } @@ -271,4 +271,3 @@ int main() { std_shared_ptr(); return boost::report_errors(); } -