OLD | NEW |
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_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_STRUCT_WITH_TRAITS_IMPL_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_STRUCT_WITH_TRAITS_IMPL_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
| 11 #include <vector> |
11 | 12 |
12 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
13 | 14 |
14 namespace mojo { | 15 namespace mojo { |
15 namespace test { | 16 namespace test { |
16 | 17 |
| 18 struct NestedStructWithTraitsImpl { |
| 19 public: |
| 20 bool operator==(const NestedStructWithTraitsImpl& other) const { |
| 21 return value == other.value; |
| 22 } |
| 23 |
| 24 int32_t value = 0; |
| 25 }; |
| 26 |
17 // A type which knows how to look like a mojo::test::StructWithTraits mojom type | 27 // A type which knows how to look like a mojo::test::StructWithTraits mojom type |
18 // by way of mojo::StructTraits. | 28 // by way of mojo::StructTraits. |
19 class StructWithTraitsImpl { | 29 class StructWithTraitsImpl { |
20 public: | 30 public: |
21 StructWithTraitsImpl(); | 31 StructWithTraitsImpl(); |
22 ~StructWithTraitsImpl(); | 32 ~StructWithTraitsImpl(); |
23 | 33 |
24 void set_bool(bool value) { bool_ = value; } | 34 void set_bool(bool value) { bool_ = value; } |
25 bool get_bool() const { return bool_; } | 35 bool get_bool() const { return bool_; } |
26 | 36 |
27 void set_uint32(uint32_t value) { uint32_ = value; } | 37 void set_uint32(uint32_t value) { uint32_ = value; } |
28 uint32_t get_uint32() const { return uint32_; } | 38 uint32_t get_uint32() const { return uint32_; } |
29 | 39 |
30 void set_uint64(uint64_t value) { uint64_ = value; } | 40 void set_uint64(uint64_t value) { uint64_ = value; } |
31 uint64_t get_uint64() const { return uint64_; } | 41 uint64_t get_uint64() const { return uint64_; } |
32 | 42 |
33 void set_string(std::string value) { string_ = value; } | 43 void set_string(std::string value) { string_ = value; } |
34 base::StringPiece get_string() const { return string_; } | 44 base::StringPiece get_string_as_string_piece() const { return string_; } |
| 45 const std::string& get_string() const { return string_; } |
| 46 |
| 47 const std::vector<std::string>& get_string_array() const { |
| 48 return string_array_; |
| 49 } |
| 50 std::vector<std::string>& get_mutable_string_array() { return string_array_; } |
| 51 |
| 52 const NestedStructWithTraitsImpl& get_struct() const { return struct_; } |
| 53 NestedStructWithTraitsImpl& get_mutable_struct() { return struct_; } |
| 54 |
| 55 const std::vector<NestedStructWithTraitsImpl>& get_struct_array() const { |
| 56 return struct_array_; |
| 57 } |
| 58 std::vector<NestedStructWithTraitsImpl>& get_mutable_struct_array() { |
| 59 return struct_array_; |
| 60 } |
35 | 61 |
36 private: | 62 private: |
37 bool bool_ = false; | 63 bool bool_ = false; |
38 uint32_t uint32_ = 0; | 64 uint32_t uint32_ = 0; |
39 uint64_t uint64_ = 0; | 65 uint64_t uint64_ = 0; |
40 std::string string_; | 66 std::string string_; |
| 67 std::vector<std::string> string_array_; |
| 68 NestedStructWithTraitsImpl struct_; |
| 69 std::vector<NestedStructWithTraitsImpl> struct_array_; |
41 }; | 70 }; |
42 | 71 |
43 } // namespace test | 72 } // namespace test |
44 } // namespace mojo | 73 } // namespace mojo |
45 | 74 |
46 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_STRUCT_WITH_TRAITS_IMPL_H_ | 75 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_STRUCT_WITH_TRAITS_IMPL_H_ |
OLD | NEW |