| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
1 |
// Tencent is pleased to support the open source community by making RapidJSON available. |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
2 |
// |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
3 |
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
4 |
// |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
5 |
// Licensed under the MIT License (the "License"); you may not use this file except |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
6 |
// in compliance with the License. You may obtain a copy of the License at |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
7 |
// |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
8 |
// http://opensource.org/licenses/MIT |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
9 |
// |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
10 |
// Unless required by applicable law or agreed to in writing, software distributed |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
11 |
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
12 |
// CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
13 |
// specific language governing permissions and limitations under the License. |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
14 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
15 |
#ifndef CEREAL_RAPIDJSON_INTERNAL_META_H_ |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
16 |
#define CEREAL_RAPIDJSON_INTERNAL_META_H_ |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
17 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
18 |
#include "../rapidjson.h" |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
19 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
20 |
#ifdef __GNUC__ |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
21 |
CEREAL_RAPIDJSON_DIAG_PUSH |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
22 |
CEREAL_RAPIDJSON_DIAG_OFF(effc++) |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
23 |
#endif |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
24 |
#if defined(_MSC_VER) |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
25 |
CEREAL_RAPIDJSON_DIAG_PUSH |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
26 |
CEREAL_RAPIDJSON_DIAG_OFF(6334) |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
27 |
#endif |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
28 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
29 |
#if CEREAL_RAPIDJSON_HAS_CXX11_TYPETRAITS |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
30 |
#include <type_traits> |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
31 |
#endif |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
32 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
33 |
//@cond CEREAL_RAPIDJSON_INTERNAL |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
34 |
CEREAL_RAPIDJSON_NAMESPACE_BEGIN |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
35 |
namespace internal { |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
36 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
37 |
// Helper to wrap/convert arbitrary types to void, useful for arbitrary type matching |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
38 |
template <typename T> struct Void { typedef void Type; }; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
39 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
40 |
/////////////////////////////////////////////////////////////////////////////// |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
41 |
// BoolType, TrueType, FalseType |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
42 |
// |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
43 |
template <bool Cond> struct BoolType { |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
44 |
static const bool Value = Cond; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
45 |
typedef BoolType Type; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
46 |
}; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
47 |
typedef BoolType<true> TrueType; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
48 |
typedef BoolType<false> FalseType; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
49 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
50 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
51 |
/////////////////////////////////////////////////////////////////////////////// |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
52 |
// SelectIf, BoolExpr, NotExpr, AndExpr, OrExpr |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
53 |
// |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
54 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
55 |
template <bool C> struct SelectIfImpl { template <typename T1, typename T2> struct Apply { typedef T1 Type; }; }; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
56 |
template <> struct SelectIfImpl<false> { template <typename T1, typename T2> struct Apply { typedef T2 Type; }; }; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
57 |
template <bool C, typename T1, typename T2> struct SelectIfCond : SelectIfImpl<C>::template Apply<T1,T2> {}; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
58 |
template <typename C, typename T1, typename T2> struct SelectIf : SelectIfCond<C::Value, T1, T2> {}; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
59 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
60 |
template <bool Cond1, bool Cond2> struct AndExprCond : FalseType {}; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
61 |
template <> struct AndExprCond<true, true> : TrueType {}; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
62 |
template <bool Cond1, bool Cond2> struct OrExprCond : TrueType {}; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
63 |
template <> struct OrExprCond<false, false> : FalseType {}; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
64 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
65 |
template <typename C> struct BoolExpr : SelectIf<C,TrueType,FalseType>::Type {}; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
66 |
template <typename C> struct NotExpr : SelectIf<C,FalseType,TrueType>::Type {}; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
67 |
template <typename C1, typename C2> struct AndExpr : AndExprCond<C1::Value, C2::Value>::Type {}; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
68 |
template <typename C1, typename C2> struct OrExpr : OrExprCond<C1::Value, C2::Value>::Type {}; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
69 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
70 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
71 |
/////////////////////////////////////////////////////////////////////////////// |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
72 |
// AddConst, MaybeAddConst, RemoveConst |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
73 |
template <typename T> struct AddConst { typedef const T Type; }; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
74 |
template <bool Constify, typename T> struct MaybeAddConst : SelectIfCond<Constify, const T, T> {}; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
75 |
template <typename T> struct RemoveConst { typedef T Type; }; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
76 |
template <typename T> struct RemoveConst<const T> { typedef T Type; }; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
77 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
78 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
79 |
/////////////////////////////////////////////////////////////////////////////// |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
80 |
// IsSame, IsConst, IsMoreConst, IsPointer |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
81 |
// |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
82 |
template <typename T, typename U> struct IsSame : FalseType {}; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
83 |
template <typename T> struct IsSame<T, T> : TrueType {}; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
84 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
85 |
template <typename T> struct IsConst : FalseType {}; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
86 |
template <typename T> struct IsConst<const T> : TrueType {}; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
87 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
88 |
template <typename CT, typename T> |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
89 |
struct IsMoreConst |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
90 |
: AndExpr<IsSame<typename RemoveConst<CT>::Type, typename RemoveConst<T>::Type>, |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
91 |
BoolType<IsConst<CT>::Value >= IsConst<T>::Value> >::Type {}; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
92 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
93 |
template <typename T> struct IsPointer : FalseType {}; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
94 |
template <typename T> struct IsPointer<T*> : TrueType {}; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
95 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
96 |
/////////////////////////////////////////////////////////////////////////////// |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
97 |
// IsBaseOf |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
98 |
// |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
99 |
#if CEREAL_RAPIDJSON_HAS_CXX11_TYPETRAITS |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
100 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
101 |
template <typename B, typename D> struct IsBaseOf |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
102 |
: BoolType< ::std::is_base_of<B,D>::value> {}; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
103 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
104 |
#else // simplified version adopted from Boost |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
105 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
106 |
template<typename B, typename D> struct IsBaseOfImpl { |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
107 |
CEREAL_RAPIDJSON_STATIC_ASSERT(sizeof(B) != 0); |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
108 |
CEREAL_RAPIDJSON_STATIC_ASSERT(sizeof(D) != 0); |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
109 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
110 |
typedef char (&Yes)[1]; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
111 |
typedef char (&No) [2]; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
112 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
113 |
template <typename T> |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
114 |
static Yes Check(const D*, T); |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
115 |
static No Check(const B*, int); |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
116 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
117 |
struct Host { |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
118 |
operator const B*() const; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
119 |
operator const D*(); |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
120 |
}; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
121 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
122 |
enum { Value = (sizeof(Check(Host(), 0)) == sizeof(Yes)) }; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
123 |
}; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
124 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
125 |
template <typename B, typename D> struct IsBaseOf |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
126 |
: OrExpr<IsSame<B, D>, BoolExpr<IsBaseOfImpl<B, D> > >::Type {}; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
127 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
128 |
#endif // CEREAL_RAPIDJSON_HAS_CXX11_TYPETRAITS |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
129 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
130 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
131 |
////////////////////////////////////////////////////////////////////////// |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
132 |
// EnableIf / DisableIf |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
133 |
// |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
134 |
template <bool Condition, typename T = void> struct EnableIfCond { typedef T Type; }; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
135 |
template <typename T> struct EnableIfCond<false, T> { /* empty */ }; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
136 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
137 |
template <bool Condition, typename T = void> struct DisableIfCond { typedef T Type; }; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
138 |
template <typename T> struct DisableIfCond<true, T> { /* empty */ }; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
139 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
140 |
template <typename Condition, typename T = void> |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
141 |
struct EnableIf : EnableIfCond<Condition::Value, T> {}; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
142 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
143 |
template <typename Condition, typename T = void> |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
144 |
struct DisableIf : DisableIfCond<Condition::Value, T> {}; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
145 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
146 |
// SFINAE helpers |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
147 |
struct SfinaeTag {}; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
148 |
template <typename T> struct RemoveSfinaeTag; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
149 |
template <typename T> struct RemoveSfinaeTag<SfinaeTag&(*)(T)> { typedef T Type; }; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
150 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
151 |
#define CEREAL_RAPIDJSON_REMOVEFPTR_(type) \ |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
152 |
typename ::CEREAL_RAPIDJSON_NAMESPACE::internal::RemoveSfinaeTag \ |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
153 |
< ::CEREAL_RAPIDJSON_NAMESPACE::internal::SfinaeTag&(*) type>::Type |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
154 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
155 |
#define CEREAL_RAPIDJSON_ENABLEIF(cond) \ |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
156 |
typename ::CEREAL_RAPIDJSON_NAMESPACE::internal::EnableIf \ |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
157 |
<CEREAL_RAPIDJSON_REMOVEFPTR_(cond)>::Type * = NULL |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
158 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
159 |
#define CEREAL_RAPIDJSON_DISABLEIF(cond) \ |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
160 |
typename ::CEREAL_RAPIDJSON_NAMESPACE::internal::DisableIf \ |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
161 |
<CEREAL_RAPIDJSON_REMOVEFPTR_(cond)>::Type * = NULL |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
162 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
163 |
#define CEREAL_RAPIDJSON_ENABLEIF_RETURN(cond,returntype) \ |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
164 |
typename ::CEREAL_RAPIDJSON_NAMESPACE::internal::EnableIf \ |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
165 |
<CEREAL_RAPIDJSON_REMOVEFPTR_(cond), \ |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
166 |
CEREAL_RAPIDJSON_REMOVEFPTR_(returntype)>::Type |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
167 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
168 |
#define CEREAL_RAPIDJSON_DISABLEIF_RETURN(cond,returntype) \ |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
169 |
typename ::CEREAL_RAPIDJSON_NAMESPACE::internal::DisableIf \ |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
170 |
<CEREAL_RAPIDJSON_REMOVEFPTR_(cond), \ |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
171 |
CEREAL_RAPIDJSON_REMOVEFPTR_(returntype)>::Type |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
172 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
173 |
} // namespace internal |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
174 |
CEREAL_RAPIDJSON_NAMESPACE_END |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
175 |
//@endcond |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
176 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
177 |
#if defined(__GNUC__) || defined(_MSC_VER) |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
178 |
CEREAL_RAPIDJSON_DIAG_POP |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
179 |
#endif |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
180 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
181 |
#endif // CEREAL_RAPIDJSON_INTERNAL_META_H_ |
|
|
1970-01-01 00:00 |
182 |
|