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

Side by Side Diff: mojo/public/cpp/bindings/tests/struct_with_traits_impl_traits.h

Issue 1821073002: Mojo bindings: Fix typemap includes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_TESTS_STRUCT_WITH_TRAITS_IMPL_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_TESTS_STRUCT_WITH_TRAITS_IMPL_TRAITS_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_STRUCT_WITH_TRAITS_IMPL_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_STRUCT_WITH_TRAITS_IMPL_TRAITS_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <string> 10 #include <string>
11 11
12 #include "base/strings/string_piece.h" 12 #include "base/strings/string_piece.h"
13 #include "mojo/public/cpp/bindings/struct_traits.h" 13 #include "mojo/public/cpp/bindings/struct_traits.h"
14 #include "mojo/public/cpp/bindings/tests/struct_with_traits_impl.h"
14 15
15 namespace mojo { 16 namespace mojo {
16 namespace test {
17
18 // The mojom types are forward-declared to avoid circular dependencies between
19 // this and generated headers.
20 class StructWithTraits;
21 class StructWithTraits_Reader;
22
23 // A type which knows how to look like a mojo::test::StructWithTraits mojom type
24 // by way of mojo::StructTraits.
25 class StructWithTraitsImpl {
26 public:
27 StructWithTraitsImpl();
28 ~StructWithTraitsImpl();
29
30 void set_bool(bool value) { bool_ = value; }
31 bool get_bool() const { return bool_; }
32
33 void set_uint32(uint32_t value) { uint32_ = value; }
34 uint32_t get_uint32() const { return uint32_; }
35
36 void set_uint64(uint64_t value) { uint64_ = value; }
37 uint64_t get_uint64() const { return uint64_; }
38
39 void set_string(std::string value) { string_ = value; }
40 base::StringPiece get_string() const { return string_; }
41
42 private:
43 bool bool_ = false;
44 uint32_t uint32_ = 0;
45 uint64_t uint64_ = 0;
46 std::string string_;
47 };
48
49 } // namespace test
50 17
51 template <> 18 template <>
52 struct StructTraits<test::StructWithTraits, test::StructWithTraitsImpl> { 19 struct StructTraits<test::StructWithTraits, test::StructWithTraitsImpl> {
53 // Deserialization to test::StructTraitsImpl. 20 // Deserialization to test::StructTraitsImpl.
54 static bool Read(test::StructWithTraits_Reader r, 21 static bool Read(test::StructWithTraits_Reader r,
55 test::StructWithTraitsImpl* out); 22 test::StructWithTraitsImpl* out);
56 23
57 // Fields in test::StructWithTraits. 24 // Fields in test::StructWithTraits.
58 // See src/mojo/public/interfaces/bindings/tests/test_native_types.mojom. 25 // See src/mojo/public/interfaces/bindings/tests/test_native_types.mojom.
59 static bool f_bool(const test::StructWithTraitsImpl& value) { 26 static bool f_bool(const test::StructWithTraitsImpl& value) {
60 return value.get_bool(); 27 return value.get_bool();
61 } 28 }
62 29
63 static uint32_t f_uint32(const test::StructWithTraitsImpl& value) { 30 static uint32_t f_uint32(const test::StructWithTraitsImpl& value) {
64 return value.get_uint32(); 31 return value.get_uint32();
65 } 32 }
66 33
67 static uint64_t f_uint64(const test::StructWithTraitsImpl& value) { 34 static uint64_t f_uint64(const test::StructWithTraitsImpl& value) {
68 return value.get_uint64(); 35 return value.get_uint64();
69 } 36 }
70 37
71 static base::StringPiece f_string(const test::StructWithTraitsImpl& value) { 38 static base::StringPiece f_string(const test::StructWithTraitsImpl& value) {
72 return value.get_string(); 39 return value.get_string();
73 } 40 }
74 }; 41 };
75 42
76 } // namespace mojo 43 } // namespace mojo
77 44
78 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_STRUCT_WITH_TRAITS_IMPL_H_ 45 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_STRUCT_WITH_TRAITS_IMPL_TRAITS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698