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

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

Issue 2253293002: Mojo C++ bindings: change the first template parameter of StructTraits and UnionTraits. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@91_extra
Patch Set: rebase Created 4 years, 4 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_TRAITS_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_TRAITS_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 #include <vector> 11 #include <vector>
12 12
13 #include "base/strings/string_piece.h" 13 #include "base/strings/string_piece.h"
14 #include "mojo/public/cpp/bindings/struct_traits.h" 14 #include "mojo/public/cpp/bindings/struct_traits.h"
15 #include "mojo/public/cpp/bindings/tests/struct_with_traits_impl.h" 15 #include "mojo/public/cpp/bindings/tests/struct_with_traits_impl.h"
16 #include "mojo/public/interfaces/bindings/tests/struct_with_traits.mojom.h" 16 #include "mojo/public/interfaces/bindings/tests/struct_with_traits.mojom.h"
17 17
18 namespace mojo { 18 namespace mojo {
19 19
20 template <> 20 template <>
21 struct StructTraits<test::NestedStructWithTraits, 21 struct StructTraits<test::NestedStructWithTraitsDataView,
22 test::NestedStructWithTraitsImpl> { 22 test::NestedStructWithTraitsImpl> {
23 static void* SetUpContext(const test::NestedStructWithTraitsImpl& input); 23 static void* SetUpContext(const test::NestedStructWithTraitsImpl& input);
24 static void TearDownContext(const test::NestedStructWithTraitsImpl& input, 24 static void TearDownContext(const test::NestedStructWithTraitsImpl& input,
25 void* context); 25 void* context);
26 26
27 static int32_t value(const test::NestedStructWithTraitsImpl& input, 27 static int32_t value(const test::NestedStructWithTraitsImpl& input,
28 void* context); 28 void* context);
29 29
30 static bool Read(test::NestedStructWithTraits::DataView data, 30 static bool Read(test::NestedStructWithTraitsDataView data,
31 test::NestedStructWithTraitsImpl* output); 31 test::NestedStructWithTraitsImpl* output);
32 }; 32 };
33 33
34 template <> 34 template <>
35 struct EnumTraits<test::EnumWithTraits, test::EnumWithTraitsImpl> { 35 struct EnumTraits<test::EnumWithTraits, test::EnumWithTraitsImpl> {
36 static test::EnumWithTraits ToMojom(test::EnumWithTraitsImpl input); 36 static test::EnumWithTraits ToMojom(test::EnumWithTraitsImpl input);
37 static bool FromMojom(test::EnumWithTraits input, 37 static bool FromMojom(test::EnumWithTraits input,
38 test::EnumWithTraitsImpl* output); 38 test::EnumWithTraitsImpl* output);
39 }; 39 };
40 40
41 template <> 41 template <>
42 struct StructTraits<test::StructWithTraits, test::StructWithTraitsImpl> { 42 struct StructTraits<test::StructWithTraitsDataView,
43 test::StructWithTraitsImpl> {
43 // Deserialization to test::StructTraitsImpl. 44 // Deserialization to test::StructTraitsImpl.
44 static bool Read(test::StructWithTraits::DataView data, 45 static bool Read(test::StructWithTraitsDataView data,
45 test::StructWithTraitsImpl* out); 46 test::StructWithTraitsImpl* out);
46 47
47 // Fields in test::StructWithTraits. 48 // Fields in test::StructWithTraits.
48 // See src/mojo/public/interfaces/bindings/tests/struct_with_traits.mojom. 49 // See src/mojo/public/interfaces/bindings/tests/struct_with_traits.mojom.
49 static test::EnumWithTraitsImpl f_enum( 50 static test::EnumWithTraitsImpl f_enum(
50 const test::StructWithTraitsImpl& value) { 51 const test::StructWithTraitsImpl& value) {
51 return value.get_enum(); 52 return value.get_enum();
52 } 53 }
53 54
54 static bool f_bool(const test::StructWithTraitsImpl& value) { 55 static bool f_bool(const test::StructWithTraitsImpl& value) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 return value.get_struct_array(); 92 return value.get_struct_array();
92 } 93 }
93 94
94 static const std::map<std::string, test::NestedStructWithTraitsImpl>& 95 static const std::map<std::string, test::NestedStructWithTraitsImpl>&
95 f_struct_map(const test::StructWithTraitsImpl& value) { 96 f_struct_map(const test::StructWithTraitsImpl& value) {
96 return value.get_struct_map(); 97 return value.get_struct_map();
97 } 98 }
98 }; 99 };
99 100
100 template <> 101 template <>
101 struct StructTraits<test::TrivialStructWithTraits, 102 struct StructTraits<test::TrivialStructWithTraitsDataView,
102 test::TrivialStructWithTraitsImpl> { 103 test::TrivialStructWithTraitsImpl> {
103 // Deserialization to test::TrivialStructTraitsImpl. 104 // Deserialization to test::TrivialStructTraitsImpl.
104 static bool Read(test::TrivialStructWithTraits::DataView data, 105 static bool Read(test::TrivialStructWithTraitsDataView data,
105 test::TrivialStructWithTraitsImpl* out) { 106 test::TrivialStructWithTraitsImpl* out) {
106 out->value = data.value(); 107 out->value = data.value();
107 return true; 108 return true;
108 } 109 }
109 110
110 // Fields in test::TrivialStructWithTraits. 111 // Fields in test::TrivialStructWithTraits.
111 // See src/mojo/public/interfaces/bindings/tests/struct_with_traits.mojom. 112 // See src/mojo/public/interfaces/bindings/tests/struct_with_traits.mojom.
112 static int32_t value(test::TrivialStructWithTraitsImpl& input) { 113 static int32_t value(test::TrivialStructWithTraitsImpl& input) {
113 return input.value; 114 return input.value;
114 } 115 }
115 }; 116 };
116 117
117 template <> 118 template <>
118 struct StructTraits<test::MoveOnlyStructWithTraits, 119 struct StructTraits<test::MoveOnlyStructWithTraitsDataView,
119 test::MoveOnlyStructWithTraitsImpl> { 120 test::MoveOnlyStructWithTraitsImpl> {
120 // Deserialization to test::MoveOnlyStructTraitsImpl. 121 // Deserialization to test::MoveOnlyStructTraitsImpl.
121 static bool Read(test::MoveOnlyStructWithTraits::DataView data, 122 static bool Read(test::MoveOnlyStructWithTraitsDataView data,
122 test::MoveOnlyStructWithTraitsImpl* out); 123 test::MoveOnlyStructWithTraitsImpl* out);
123 124
124 // Fields in test::MoveOnlyStructWithTraits. 125 // Fields in test::MoveOnlyStructWithTraits.
125 // See src/mojo/public/interfaces/bindings/tests/struct_with_traits.mojom. 126 // See src/mojo/public/interfaces/bindings/tests/struct_with_traits.mojom.
126 static ScopedHandle f_handle(test::MoveOnlyStructWithTraitsImpl& value) { 127 static ScopedHandle f_handle(test::MoveOnlyStructWithTraitsImpl& value) {
127 return std::move(value.get_mutable_handle()); 128 return std::move(value.get_mutable_handle());
128 } 129 }
129 }; 130 };
130 131
131 template <> 132 template <>
132 struct StructTraits<test::StructWithTraitsForUniquePtr, std::unique_ptr<int>> { 133 struct StructTraits<test::StructWithTraitsForUniquePtrDataView,
134 std::unique_ptr<int>> {
133 static bool IsNull(const std::unique_ptr<int>& data) { return !data; } 135 static bool IsNull(const std::unique_ptr<int>& data) { return !data; }
134 static void SetToNull(std::unique_ptr<int>* data) { data->reset(); } 136 static void SetToNull(std::unique_ptr<int>* data) { data->reset(); }
135 137
136 static int f_int32(const std::unique_ptr<int>& data) { return *data; } 138 static int f_int32(const std::unique_ptr<int>& data) { return *data; }
137 139
138 static bool Read(test::StructWithTraitsForUniquePtr::DataView data, 140 static bool Read(test::StructWithTraitsForUniquePtrDataView data,
139 std::unique_ptr<int>* out) { 141 std::unique_ptr<int>* out) {
140 out->reset(new int(data.f_int32())); 142 out->reset(new int(data.f_int32()));
141 return true; 143 return true;
142 } 144 }
143 }; 145 };
144 146
145 template <> 147 template <>
146 struct UnionTraits<test::UnionWithTraits, 148 struct UnionTraits<test::UnionWithTraitsDataView,
147 std::unique_ptr<test::UnionWithTraitsBase>> { 149 std::unique_ptr<test::UnionWithTraitsBase>> {
148 static bool IsNull(const std::unique_ptr<test::UnionWithTraitsBase>& data) { 150 static bool IsNull(const std::unique_ptr<test::UnionWithTraitsBase>& data) {
149 return !data; 151 return !data;
150 } 152 }
151 static void SetToNull(std::unique_ptr<test::UnionWithTraitsBase>* data) { 153 static void SetToNull(std::unique_ptr<test::UnionWithTraitsBase>* data) {
152 data->reset(); 154 data->reset();
153 } 155 }
154 156
155 static test::UnionWithTraits::DataView::Tag GetTag( 157 static test::UnionWithTraitsDataView::Tag GetTag(
156 const std::unique_ptr<test::UnionWithTraitsBase>& data) { 158 const std::unique_ptr<test::UnionWithTraitsBase>& data) {
157 if (data->type() == test::UnionWithTraitsBase::Type::INT32) 159 if (data->type() == test::UnionWithTraitsBase::Type::INT32)
158 return test::UnionWithTraits::DataView::Tag::F_INT32; 160 return test::UnionWithTraitsDataView::Tag::F_INT32;
159 161
160 return test::UnionWithTraits::DataView::Tag::F_STRUCT; 162 return test::UnionWithTraitsDataView::Tag::F_STRUCT;
161 } 163 }
162 164
163 static int32_t f_int32( 165 static int32_t f_int32(
164 const std::unique_ptr<test::UnionWithTraitsBase>& data) { 166 const std::unique_ptr<test::UnionWithTraitsBase>& data) {
165 return static_cast<test::UnionWithTraitsInt32*>(data.get())->value(); 167 return static_cast<test::UnionWithTraitsInt32*>(data.get())->value();
166 } 168 }
167 169
168 static const test::NestedStructWithTraitsImpl& f_struct( 170 static const test::NestedStructWithTraitsImpl& f_struct(
169 const std::unique_ptr<test::UnionWithTraitsBase>& data) { 171 const std::unique_ptr<test::UnionWithTraitsBase>& data) {
170 return static_cast<test::UnionWithTraitsStruct*>(data.get())->get_struct(); 172 return static_cast<test::UnionWithTraitsStruct*>(data.get())->get_struct();
171 } 173 }
172 174
173 static bool Read(test::UnionWithTraits::DataView data, 175 static bool Read(test::UnionWithTraitsDataView data,
174 std::unique_ptr<test::UnionWithTraitsBase>* out) { 176 std::unique_ptr<test::UnionWithTraitsBase>* out) {
175 switch (data.tag()) { 177 switch (data.tag()) {
176 case test::UnionWithTraits::DataView::Tag::F_INT32: { 178 case test::UnionWithTraitsDataView::Tag::F_INT32: {
177 out->reset(new test::UnionWithTraitsInt32(data.f_int32())); 179 out->reset(new test::UnionWithTraitsInt32(data.f_int32()));
178 return true; 180 return true;
179 } 181 }
180 case test::UnionWithTraits::DataView::Tag::F_STRUCT: { 182 case test::UnionWithTraitsDataView::Tag::F_STRUCT: {
181 auto* struct_object = new test::UnionWithTraitsStruct(); 183 auto* struct_object = new test::UnionWithTraitsStruct();
182 out->reset(struct_object); 184 out->reset(struct_object);
183 return data.ReadFStruct(&struct_object->get_mutable_struct()); 185 return data.ReadFStruct(&struct_object->get_mutable_struct());
184 } 186 }
185 } 187 }
186 188
187 NOTREACHED(); 189 NOTREACHED();
188 return false; 190 return false;
189 } 191 }
190 }; 192 };
191 193
192 } // namespace mojo 194 } // namespace mojo
193 195
194 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_STRUCT_WITH_TRAITS_IMPL_TRAITS_H_ 196 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_STRUCT_WITH_TRAITS_IMPL_TRAITS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698