meta.h
Go to the documentation of this file.
1 // Tencent is pleased to support the open source community by making RapidJSON
2 // available.
3 //
4 // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All
5 // rights reserved.
6 //
7 // Licensed under the MIT License (the "License"); you may not use this file
8 // except in compliance with the License. You may obtain a copy of the License
9 // at
10 //
11 // http://opensource.org/licenses/MIT
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16 // License for the specific language governing permissions and limitations under
17 // the License.
18 
19 #ifndef RAPIDJSON_INTERNAL_META_H_
20 #define RAPIDJSON_INTERNAL_META_H_
21 
22 #include "../rapidjson.h"
23 
24 #ifdef __GNUC__
25 RAPIDJSON_DIAG_PUSH
26 RAPIDJSON_DIAG_OFF(effc++)
27 #endif
28 
29 #if defined(_MSC_VER) && !defined(__clang__)
30 RAPIDJSON_DIAG_PUSH
31 RAPIDJSON_DIAG_OFF(6334)
32 #endif
33 
34 #if RAPIDJSON_HAS_CXX11_TYPETRAITS
35 #include <type_traits>
36 #endif
37 
38 //@cond RAPIDJSON_INTERNAL
40 namespace internal {
41 
42 // Helper to wrap/convert arbitrary types to void, useful for arbitrary type
43 // matching
44 template <typename T>
45 struct Void {
46  typedef void Type;
47 };
48 
50 // BoolType, TrueType, FalseType
51 //
52 template <bool Cond>
53 struct BoolType {
54  static const bool Value = Cond;
55  typedef BoolType Type;
56 };
57 typedef BoolType<true> TrueType;
58 typedef BoolType<false> FalseType;
59 
61 // SelectIf, BoolExpr, NotExpr, AndExpr, OrExpr
62 //
63 
64 template <bool C>
65 struct SelectIfImpl {
66  template <typename T1, typename T2>
67  struct Apply {
68  typedef T1 Type;
69  };
70 };
71 template <>
72 struct SelectIfImpl<false> {
73  template <typename T1, typename T2>
74  struct Apply {
75  typedef T2 Type;
76  };
77 };
78 template <bool C, typename T1, typename T2>
79 struct SelectIfCond : SelectIfImpl<C>::template Apply<T1, T2> {};
80 template <typename C, typename T1, typename T2>
81 struct SelectIf : SelectIfCond<C::Value, T1, T2> {};
82 
83 template <bool Cond1, bool Cond2>
84 struct AndExprCond : FalseType {};
85 template <>
86 struct AndExprCond<true, true> : TrueType {};
87 template <bool Cond1, bool Cond2>
88 struct OrExprCond : TrueType {};
89 template <>
90 struct OrExprCond<false, false> : FalseType {};
91 
92 template <typename C>
93 struct BoolExpr : SelectIf<C, TrueType, FalseType>::Type {};
94 template <typename C>
95 struct NotExpr : SelectIf<C, FalseType, TrueType>::Type {};
96 template <typename C1, typename C2>
97 struct AndExpr : AndExprCond<C1::Value, C2::Value>::Type {};
98 template <typename C1, typename C2>
99 struct OrExpr : OrExprCond<C1::Value, C2::Value>::Type {};
100 
102 // AddConst, MaybeAddConst, RemoveConst
103 template <typename T>
104 struct AddConst {
105  typedef const T Type;
106 };
107 template <bool Constify, typename T>
108 struct MaybeAddConst : SelectIfCond<Constify, const T, T> {};
109 template <typename T>
110 struct RemoveConst {
111  typedef T Type;
112 };
113 template <typename T>
114 struct RemoveConst<const T> {
115  typedef T Type;
116 };
117 
119 // IsSame, IsConst, IsMoreConst, IsPointer
120 //
121 template <typename T, typename U>
122 struct IsSame : FalseType {};
123 template <typename T>
124 struct IsSame<T, T> : TrueType {};
125 
126 template <typename T>
127 struct IsConst : FalseType {};
128 template <typename T>
129 struct IsConst<const T> : TrueType {};
130 
131 template <typename CT, typename T>
132 struct IsMoreConst
133  : AndExpr<
134  IsSame<typename RemoveConst<CT>::Type, typename RemoveConst<T>::Type>,
135  BoolType<IsConst<CT>::Value >= IsConst<T>::Value>>::Type {};
136 
137 template <typename T>
138 struct IsPointer : FalseType {};
139 template <typename T>
140 struct IsPointer<T *> : TrueType {};
141 
143 // IsBaseOf
144 //
145 #if RAPIDJSON_HAS_CXX11_TYPETRAITS
146 
147 template <typename B, typename D>
148 struct IsBaseOf : BoolType<::std::is_base_of<B, D>::value> {};
149 
150 #else // simplified version adopted from Boost
151 
152 template <typename B, typename D>
153 struct IsBaseOfImpl {
154  RAPIDJSON_STATIC_ASSERT(sizeof(B) != 0);
155  RAPIDJSON_STATIC_ASSERT(sizeof(D) != 0);
156 
157  typedef char (&Yes)[1];
158  typedef char (&No)[2];
159 
160  template <typename T>
161  static Yes Check(const D *, T);
162  static No Check(const B *, int);
163 
164  struct Host {
165  operator const B *() const;
166  operator const D *();
167  };
168 
169  enum { Value = (sizeof(Check(Host(), 0)) == sizeof(Yes)) };
170 };
171 
172 template <typename B, typename D>
173 struct IsBaseOf : OrExpr<IsSame<B, D>, BoolExpr<IsBaseOfImpl<B, D>>>::Type {};
174 
175 #endif // RAPIDJSON_HAS_CXX11_TYPETRAITS
176 
178 // EnableIf / DisableIf
179 //
180 template <bool Condition, typename T = void>
181 struct EnableIfCond {
182  typedef T Type;
183 };
184 template <typename T>
185 struct EnableIfCond<false, T> { /* empty */
186 };
187 
188 template <bool Condition, typename T = void>
189 struct DisableIfCond {
190  typedef T Type;
191 };
192 template <typename T>
193 struct DisableIfCond<true, T> { /* empty */
194 };
195 
196 template <typename Condition, typename T = void>
197 struct EnableIf : EnableIfCond<Condition::Value, T> {};
198 
199 template <typename Condition, typename T = void>
200 struct DisableIf : DisableIfCond<Condition::Value, T> {};
201 
202 // SFINAE helpers
203 struct SfinaeTag {};
204 template <typename T>
205 struct RemoveSfinaeTag;
206 template <typename T>
207 struct RemoveSfinaeTag<SfinaeTag &(*)(T)> {
208  typedef T Type;
209 };
210 
211 #define RAPIDJSON_REMOVEFPTR_(type) \
212  typename ::RAPIDJSON_NAMESPACE::internal::RemoveSfinaeTag< \
213  ::RAPIDJSON_NAMESPACE::internal::SfinaeTag &(*)type>::Type
214 
215 #define RAPIDJSON_ENABLEIF(cond) \
216  typename ::RAPIDJSON_NAMESPACE::internal::EnableIf<RAPIDJSON_REMOVEFPTR_( \
217  cond)>::Type * = NULL
218 
219 #define RAPIDJSON_DISABLEIF(cond) \
220  typename ::RAPIDJSON_NAMESPACE::internal::DisableIf<RAPIDJSON_REMOVEFPTR_( \
221  cond)>::Type * = NULL
222 
223 #define RAPIDJSON_ENABLEIF_RETURN(cond, returntype) \
224  typename ::RAPIDJSON_NAMESPACE::internal::EnableIf< \
225  RAPIDJSON_REMOVEFPTR_(cond), RAPIDJSON_REMOVEFPTR_(returntype)>::Type
226 
227 #define RAPIDJSON_DISABLEIF_RETURN(cond, returntype) \
228  typename ::RAPIDJSON_NAMESPACE::internal::DisableIf< \
229  RAPIDJSON_REMOVEFPTR_(cond), RAPIDJSON_REMOVEFPTR_(returntype)>::Type
230 
231 } // namespace internal
233 //@endcond
234 
235 #if defined(_MSC_VER) && !defined(__clang__)
236 RAPIDJSON_DIAG_POP
237 #endif
238 
239 #ifdef __GNUC__
240 RAPIDJSON_DIAG_POP
241 #endif
242 
243 #endif // RAPIDJSON_INTERNAL_META_H_
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:131
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition: document.h:59
#define RAPIDJSON_STATIC_ASSERT(x)
(Internal) macro to check for conditions at compile-time
Definition: rapidjson.h:476
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:128
Type
Type of JSON value.
Definition: rapidjson.h:707


livox_ros_driver
Author(s): Livox Dev Team
autogenerated on Mon Mar 15 2021 02:40:46