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

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

Issue 2146153002: Mojo typemap config: support "copyable_pass_by_value" attribute. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@69_change_move_only
Patch Set: . Created 4 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
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>
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 return value.get_struct_array(); 86 return value.get_struct_array();
87 } 87 }
88 88
89 static const std::map<std::string, test::NestedStructWithTraitsImpl>& 89 static const std::map<std::string, test::NestedStructWithTraitsImpl>&
90 f_struct_map(const test::StructWithTraitsImpl& value) { 90 f_struct_map(const test::StructWithTraitsImpl& value) {
91 return value.get_struct_map(); 91 return value.get_struct_map();
92 } 92 }
93 }; 93 };
94 94
95 template <> 95 template <>
96 struct StructTraits<test::PassByValueStructWithTraits, 96 struct StructTraits<test::TrivialStructWithTraits,
97 test::PassByValueStructWithTraitsImpl> { 97 test::TrivialStructWithTraitsImpl> {
98 // Deserialization to test::PassByValueStructTraitsImpl. 98 // Deserialization to test::TrivialStructTraitsImpl.
99 static bool Read(test::PassByValueStructWithTraits::DataView data, 99 static bool Read(test::TrivialStructWithTraits::DataView data,
100 test::PassByValueStructWithTraitsImpl* out); 100 test::TrivialStructWithTraitsImpl* out) {
101 out->value = data.value();
102 return true;
103 }
101 104
102 // Fields in test::PassByValueStructWithTraits. 105 // Fields in test::TrivialStructWithTraits.
103 // See src/mojo/public/interfaces/bindings/tests/struct_with_traits.mojom. 106 // See src/mojo/public/interfaces/bindings/tests/struct_with_traits.mojom.
104 static ScopedHandle f_handle(test::PassByValueStructWithTraitsImpl& value) { 107 static int32_t value(test::TrivialStructWithTraitsImpl& input) {
108 return input.value;
109 }
110 };
111
112 template <>
113 struct StructTraits<test::MoveOnlyStructWithTraits,
114 test::MoveOnlyStructWithTraitsImpl> {
115 // Deserialization to test::MoveOnlyStructTraitsImpl.
116 static bool Read(test::MoveOnlyStructWithTraits::DataView data,
117 test::MoveOnlyStructWithTraitsImpl* out);
118
119 // Fields in test::MoveOnlyStructWithTraits.
120 // See src/mojo/public/interfaces/bindings/tests/struct_with_traits.mojom.
121 static ScopedHandle f_handle(test::MoveOnlyStructWithTraitsImpl& value) {
105 return std::move(value.get_mutable_handle()); 122 return std::move(value.get_mutable_handle());
106 } 123 }
107 }; 124 };
108 125
109 template <> 126 template <>
110 struct StructTraits<test::StructWithTraitsForUniquePtrTest, 127 struct StructTraits<test::StructWithTraitsForUniquePtrTest,
111 std::unique_ptr<int>> { 128 std::unique_ptr<int>> {
112 static int f_int32(const std::unique_ptr<int>& data) { return *data; } 129 static int f_int32(const std::unique_ptr<int>& data) { return *data; }
113 130
114 static bool Read(test::StructWithTraitsForUniquePtrTest::DataView data, 131 static bool Read(test::StructWithTraitsForUniquePtrTest::DataView data,
115 std::unique_ptr<int>* out) { 132 std::unique_ptr<int>* out) {
116 out->reset(new int(data.f_int32())); 133 out->reset(new int(data.f_int32()));
117 return true; 134 return true;
118 } 135 }
119 }; 136 };
120 137
121 } // namespace mojo 138 } // namespace mojo
122 139
123 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_STRUCT_WITH_TRAITS_IMPL_TRAITS_H_ 140 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_STRUCT_WITH_TRAITS_IMPL_TRAITS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698