-
Notifications
You must be signed in to change notification settings - Fork 298
/
typeinfo.hpp
134 lines (120 loc) · 3.94 KB
/
typeinfo.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
* Boost.Extension / typeinfo:
* implementations name management with RTTI
*
* (C) Copyright Jeremy Pack 2008
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org/ for latest version.
*/
#ifndef BOOST_EXTENSION_TYPEINFO_HPP
#define BOOST_EXTENSION_TYPEINFO_HPP
#include <typeinfo>
namespace boost { namespace extensions {
template <class TypeInfo, class ClassType>
struct type_info_handler {
static TypeInfo get_class_type();
};
class default_type_info {
public:
default_type_info() : type_(&typeid(void)) {
}
default_type_info(const std::type_info& new_type) : type_(&new_type) {
}
default_type_info(const default_type_info& first) : type_(first.type_) {
}
const std::type_info& type() const {
return *type_;
}
default_type_info& operator=(const default_type_info& first) {
type_ = first.type_;
return *this;
}
private:
const std::type_info* type_;
};
template <class ClassType>
struct type_info_handler<default_type_info, ClassType>
{
static default_type_info get_class_type() {
return default_type_info(typeid(ClassType));
}
};
}}
#if defined(__MINGW32__) || defined(__GNUC__)
#include <cstring>
namespace boost { namespace extensions {
inline bool operator<(const default_type_info& first,
const default_type_info& second) {
return std::strcmp(first.type().name(), second.type().name()) < 0;
}
inline bool operator==(const default_type_info& first,
const default_type_info& second) {
return std::strcmp(first.type().name(), second.type().name()) == 0;
}
inline bool operator>(const default_type_info& first,
const default_type_info& second) {
return std::strcmp(first.type().name(), second.type().name()) > 0;
}
}}
#else
// This list should be expanded to all platforms that successfully
// compare type_info across shared library boundaries.
#if defined(__APPLE__) || \
defined(BOOST_EXTENSION_FORCE_FAST_TYPEINFO)
namespace boost {
namespace extensions {
inline bool operator<(const default_type_info& first,
const default_type_info& second) {
return &first.type() < &second.type();
}
inline bool operator==(const default_type_info& first,
const default_type_info& second) {
return &first.type() == &second.type();
}
inline bool operator>(const default_type_info& first,
const default_type_info& second) {
return &first.type() > &second.type();
}
}}
#else
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
#include <string>
namespace boost { namespace extensions {
inline bool operator<(const default_type_info& first,
const default_type_info& second) {
return std::strcmp(first.type().raw_name(), second.type().raw_name()) < 0;
}
inline bool operator==(const default_type_info& first,
const default_type_info& second) {
return std::strcmp(first.type().raw_name(), second.type().raw_name()) == 0;
}
inline bool operator>(const default_type_info& first,
const default_type_info& second) {
return std::strcmp(first.type().raw_name(), second.type().raw_name()) > 0;
}
} // namespace extensions
} // namespace boost
#else // OTHER OS
#include <string>
namespace boost { namespace extensions {
inline bool operator<(const default_type_info& first,
const default_type_info& second) {
return std::strcmp(first.type().name(), second.type().name()) < 0;
}
inline bool operator==(const default_type_info& first,
const default_type_info& second) {
return std::strcmp(first.type().name(), second.type().name()) == 0;
}
inline bool operator>(const default_type_info& first,
const default_type_info& second) {
return std::strcmp(first.type().name(), second.type().name()) > 0;
}
} // namespace extensions
} // namespace boost
#endif
#endif // WINDOWS
#endif // OS X
#endif // BOOST_EXTENSION_TYPEINFO_HPP