| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_ |
| 7 | 7 |
| 8 #include <type_traits> |
| 9 |
| 8 #include "mojo/public/cpp/bindings/lib/template_util.h" | 10 #include "mojo/public/cpp/bindings/lib/template_util.h" |
| 9 #include "mojo/public/cpp/bindings/struct_ptr.h" | 11 #include "mojo/public/cpp/bindings/struct_ptr.h" |
| 10 #include "mojo/public/cpp/system/core.h" | 12 #include "mojo/public/cpp/system/core.h" |
| 11 | 13 |
| 12 namespace mojo { | 14 namespace mojo { |
| 13 class String; | 15 class String; |
| 14 | 16 |
| 15 template <typename T> | 17 template <typename T> |
| 16 class Array; | 18 class Array; |
| 17 | 19 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 81 |
| 80 template <typename T> | 82 template <typename T> |
| 81 T FetchAndReset(T* ptr) { | 83 T FetchAndReset(T* ptr) { |
| 82 T temp = *ptr; | 84 T temp = *ptr; |
| 83 *ptr = T(); | 85 *ptr = T(); |
| 84 return temp; | 86 return temp; |
| 85 } | 87 } |
| 86 | 88 |
| 87 template <typename H> | 89 template <typename H> |
| 88 struct IsHandle { | 90 struct IsHandle { |
| 89 enum { value = IsBaseOf<Handle, H>::value }; | 91 enum { value = std::is_base_of<Handle, H>::value }; |
| 90 }; | 92 }; |
| 91 | 93 |
| 92 template <typename T> | 94 template <typename T> |
| 93 struct RemoveStructPtr { | 95 struct RemoveStructPtr { |
| 94 typedef T type; | 96 typedef T type; |
| 95 }; | 97 }; |
| 96 | 98 |
| 97 template <typename T> | 99 template <typename T> |
| 98 struct RemoveStructPtr<StructPtr<T>> { | 100 struct RemoveStructPtr<StructPtr<T>> { |
| 99 typedef T type; | 101 typedef T type; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 144 |
| 143 template <typename T> | 145 template <typename T> |
| 144 struct IsUnionWrapperType { | 146 struct IsUnionWrapperType { |
| 145 template <typename U> | 147 template <typename U> |
| 146 static YesType Test(const typename U::Data_::MojomUnionDataType*); | 148 static YesType Test(const typename U::Data_::MojomUnionDataType*); |
| 147 | 149 |
| 148 template <typename U> | 150 template <typename U> |
| 149 static NoType Test(...); | 151 static NoType Test(...); |
| 150 | 152 |
| 151 static const bool value = | 153 static const bool value = |
| 152 sizeof(Test<T>(0)) == sizeof(YesType) && !IsConst<T>::value; | 154 sizeof(Test<T>(0)) == sizeof(YesType) && !std::is_const<T>::value; |
| 153 }; | 155 }; |
| 154 | 156 |
| 155 template <typename T> | 157 template <typename T> |
| 156 struct IsUnionDataType { | 158 struct IsUnionDataType { |
| 157 template <typename U> | 159 template <typename U> |
| 158 static YesType Test(const typename U::MojomUnionDataType*); | 160 static YesType Test(const typename U::MojomUnionDataType*); |
| 159 | 161 |
| 160 template <typename U> | 162 template <typename U> |
| 161 static NoType Test(...); | 163 static NoType Test(...); |
| 162 | 164 |
| 163 static const bool value = | 165 static const bool value = |
| 164 sizeof(Test<T>(0)) == sizeof(YesType) && !IsConst<T>::value; | 166 sizeof(Test<T>(0)) == sizeof(YesType) && !std::is_const<T>::value; |
| 165 }; | 167 }; |
| 166 | 168 |
| 167 template <typename T, | 169 template <typename T, |
| 168 bool move_only = IsMoveOnlyType<T>::value, | 170 bool move_only = IsMoveOnlyType<T>::value, |
| 169 bool is_union = | 171 bool is_union = |
| 170 IsUnionWrapperType<typename RemoveStructPtr<T>::type>::value> | 172 IsUnionWrapperType<typename RemoveStructPtr<T>::type>::value> |
| 171 struct WrapperTraits; | 173 struct WrapperTraits; |
| 172 | 174 |
| 173 template <typename T> | 175 template <typename T> |
| 174 struct WrapperTraits<T, false, false> { | 176 struct WrapperTraits<T, false, false> { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 198 struct WrapperTraits<S, true, false> { | 200 struct WrapperTraits<S, true, false> { |
| 199 typedef typename S::Data_* DataType; | 201 typedef typename S::Data_* DataType; |
| 200 }; | 202 }; |
| 201 | 203 |
| 202 template <typename T, typename Enable = void> | 204 template <typename T, typename Enable = void> |
| 203 struct ValueTraits { | 205 struct ValueTraits { |
| 204 static bool Equals(const T& a, const T& b) { return a == b; } | 206 static bool Equals(const T& a, const T& b) { return a == b; } |
| 205 }; | 207 }; |
| 206 | 208 |
| 207 template <typename T> | 209 template <typename T> |
| 208 struct ValueTraits< | 210 struct ValueTraits<T, |
| 209 T, | 211 typename std::enable_if< |
| 210 typename EnableIf<IsSpecializationOf<Array, T>::value || | 212 IsSpecializationOf<Array, T>::value || |
| 211 IsSpecializationOf<Map, T>::value || | 213 IsSpecializationOf<Map, T>::value || |
| 212 IsSpecializationOf<StructPtr, T>::value || | 214 IsSpecializationOf<StructPtr, T>::value || |
| 213 IsSpecializationOf<InlinedStructPtr, T>::value>::type> { | 215 IsSpecializationOf<InlinedStructPtr, T>::value>::type> { |
| 214 static bool Equals(const T& a, const T& b) { return a.Equals(b); } | 216 static bool Equals(const T& a, const T& b) { return a.Equals(b); } |
| 215 }; | 217 }; |
| 216 | 218 |
| 217 template <typename T> | 219 template <typename T> |
| 218 struct ValueTraits<ScopedHandleBase<T>> { | 220 struct ValueTraits<ScopedHandleBase<T>> { |
| 219 static bool Equals(const ScopedHandleBase<T>& a, | 221 static bool Equals(const ScopedHandleBase<T>& a, |
| 220 const ScopedHandleBase<T>& b) { | 222 const ScopedHandleBase<T>& b) { |
| 221 return a.get().value() == b.get().value(); | 223 return a.get().value() == b.get().value(); |
| 222 } | 224 } |
| 223 }; | 225 }; |
| 224 | 226 |
| 225 } // namespace internal | 227 } // namespace internal |
| 226 } // namespace mojo | 228 } // namespace mojo |
| 227 | 229 |
| 228 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_ | 230 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_ |
| OLD | NEW |