Blame boost/type_index.hpp

Packit 58578d
//
Packit 58578d
// Copyright (c) Antony Polukhin, 2012-2014.
Packit 58578d
//
Packit 58578d
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Packit 58578d
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Packit 58578d
//
Packit 58578d
Packit 58578d
#ifndef BOOST_TYPE_INDEX_HPP
Packit 58578d
#define BOOST_TYPE_INDEX_HPP
Packit 58578d
Packit 58578d
/// \file boost/type_index.hpp
Packit 58578d
/// \brief Includes minimal set of headers required to use the Boost.TypeIndex library.
Packit 58578d
///
Packit 58578d
/// By inclusion of this file most optimal type index classes will be included and used 
Packit 58578d
/// as a boost::typeindex::type_index and boost::typeindex::type_info.
Packit 58578d
Packit 58578d
#include <boost/config.hpp>
Packit 58578d
Packit 58578d
#ifdef BOOST_HAS_PRAGMA_ONCE
Packit 58578d
# pragma once
Packit 58578d
#endif
Packit 58578d
Packit 58578d
#if defined(BOOST_TYPE_INDEX_USER_TYPEINDEX)
Packit 58578d
#   include BOOST_TYPE_INDEX_USER_TYPEINDEX
Packit 58578d
#   ifdef BOOST_HAS_PRAGMA_DETECT_MISMATCH
Packit 58578d
#       pragma detect_mismatch( "boost__type_index__abi", "user defined type_index class is used: " BOOST_STRINGIZE(BOOST_TYPE_INDEX_USER_TYPEINDEX))
Packit 58578d
#   endif
Packit 58578d
#elif (!defined(BOOST_NO_RTTI) && !defined(BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY)) || defined(BOOST_MSVC)
Packit 58578d
#   include <boost/type_index/stl_type_index.hpp>
Packit 58578d
#   if defined(BOOST_NO_RTTI) || defined(BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY)
Packit 58578d
#       include <boost/type_index/detail/stl_register_class.hpp>
Packit 58578d
#       ifdef BOOST_HAS_PRAGMA_DETECT_MISMATCH
Packit 58578d
#           pragma detect_mismatch( "boost__type_index__abi", "RTTI is off - typeid() is used only for templates")
Packit 58578d
#       endif
Packit 58578d
#   else
Packit 58578d
#       ifdef BOOST_HAS_PRAGMA_DETECT_MISMATCH
Packit 58578d
#           pragma detect_mismatch( "boost__type_index__abi", "RTTI is used")
Packit 58578d
#       endif
Packit 58578d
#   endif
Packit 58578d
#else
Packit 58578d
#   include <boost/type_index/ctti_type_index.hpp>
Packit 58578d
#   include <boost/type_index/detail/ctti_register_class.hpp>
Packit 58578d
#   ifdef BOOST_HAS_PRAGMA_DETECT_MISMATCH
Packit 58578d
#       pragma detect_mismatch( "boost__type_index__abi", "RTTI is off - using CTTI")
Packit 58578d
#   endif
Packit 58578d
#endif
Packit 58578d
Packit 58578d
#ifndef BOOST_TYPE_INDEX_REGISTER_CLASS
Packit 58578d
#define BOOST_TYPE_INDEX_REGISTER_CLASS
Packit 58578d
#endif
Packit 58578d
Packit 58578d
namespace boost { namespace typeindex {
Packit 58578d
Packit 58578d
#if defined(BOOST_TYPE_INDEX_DOXYGEN_INVOKED)
Packit 58578d
Packit 58578d
/// \def BOOST_TYPE_INDEX_FUNCTION_SIGNATURE
Packit 58578d
/// BOOST_TYPE_INDEX_FUNCTION_SIGNATURE is used by boost::typeindex::ctti_type_index class to
Packit 58578d
/// deduce the name of a type. If your compiler is not recognized
Packit 58578d
/// by the TypeIndex library and you wish to work with boost::typeindex::ctti_type_index, you may
Packit 58578d
/// define this macro by yourself.
Packit 58578d
///
Packit 58578d
/// BOOST_TYPE_INDEX_FUNCTION_SIGNATURE must be defined to a compiler specific macro
Packit 58578d
/// that outputs the \b whole function signature \b including \b template \b parameters.
Packit 58578d
///
Packit 58578d
/// If your compiler is not recognised and BOOST_TYPE_INDEX_FUNCTION_SIGNATURE is not defined,
Packit 58578d
/// then a compile-time error will arise at any attempt to use boost::typeindex::ctti_type_index classes.
Packit 58578d
///
Packit 58578d
/// See BOOST_TYPE_INDEX_REGISTER_CTTI_PARSING_PARAMS and BOOST_TYPE_INDEX_CTTI_USER_DEFINED_PARSING
Packit 58578d
/// for an information of how to tune the implementation to make a nice pretty_name() output.
Packit 58578d
#define BOOST_TYPE_INDEX_FUNCTION_SIGNATURE BOOST_CURRENT_FUNCTION
Packit 58578d
Packit 58578d
/// \def BOOST_TYPE_INDEX_CTTI_USER_DEFINED_PARSING
Packit 58578d
/// This is a helper macro for making correct pretty_names() with RTTI off.
Packit 58578d
///
Packit 58578d
/// BOOST_TYPE_INDEX_CTTI_USER_DEFINED_PARSING macro may be defined to
Packit 58578d
/// '(begin_skip, end_skip, runtime_skip, runtime_skip_until)' with parameters for adding a
Packit 58578d
/// support for compilers, that by default are not recognized by TypeIndex library.
Packit 58578d
///
Packit 58578d
/// \b Example:
Packit 58578d
///
Packit 58578d
/// Imagine the situation when
Packit 58578d
/// \code boost::typeindex::ctti_type_index::type_id<int>().pretty_name() \endcode
Packit 58578d
/// returns the following string:
Packit 58578d
/// \code "static const char *boost::detail::ctti<int>::n() [T = int]" \endcode
Packit 58578d
/// and \code boost::typeindex::ctti_type_index::type_id<short>().pretty_name() \endcode returns the following:
Packit 58578d
/// \code "static const char *boost::detail::ctti<short>::n() [T = short]" \endcode
Packit 58578d
///
Packit 58578d
/// As we may see first 39 characters are "static const char *boost::detail::ctti<" and they do not depend on
Packit 58578d
/// the type T. After first 39 characters we have a human readable type name which is duplicated at the end
Packit 58578d
/// of a string. String always ends on ']', which consumes 1 character.
Packit 58578d
///
Packit 58578d
/// Now if we define `BOOST_TYPE_INDEX_CTTI_USER_DEFINED_PARSING` to
Packit 58578d
/// `(39, 1, false, "")` we'll be getting \code "int>::n() [T = int" \endcode
Packit 58578d
/// for `boost::typeindex::ctti_type_index::type_id<int>().pretty_name()` and \code "short>::n() [T = short" \endcode
Packit 58578d
/// for `boost::typeindex::ctti_type_index::type_id<short>().pretty_name()`.
Packit 58578d
///
Packit 58578d
/// Now we need to take additional care of the characters that go before the last mention of our type. We'll
Packit 58578d
/// do that by telling the macro that we need to cut off everything that goes before the "T = " including the "T = "
Packit 58578d
/// itself:
Packit 58578d
///
Packit 58578d
/// \code (39, 1, true, "T = ") \endcode
Packit 58578d
///
Packit 58578d
/// In case of GCC or Clang command line we need to add the following line while compiling all the sources:
Packit 58578d
///
Packit 58578d
/// \code
Packit 58578d
/// -DBOOST_TYPE_INDEX_CTTI_USER_DEFINED_PARSING='(39, 1, true, "T = ")'
Packit 58578d
/// \endcode
Packit 58578d
/// \param begin_skip How many characters must be skipped at the beginning of the type holding string.
Packit 58578d
/// Must be a compile time constant.
Packit 58578d
/// \param end_skip How many characters must be skipped at the end of the type holding string.
Packit 58578d
/// Must be a compile time constant.
Packit 58578d
/// \param runtime_skip Do we need additional checks at runtime to cut off the more characters.
Packit 58578d
/// Must be `true` or `false`.
Packit 58578d
/// \param runtime_skip_until Skip all the characters before the following string (including the string itself).
Packit 58578d
/// Must be a compile time array of characters.
Packit 58578d
///
Packit 58578d
/// See [RTTI emulation limitations](boost_typeindex/rtti_emulation_limitations.html) for more info.
Packit 58578d
#define BOOST_TYPE_INDEX_CTTI_USER_DEFINED_PARSING (0, 0, false, "")
Packit 58578d
Packit 58578d
Packit 58578d
    /// Depending on a compiler flags, optimal implementation of type_index will be used 
Packit 58578d
    /// as a default boost::typeindex::type_index.
Packit 58578d
    ///
Packit 58578d
    /// Could be a boost::typeindex::stl_type_index, boost::typeindex::ctti_type_index or 
Packit 58578d
    /// user defined type_index class.
Packit 58578d
    ///
Packit 58578d
    /// \b See boost::typeindex::type_index_facade for a full description of type_index functions.
Packit 58578d
    typedef platform_specific type_index;
Packit 58578d
#elif defined(BOOST_TYPE_INDEX_USER_TYPEINDEX)
Packit 58578d
    // Nothing to do
Packit 58578d
#elif (!defined(BOOST_NO_RTTI) && !defined(BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY)) || defined(BOOST_MSVC)
Packit 58578d
    typedef boost::typeindex::stl_type_index type_index;
Packit 58578d
#else 
Packit 58578d
    typedef boost::typeindex::ctti_type_index type_index;
Packit 58578d
#endif
Packit 58578d
Packit 58578d
/// Depending on a compiler flags, optimal implementation of type_info will be used 
Packit 58578d
/// as a default boost::typeindex::type_info.
Packit 58578d
///
Packit 58578d
/// Could be a std::type_info, boost::typeindex::detail::ctti_data or 
Packit 58578d
/// some user defined class.
Packit 58578d
///
Packit 58578d
/// type_info \b is \b not copyable or default constructible. It is \b not assignable too!
Packit 58578d
typedef type_index::type_info_t type_info;
Packit 58578d
Packit 58578d
#if defined(BOOST_TYPE_INDEX_DOXYGEN_INVOKED)
Packit 58578d
Packit 58578d
/// \def BOOST_TYPE_INDEX_USER_TYPEINDEX
Packit 58578d
/// BOOST_TYPE_INDEX_USER_TYPEINDEX can be defined to the path to header file
Packit 58578d
/// with user provided implementation of type_index.
Packit 58578d
///
Packit 58578d
/// See [Making a custom type_index](boost_typeindex/making_a_custom_type_index.html) section
Packit 58578d
/// of documentation for usage example.
Packit 58578d
#define BOOST_TYPE_INDEX_USER_TYPEINDEX <full/absolute/path/to/header/with/type_index.hpp>
Packit 58578d
Packit 58578d
Packit 58578d
/// \def BOOST_TYPE_INDEX_REGISTER_CLASS
Packit 58578d
/// BOOST_TYPE_INDEX_REGISTER_CLASS is used to help to emulate RTTI.
Packit 58578d
/// Put this macro into the public section of polymorphic class to allow runtime type detection.
Packit 58578d
///
Packit 58578d
/// Depending on the typeid() availability this macro will expand to nothing or to virtual helper function
Packit 58578d
/// `virtual const type_info& boost_type_info_type_id_runtime_() const noexcept`.
Packit 58578d
///
Packit 58578d
/// \b Example:
Packit 58578d
/// \code
Packit 58578d
/// class A {
Packit 58578d
/// public:
Packit 58578d
///     BOOST_TYPE_INDEX_REGISTER_CLASS
Packit 58578d
///     virtual ~A(){}
Packit 58578d
/// };
Packit 58578d
///
Packit 58578d
/// struct B: public A {
Packit 58578d
///     BOOST_TYPE_INDEX_REGISTER_CLASS
Packit 58578d
/// };
Packit 58578d
///
Packit 58578d
/// struct C: public B {
Packit 58578d
///     BOOST_TYPE_INDEX_REGISTER_CLASS
Packit 58578d
/// };
Packit 58578d
///
Packit 58578d
/// ...
Packit 58578d
///
Packit 58578d
/// C c1;
Packit 58578d
/// A* pc1 = &c1;
Packit 58578d
/// assert(boost::typeindex::type_id<C>() == boost::typeindex::type_id_runtime(*pc1));
Packit 58578d
/// \endcode
Packit 58578d
#define BOOST_TYPE_INDEX_REGISTER_CLASS nothing-or-some-virtual-functions
Packit 58578d
Packit 58578d
/// \def BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY
Packit 58578d
/// BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY is a helper macro that must be defined if mixing
Packit 58578d
/// RTTI on/off modules. See
Packit 58578d
/// [Mixing sources with RTTI on and RTTI off](boost_typeindex/mixing_sources_with_rtti_on_and_.html)
Packit 58578d
/// section of documentation for more info.
Packit 58578d
#define BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY
Packit 58578d
Packit 58578d
#endif // defined(BOOST_TYPE_INDEX_DOXYGEN_INVOKED)
Packit 58578d
Packit 58578d
Packit 58578d
/// Function to get boost::typeindex::type_index for a type T.
Packit 58578d
/// Removes const, volatile && and & modifiers from T.
Packit 58578d
///
Packit 58578d
/// \b Example:
Packit 58578d
/// \code
Packit 58578d
/// type_index ti = type_id<int&>();
Packit 58578d
/// std::cout << ti.pretty_name();  // Outputs 'int'
Packit 58578d
/// \endcode
Packit 58578d
///
Packit 58578d
/// \tparam T Type for which type_index must be created.
Packit 58578d
/// \throw Nothing.
Packit 58578d
/// \return boost::typeindex::type_index with information about the specified type T.
Packit 58578d
template <class T>
Packit 58578d
inline type_index type_id() BOOST_NOEXCEPT {
Packit 58578d
    return type_index::type_id<T>();
Packit 58578d
}
Packit 58578d
Packit 58578d
/// Function for constructing boost::typeindex::type_index instance for type T. 
Packit 58578d
/// Does not remove const, volatile, & and && modifiers from T.
Packit 58578d
///
Packit 58578d
/// If T has no const, volatile, & and && modifiers, then returns exactly 
Packit 58578d
/// the same result as in case of calling `type_id<T>()`.
Packit 58578d
///
Packit 58578d
/// \b Example:
Packit 58578d
/// \code
Packit 58578d
/// type_index ti = type_id_with_cvr<int&>();
Packit 58578d
/// std::cout << ti.pretty_name();  // Outputs 'int&'
Packit 58578d
/// \endcode
Packit 58578d
///
Packit 58578d
/// \tparam T Type for which type_index must be created.
Packit 58578d
/// \throw Nothing.
Packit 58578d
/// \return boost::typeindex::type_index with information about the specified type T.
Packit 58578d
template <class T>
Packit 58578d
inline type_index type_id_with_cvr() BOOST_NOEXCEPT {
Packit 58578d
    return type_index::type_id_with_cvr<T>();
Packit 58578d
}
Packit 58578d
Packit 58578d
/// Function that works exactly like C++ typeid(rtti_val) call, but returns boost::type_index.
Packit 58578d
///
Packit 58578d
/// Returns runtime information about specified type.
Packit 58578d
///
Packit 58578d
/// \b Requirements: RTTI available or Base and Derived classes must be marked with BOOST_TYPE_INDEX_REGISTER_CLASS.
Packit 58578d
///
Packit 58578d
/// \b Example:
Packit 58578d
/// \code
Packit 58578d
/// struct Base { virtual ~Base(){} };
Packit 58578d
/// struct Derived: public Base  {};
Packit 58578d
/// ...
Packit 58578d
/// Derived d;
Packit 58578d
/// Base& b = d;
Packit 58578d
/// type_index ti = type_id_runtime(b);
Packit 58578d
/// std::cout << ti.pretty_name();  // Outputs 'Derived'
Packit 58578d
/// \endcode
Packit 58578d
///
Packit 58578d
/// \param runtime_val Variable which runtime type must be returned.
Packit 58578d
/// \throw Nothing.
Packit 58578d
/// \return boost::typeindex::type_index with information about the specified variable.
Packit 58578d
template <class T>
Packit 58578d
inline type_index type_id_runtime(const T& runtime_val) BOOST_NOEXCEPT {
Packit 58578d
    return type_index::type_id_runtime(runtime_val);
Packit 58578d
}
Packit 58578d
Packit 58578d
}} // namespace boost::typeindex
Packit 58578d
Packit 58578d
Packit 58578d
Packit 58578d
#endif // BOOST_TYPE_INDEX_HPP
Packit 58578d