rtti.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // (C) Copyright Gennadiy Rozental 2005-2008.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // See http://www.boost.org/libs/test for the library home page.
  6. //
  7. // File : $RCSfile$
  8. //
  9. // Version : $Revision: 49312 $
  10. //
  11. // Description : simple facilities for accessing type information at runtime
  12. // ***************************************************************************
  13. #ifndef BOOST_TEST_RTTI_HPP_062604GER
  14. #define BOOST_TEST_RTTI_HPP_062604GER
  15. #include <cstddef>
  16. namespace boost {
  17. namespace rtti {
  18. // ************************************************************************** //
  19. // ************** rtti::type_id ************** //
  20. // ************************************************************************** //
  21. typedef std::ptrdiff_t id_t;
  22. namespace rtti_detail {
  23. template<typename T>
  24. struct rttid_holder {
  25. static id_t id() { return reinterpret_cast<id_t>( &inst() ); }
  26. private:
  27. struct rttid {};
  28. static rttid const& inst() { static rttid s_inst; return s_inst; }
  29. };
  30. } // namespace rtti_detail
  31. //____________________________________________________________________________//
  32. template<typename T>
  33. inline id_t
  34. type_id()
  35. {
  36. return rtti_detail::rttid_holder<T>::id();
  37. }
  38. //____________________________________________________________________________//
  39. #define BOOST_RTTI_SWITCH( type_id_ ) if( ::boost::rtti::id_t switch_by_id = type_id_ )
  40. #define BOOST_RTTI_CASE( type ) if( switch_by_id == ::boost::rtti::type_id<type>() )
  41. //____________________________________________________________________________//
  42. } // namespace rtti
  43. } // namespace boost
  44. #endif // BOOST_RT_RTTI_HPP_062604GER