Cleanup line endings, file endings, some spacing etc.

This commit is contained in:
Chris Glover
2016-08-21 12:47:44 -04:00
parent 3bb646d19b
commit b6b23bad3a
10 changed files with 54 additions and 55 deletions

View File

@ -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.

View File

@ -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<C*>(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<E*>(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<D*>(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 {

View File

@ -25,4 +25,4 @@
# pragma once
#endif
#endif // BOOST_TYPE_INDEX_RUNTIME_CAST_HPP
#endif // BOOST_TYPE_INDEX_RUNTIME_CAST_HPP

View File

@ -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<T>
/// 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<T>
/// that points to an address suitably offset from u.
/// If no such conversion exists, returns boost::shared_ptr<T>();
template<typename T, typename U>
boost::shared_ptr<T> runtime_pointer_cast(boost::shared_ptr<U> const& u) {
@ -39,8 +39,8 @@ boost::shared_ptr<T> runtime_pointer_cast(boost::shared_ptr<U> const& u) {
if(value)
return boost::shared_ptr<T>(u, value);
return boost::shared_ptr<T>();
}
}
}} // namespace boost::typeindex
#endif // BOOST_TYPE_INDEX_RUNTIME_CAST_BOOST_SHARED_PTR_CAST_HPP
#endif // BOOST_TYPE_INDEX_RUNTIME_CAST_BOOST_SHARED_PTR_CAST_HPP

View File

@ -31,7 +31,7 @@ namespace detail {
template<typename T, typename U>
T* runtime_cast_impl(U* u, boost::true_type) BOOST_NOEXCEPT {
return u;
}
}
template<typename T, typename U>
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<T*>(static_cast<T const*>(
u->boost_type_index_find_instance_(boost::typeindex::type_id<T>())
));
}
}
template<typename T, typename U>
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
#endif // BOOST_TYPE_INDEX_RUNTIME_CAST_DETAIL_RUNTIME_CAST_IMPL_HPP

View File

@ -32,7 +32,7 @@ template<typename T, typename U>
T runtime_cast(U* u) BOOST_NOEXCEPT {
typedef typename boost::remove_pointer<T>::type impl_type;
return detail::runtime_cast_impl<impl_type>(u, boost::is_base_and_derived<T, U>());
}
}
/// \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<impl_type>(u, boost::is_base_and_derived<T, U>());
}
/// \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<typename T, typename U>
T* runtime_pointer_cast(U* u) BOOST_NOEXCEPT {
return detail::runtime_cast_impl<T>(u, boost::is_base_and_derived<T, U>());
}
}
/// \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<typename T, typename U>
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
#endif // BOOST_TYPE_INDEX_RUNTIME_CAST_POINTER_CAST_HPP

View File

@ -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<typename T, typename U>
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<typename T, typename U>
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
#endif // BOOST_TYPE_INDEX_RUNTIME_CAST_REFERENCE_CAST_HPP

View File

@ -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<derived2*>(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
#endif // BOOST_TYPE_INDEX_RUNTIME_CAST_REGISTER_RUNTIME_CLASS_HPP

View File

@ -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<T>
/// 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<T>
/// that points to an address suitably offset from u.
/// If no such conversion exists, returns std::shared_ptr<T>();
template<typename T, typename U>
std::shared_ptr<T> runtime_pointer_cast(std::shared_ptr<U> const& u) {
@ -39,8 +39,8 @@ std::shared_ptr<T> runtime_pointer_cast(std::shared_ptr<U> const& u) {
if(value)
return std::shared_ptr<T>(u, value);
return std::shared_ptr<T>();
}
}
}} // namespace boost::typeindex
#endif // BOOST_TYPE_INDEX_RUNTIME_CAST_STD_SHARED_PTR_CAST_HPP
#endif // BOOST_TYPE_INDEX_RUNTIME_CAST_STD_SHARED_PTR_CAST_HPP

View File

@ -180,8 +180,8 @@ void reference_interface()
using namespace boost::typeindex;
single_derived d;
base& b = d;
single_derived& d2 = runtime_cast<single_derived&>(b);
BOOST_TEST_EQ(d2.name, "single_derived");
single_derived& d2 = runtime_cast<single_derived&>(b);
BOOST_TEST_EQ(d2.name, "single_derived");
try {
unrelated& u = runtime_cast<unrelated&>(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<single_derived const&>(b);
BOOST_TEST_EQ(d2.name, "single_derived");
single_derived const& d2 = runtime_cast<single_derived const&>(b);
BOOST_TEST_EQ(d2.name, "single_derived");
try {
unrelated const& u = runtime_cast<unrelated const&>(b);
@ -233,7 +233,7 @@ void diamond_non_virtual()
level1_a* l1a = &inst;
base* b1 = l1a;
level1_b* l1_b = runtime_cast<level1_b*>(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();
}