Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: mojo/public/cpp/bindings/lib/bindings_internal.h

Issue 2965663002: Mojo C++ bindings: support setting default value for fields whose types are typemapped enums. (Closed)
Patch Set: . Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/tests/struct_traits_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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_
OLDNEW
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/tests/struct_traits_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698