All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
meta.h
1 // Copyright (C) 2011 Milo Yip
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 // THE SOFTWARE.
20 
21 #ifndef RAPIDJSON_INTERNAL_META_H_
22 #define RAPIDJSON_INTERNAL_META_H_
23 
24 #ifdef __GNUC__
25 RAPIDJSON_DIAG_PUSH
26 RAPIDJSON_DIAG_OFF(effc++)
27 #endif
28 
29 //@cond RAPIDJSON_INTERNAL
30 namespace rapidjson {
31 namespace internal {
32 
33 template <int N> struct IntegralC { enum { Value = N }; };
34 template <bool Cond> struct BoolType : IntegralC<Cond> {};
35 struct TrueType : BoolType<true> {};
36 struct FalseType : BoolType<false> {};
37 
38 template <typename T> struct AddConst { typedef const T Type; };
39 template <typename T> struct RemoveConst { typedef T Type; };
40 template <typename T> struct RemoveConst<const T> { typedef T Type; };
41 
42 template <bool Condition, typename T1, typename T2> struct SelectIfCond;
43 template <typename T1, typename T2> struct SelectIfCond<true,T1,T2> { typedef T1 Type; };
44 template <typename T1, typename T2> struct SelectIfCond<false,T1,T2> { typedef T2 Type; };
45 
46 template <typename Condition, typename T1, typename T2>
47 struct SelectIf : SelectIfCond<Condition::Value,T1,T2> {};
48 
49 template <bool Constify, typename T>
50 struct MaybeAddConst : SelectIfCond<Constify, const T, T> {};
51 
52 template <typename T, typename U> struct IsSame : FalseType {};
53 template <typename T> struct IsSame<T,T> : TrueType {};
54 
55 template <typename T> struct IsConst : FalseType {};
56 template <typename T> struct IsConst<const T> : TrueType {};
57 
58 template <typename T> struct IsPointer : FalseType {};
59 template <typename T> struct IsPointer<T*> : TrueType {};
60 
61 template <typename CT, typename T>
62 struct IsMoreConst {
63  enum { Value =
65  && ( IsConst<CT>::Value >= IsConst<T>::Value ) )
66  };
67 };
68 
69 template <bool Condition, typename T = void> struct EnableIfCond;
70 template <typename T> struct EnableIfCond<true, T> { typedef T Type; };
71 template <typename T> struct EnableIfCond<false, T> { /* empty */ };
72 
73 template <bool Condition, typename T = void>
74 struct DisableIfCond : EnableIfCond<!Condition, T> {};
75 
76 template <typename Condition, typename T = void>
77 struct EnableIf : EnableIfCond<Condition::Value, T> {};
78 
79 template <typename Condition, typename T = void>
80 struct DisableIf : DisableIfCond<Condition::Value, T> {};
81 
82 // SFINAE helpers
83 struct SfinaeResultTag {};
84 template <typename T> struct RemoveSfinaeFptr {};
85 template <typename T> struct RemoveSfinaeFptr<SfinaeResultTag&(*)(T)> { typedef T Type; };
86 
87 #define RAPIDJSON_REMOVEFPTR_(type) \
88  typename ::rapidjson::internal::RemoveSfinaeFptr \
89  < ::rapidjson::internal::SfinaeResultTag&(*) type>::Type
90 
91 #define RAPIDJSON_ENABLEIF(cond) \
92  typename ::rapidjson::internal::EnableIf \
93  <RAPIDJSON_REMOVEFPTR_(cond)>::Type * = NULL
94 
95 #define RAPIDJSON_DISABLEIF_RETURN(cond,returntype) \
96  typename ::rapidjson::internal::DisableIf<cond,returntype>::Type
97 
98 } // namespace internal
99 } // namespace rapidjson
100 //@endcond
101 
102 #ifdef __GNUC__
103 RAPIDJSON_DIAG_POP
104 #endif
105 
106 #endif // RAPIDJSON_INTERNAL_META_H_
Type
Type of JSON value.
Definition: rapidjson.h:420
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:1401