Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 1 | #ifndef NDNBOOST_DETAIL_SP_TYPEINFO_HPP_INCLUDED |
| 2 | #define NDNBOOST_DETAIL_SP_TYPEINFO_HPP_INCLUDED |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 3 | |
| 4 | // MS compatible compilers support #pragma once |
| 5 | |
| 6 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) |
| 7 | # pragma once |
| 8 | #endif |
| 9 | |
| 10 | // detail/sp_typeinfo.hpp |
| 11 | // |
| 12 | // Copyright 2007 Peter Dimov |
| 13 | // |
| 14 | // Distributed under the Boost Software License, Version 1.0. |
| 15 | // See accompanying file LICENSE_1_0.txt or copy at |
| 16 | // http://www.boost.org/LICENSE_1_0.txt) |
| 17 | |
Jeff Thompson | 2277ce5 | 2013-08-01 17:34:11 -0700 | [diff] [blame] | 18 | #include <ndnboost/config.hpp> |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 19 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 20 | #if defined( NDNBOOST_NO_TYPEID ) |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 21 | |
Jeff Thompson | 2277ce5 | 2013-08-01 17:34:11 -0700 | [diff] [blame] | 22 | #include <ndnboost/current_function.hpp> |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 23 | #include <functional> |
| 24 | |
| 25 | namespace ndnboost |
| 26 | { |
| 27 | |
| 28 | namespace detail |
| 29 | { |
| 30 | |
| 31 | class sp_typeinfo |
| 32 | { |
| 33 | private: |
| 34 | |
| 35 | sp_typeinfo( sp_typeinfo const& ); |
| 36 | sp_typeinfo& operator=( sp_typeinfo const& ); |
| 37 | |
| 38 | char const * name_; |
| 39 | |
| 40 | public: |
| 41 | |
| 42 | explicit sp_typeinfo( char const * name ): name_( name ) |
| 43 | { |
| 44 | } |
| 45 | |
| 46 | bool operator==( sp_typeinfo const& rhs ) const |
| 47 | { |
| 48 | return this == &rhs; |
| 49 | } |
| 50 | |
| 51 | bool operator!=( sp_typeinfo const& rhs ) const |
| 52 | { |
| 53 | return this != &rhs; |
| 54 | } |
| 55 | |
| 56 | bool before( sp_typeinfo const& rhs ) const |
| 57 | { |
| 58 | return std::less< sp_typeinfo const* >()( this, &rhs ); |
| 59 | } |
| 60 | |
| 61 | char const* name() const |
| 62 | { |
| 63 | return name_; |
| 64 | } |
| 65 | }; |
| 66 | |
| 67 | template<class T> struct sp_typeid_ |
| 68 | { |
| 69 | static sp_typeinfo ti_; |
| 70 | |
| 71 | static char const * name() |
| 72 | { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 73 | return NDNBOOST_CURRENT_FUNCTION; |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 74 | } |
| 75 | }; |
| 76 | |
| 77 | #if defined(__SUNPRO_CC) |
| 78 | // see #4199, the Sun Studio compiler gets confused about static initialization |
| 79 | // constructor arguments. But an assignment works just fine. |
| 80 | template<class T> sp_typeinfo sp_typeid_< T >::ti_ = sp_typeid_< T >::name(); |
| 81 | #else |
| 82 | template<class T> sp_typeinfo sp_typeid_< T >::ti_(sp_typeid_< T >::name()); |
| 83 | #endif |
| 84 | |
| 85 | template<class T> struct sp_typeid_< T & >: sp_typeid_< T > |
| 86 | { |
| 87 | }; |
| 88 | |
| 89 | template<class T> struct sp_typeid_< T const >: sp_typeid_< T > |
| 90 | { |
| 91 | }; |
| 92 | |
| 93 | template<class T> struct sp_typeid_< T volatile >: sp_typeid_< T > |
| 94 | { |
| 95 | }; |
| 96 | |
| 97 | template<class T> struct sp_typeid_< T const volatile >: sp_typeid_< T > |
| 98 | { |
| 99 | }; |
| 100 | |
| 101 | } // namespace detail |
| 102 | |
| 103 | } // namespace ndnboost |
| 104 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 105 | #define NDNBOOST_SP_TYPEID(T) (ndnboost::detail::sp_typeid_<T>::ti_) |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 106 | |
| 107 | #else |
| 108 | |
| 109 | #include <typeinfo> |
| 110 | |
| 111 | namespace ndnboost |
| 112 | { |
| 113 | |
| 114 | namespace detail |
| 115 | { |
| 116 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 117 | #if defined( NDNBOOST_NO_STD_TYPEINFO ) |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 118 | |
| 119 | typedef ::type_info sp_typeinfo; |
| 120 | |
| 121 | #else |
| 122 | |
| 123 | typedef std::type_info sp_typeinfo; |
| 124 | |
| 125 | #endif |
| 126 | |
| 127 | } // namespace detail |
| 128 | |
| 129 | } // namespace ndnboost |
| 130 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 131 | #define NDNBOOST_SP_TYPEID(T) typeid(T) |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 132 | |
| 133 | #endif |
| 134 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 135 | #endif // #ifndef NDNBOOST_DETAIL_SP_TYPEINFO_HPP_INCLUDED |