Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 | |
| 6 | // See http://www.boost.org/libs/test for the library home page. |
| 7 | // |
| 8 | // File : $RCSfile$ |
| 9 | // |
| 10 | // Version : $Revision: 49312 $ |
| 11 | // |
| 12 | // Description : simple facilities for accessing type information at runtime |
| 13 | // *************************************************************************** |
| 14 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 15 | #ifndef NDNBOOST_TEST_RTTI_HPP_062604GER |
| 16 | #define NDNBOOST_TEST_RTTI_HPP_062604GER |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 17 | |
| 18 | #include <cstddef> |
| 19 | |
| 20 | namespace ndnboost { |
| 21 | |
| 22 | namespace rtti { |
| 23 | |
| 24 | // ************************************************************************** // |
| 25 | // ************** rtti::type_id ************** // |
| 26 | // ************************************************************************** // |
| 27 | |
| 28 | typedef std::ptrdiff_t id_t; |
| 29 | |
| 30 | namespace rtti_detail { |
| 31 | |
| 32 | template<typename T> |
| 33 | struct rttid_holder { |
| 34 | static id_t id() { return reinterpret_cast<id_t>( &inst() ); } |
| 35 | |
| 36 | private: |
| 37 | struct rttid {}; |
| 38 | |
| 39 | static rttid const& inst() { static rttid s_inst; return s_inst; } |
| 40 | }; |
| 41 | |
| 42 | } // namespace rtti_detail |
| 43 | |
| 44 | //____________________________________________________________________________// |
| 45 | |
| 46 | template<typename T> |
| 47 | inline id_t |
| 48 | type_id() |
| 49 | { |
| 50 | return rtti_detail::rttid_holder<T>::id(); |
| 51 | } |
| 52 | |
| 53 | //____________________________________________________________________________// |
| 54 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 55 | #define NDNBOOST_RTTI_SWITCH( type_id_ ) if( ::ndnboost::rtti::id_t switch_by_id = type_id_ ) |
| 56 | #define NDNBOOST_RTTI_CASE( type ) if( switch_by_id == ::ndnboost::rtti::type_id<type>() ) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 57 | |
| 58 | //____________________________________________________________________________// |
| 59 | |
| 60 | } // namespace rtti |
| 61 | |
| 62 | } // namespace ndnboost |
| 63 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 64 | #endif // NDNBOOST_RT_RTTI_HPP_062604GER |