1 // (C) Copyright Gennadiy Rozental 2001. 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 6 // See http://www.boost.org/libs/test for the library home page. 7 // 8 // File : $RCSfile$ 9 // 10 // Version : $Revision$ 11 // 12 // Description : simple facilities for accessing type information at runtime 13 // *************************************************************************** 14 15 #ifndef BOOST_TEST_UTILS_RTTI_HPP 16 #define BOOST_TEST_UTILS_RTTI_HPP 17 18 // C Runtime 19 #include <cstddef> 20 #include <boost/test/detail/config.hpp> 21 22 namespace boost { 23 namespace rtti { 24 25 // ************************************************************************** // 26 // ************** rtti::type_id ************** // 27 // ************************************************************************** // 28 29 typedef std::ptrdiff_t id_t; 30 31 namespace rtti_detail { 32 33 template<typename T> 34 struct BOOST_TEST_DECL rttid_holder { idboost::rtti::rtti_detail::rttid_holder35 static id_t id() { return reinterpret_cast<id_t>( &inst() ); } 36 37 private: 38 struct rttid {}; 39 instboost::rtti::rtti_detail::rttid_holder40 static rttid const& inst() { static rttid s_inst; return s_inst; } 41 }; 42 43 } // namespace rtti_detail 44 45 //____________________________________________________________________________// 46 47 template<typename T> 48 BOOST_TEST_DECL inline id_t type_id()49type_id() 50 { 51 return rtti_detail::rttid_holder<T>::id(); 52 } 53 54 //____________________________________________________________________________// 55 56 #define BOOST_RTTI_SWITCH( type_id_ ) if( ::boost::rtti::id_t switch_by_id = type_id_ ) 57 #define BOOST_RTTI_CASE( type ) if( switch_by_id == ::boost::rtti::type_id<type>() ) 58 59 //____________________________________________________________________________// 60 61 } // namespace rtti 62 } // namespace boost 63 64 #endif // BOOST_TEST_UTILS_RTTI_HPP 65