blob: 7ed63aa0957831e9d6bd1628a352bb3ad9e1c7c3 [file] [log] [blame]
Jeff Thompson3d613fd2013-10-15 15:39:04 -07001#ifndef NDNBOOST_DETAIL_SP_TYPEINFO_HPP_INCLUDED
2#define NDNBOOST_DETAIL_SP_TYPEINFO_HPP_INCLUDED
Jeff Thompsonf7d49942013-08-01 16:47:40 -07003
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 Thompson2277ce52013-08-01 17:34:11 -070018#include <ndnboost/config.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -070019
Jeff Thompson3d613fd2013-10-15 15:39:04 -070020#if defined( NDNBOOST_NO_TYPEID )
Jeff Thompsonf7d49942013-08-01 16:47:40 -070021
Jeff Thompson2277ce52013-08-01 17:34:11 -070022#include <ndnboost/current_function.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -070023#include <functional>
24
25namespace ndnboost
26{
27
28namespace detail
29{
30
31class sp_typeinfo
32{
33private:
34
35 sp_typeinfo( sp_typeinfo const& );
36 sp_typeinfo& operator=( sp_typeinfo const& );
37
38 char const * name_;
39
40public:
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
67template<class T> struct sp_typeid_
68{
69 static sp_typeinfo ti_;
70
71 static char const * name()
72 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -070073 return NDNBOOST_CURRENT_FUNCTION;
Jeff Thompsonf7d49942013-08-01 16:47:40 -070074 }
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.
80template<class T> sp_typeinfo sp_typeid_< T >::ti_ = sp_typeid_< T >::name();
81#else
82template<class T> sp_typeinfo sp_typeid_< T >::ti_(sp_typeid_< T >::name());
83#endif
84
85template<class T> struct sp_typeid_< T & >: sp_typeid_< T >
86{
87};
88
89template<class T> struct sp_typeid_< T const >: sp_typeid_< T >
90{
91};
92
93template<class T> struct sp_typeid_< T volatile >: sp_typeid_< T >
94{
95};
96
97template<class T> struct sp_typeid_< T const volatile >: sp_typeid_< T >
98{
99};
100
101} // namespace detail
102
103} // namespace ndnboost
104
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700105#define NDNBOOST_SP_TYPEID(T) (ndnboost::detail::sp_typeid_<T>::ti_)
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700106
107#else
108
109#include <typeinfo>
110
111namespace ndnboost
112{
113
114namespace detail
115{
116
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700117#if defined( NDNBOOST_NO_STD_TYPEINFO )
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700118
119typedef ::type_info sp_typeinfo;
120
121#else
122
123typedef std::type_info sp_typeinfo;
124
125#endif
126
127} // namespace detail
128
129} // namespace ndnboost
130
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700131#define NDNBOOST_SP_TYPEID(T) typeid(T)
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700132
133#endif
134
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700135#endif // #ifndef NDNBOOST_DETAIL_SP_TYPEINFO_HPP_INCLUDED