• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
set_enum(EnumWithTraitsImpl value)43   void set_enum(EnumWithTraitsImpl value) { enum_ = value; }
get_enum()44   EnumWithTraitsImpl get_enum() const { return enum_; }
45 
set_bool(bool value)46   void set_bool(bool value) { bool_ = value; }
get_bool()47   bool get_bool() const { return bool_; }
48 
set_uint32(uint32_t value)49   void set_uint32(uint32_t value) { uint32_ = value; }
get_uint32()50   uint32_t get_uint32() const { return uint32_; }
51 
set_uint64(uint64_t value)52   void set_uint64(uint64_t value) { uint64_ = value; }
get_uint64()53   uint64_t get_uint64() const { return uint64_; }
54 
set_string(std::string value)55   void set_string(std::string value) { string_ = value; }
get_string_as_string_piece()56   base::StringPiece get_string_as_string_piece() const { return string_; }
get_string()57   const std::string& get_string() const { return string_; }
58 
get_string_array()59   const std::vector<std::string>& get_string_array() const {
60     return string_array_;
61   }
get_mutable_string_array()62   std::vector<std::string>& get_mutable_string_array() { return string_array_; }
63 
get_struct()64   const NestedStructWithTraitsImpl& get_struct() const { return struct_; }
get_mutable_struct()65   NestedStructWithTraitsImpl& get_mutable_struct() { return struct_; }
66 
get_struct_array()67   const std::vector<NestedStructWithTraitsImpl>& get_struct_array() const {
68     return struct_array_;
69   }
get_mutable_struct_array()70   std::vector<NestedStructWithTraitsImpl>& get_mutable_struct_array() {
71     return struct_array_;
72   }
73 
get_struct_map()74   const std::map<std::string, NestedStructWithTraitsImpl>& get_struct_map()
75       const {
76     return struct_map_;
77   }
get_mutable_struct_map()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 
get_mutable_handle()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