| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <functional> | 10 #include <functional> |
| 11 #include <type_traits> | 11 #include <type_traits> |
| 12 | 12 |
| 13 #include "mojo/public/cpp/bindings/enum_traits.h" |
| 13 #include "mojo/public/cpp/bindings/interface_id.h" | 14 #include "mojo/public/cpp/bindings/interface_id.h" |
| 14 #include "mojo/public/cpp/bindings/lib/template_util.h" | 15 #include "mojo/public/cpp/bindings/lib/template_util.h" |
| 15 #include "mojo/public/cpp/system/core.h" | 16 #include "mojo/public/cpp/system/core.h" |
| 16 | 17 |
| 17 namespace mojo { | 18 namespace mojo { |
| 18 | 19 |
| 19 template <typename T> | 20 template <typename T> |
| 20 class ArrayDataView; | 21 class ArrayDataView; |
| 21 | 22 |
| 22 template <typename T> | 23 template <typename T> |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 template <typename T> | 324 template <typename T> |
| 324 struct EnumHashImpl { | 325 struct EnumHashImpl { |
| 325 static_assert(std::is_enum<T>::value, "Incorrect hash function."); | 326 static_assert(std::is_enum<T>::value, "Incorrect hash function."); |
| 326 | 327 |
| 327 size_t operator()(T input) const { | 328 size_t operator()(T input) const { |
| 328 using UnderlyingType = typename std::underlying_type<T>::type; | 329 using UnderlyingType = typename std::underlying_type<T>::type; |
| 329 return std::hash<UnderlyingType>()(static_cast<UnderlyingType>(input)); | 330 return std::hash<UnderlyingType>()(static_cast<UnderlyingType>(input)); |
| 330 } | 331 } |
| 331 }; | 332 }; |
| 332 | 333 |
| 334 template <typename MojomType, typename T> |
| 335 T ConvertEnumValue(MojomType input) { |
| 336 T output; |
| 337 bool result = EnumTraits<MojomType, T>::FromMojom(input, &output); |
| 338 DCHECK(result); |
| 339 return output; |
| 340 } |
| 341 |
| 333 } // namespace internal | 342 } // namespace internal |
| 334 } // namespace mojo | 343 } // namespace mojo |
| 335 | 344 |
| 336 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_ | 345 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_ |
| OLD | NEW |