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 3 // found in the LICENSE file. 4 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_TESTS_STRUCT_WITH_TRAITS_IMPL_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_STRUCT_WITH_TRAITS_IMPL_H_ 7 8 #include <stdint.h> 9 10 #include <map> 11 #include <string> 12 #include <vector> 13 14 #include "base/strings/string_piece.h" 15 #include "mojo/public/cpp/system/handle.h" 16 17 namespace mojo { 18 namespace test { 19 20 struct NestedStructWithTraitsImpl { 21 public: 22 NestedStructWithTraitsImpl(); 23 explicit NestedStructWithTraitsImpl(int32_t in_value); 24 25 bool operator==(const NestedStructWithTraitsImpl& other) const { 26 return value == other.value; 27 } 28 29 int32_t value = 0; 30 }; 31 32 enum class EnumWithTraitsImpl { CUSTOM_VALUE_0 = 10, CUSTOM_VALUE_1 = 11 }; 33 34 // A type which knows how to look like a mojo::test::StructWithTraits mojom type 35 // by way of mojo::StructTraits. 36 class StructWithTraitsImpl { 37 public: 38 StructWithTraitsImpl(); 39 ~StructWithTraitsImpl(); 40 41 StructWithTraitsImpl(const StructWithTraitsImpl& other); 42 43 void set_enum(EnumWithTraitsImpl value) { enum_ = value; } 44 EnumWithTraitsImpl get_enum() const { return enum_; } 45 46 void set_bool(bool value) { bool_ = value; } 47 bool get_bool() const { return bool_; } 48 49 void set_uint32(uint32_t value) { uint32_ = value; } 50 uint32_t get_uint32() const { return uint32_; } 51 52 void set_uint64(uint64_t value) { uint64_ = value; } 53 uint64_t get_uint64() const { return uint64_; } 54 55 void set_string(std::string value) { string_ = value; } 56 base::StringPiece get_string_as_string_piece() const { return string_; } 57 const std::string& get_string() const { return string_; } 58 59 const std::vector<std::string>& get_string_array() const { 60 return string_array_; 61 } 62 std::vector<std::string>& get_mutable_string_array() { return string_array_; } 63 64 const NestedStructWithTraitsImpl& get_struct() const { return struct_; } 65 NestedStructWithTraitsImpl& get_mutable_struct() { return struct_; } 66 67 const std::vector<NestedStructWithTraitsImpl>& get_struct_array() const { 68 return struct_array_; 69 } 70 std::vector<NestedStructWithTraitsImpl>& get_mutable_struct_array() { 71 return struct_array_; 72 } 73 74 const std::map<std::string, NestedStructWithTraitsImpl>& get_struct_map() 75 const { 76 return struct_map_; 77 } 78 std::map<std::string, NestedStructWithTraitsImpl>& get_mutable_struct_map() { 79 return struct_map_; 80 } 81 82 private: 83 EnumWithTraitsImpl enum_ = EnumWithTraitsImpl::CUSTOM_VALUE_0; 84 bool bool_ = false; 85 uint32_t uint32_ = 0; 86 uint64_t uint64_ = 0; 87 std::string string_; 88 std::vector<std::string> string_array_; 89 NestedStructWithTraitsImpl struct_; 90 std::vector<NestedStructWithTraitsImpl> struct_array_; 91 std::map<std::string, NestedStructWithTraitsImpl> struct_map_; 92 }; 93 94 // A type which knows how to look like a mojo::test::PassByValueStructWithTraits 95 // mojom type by way of mojo::StructTraits. 96 class PassByValueStructWithTraitsImpl { 97 public: 98 PassByValueStructWithTraitsImpl(); 99 PassByValueStructWithTraitsImpl(PassByValueStructWithTraitsImpl&& other); 100 ~PassByValueStructWithTraitsImpl(); 101 102 ScopedHandle& get_mutable_handle() { return handle_; } 103 104 private: 105 ScopedHandle handle_; 106 DISALLOW_COPY_AND_ASSIGN(PassByValueStructWithTraitsImpl); 107 }; 108 109 } // namespace test 110 } // namespace mojo 111 112 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_STRUCT_WITH_TRAITS_IMPL_H_ 113