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

Side by Side Diff: mojo/public/cpp/bindings/struct_ptr.h

Issue 2076313002: Mojo C++ bindings: expose serialization public API for mojo structs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_STRUCT_PTR_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_
7 7
8 #include <new> 8 #include <new>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "mojo/public/cpp/bindings/type_converter.h" 12 #include "mojo/public/cpp/bindings/type_converter.h"
13 13
14 namespace mojo { 14 namespace mojo {
15 namespace internal { 15 namespace internal {
16 16
17 template <typename Struct> 17 template <typename Struct>
18 class StructHelper { 18 class StructHelper {
19 public: 19 public:
20 template <typename Ptr> 20 template <typename Ptr>
21 static void Initialize(Ptr* ptr) { 21 static void Initialize(Ptr* ptr) {
22 ptr->Initialize(); 22 ptr->Initialize();
23 } 23 }
24 }; 24 };
25 25
26 } // namespace internal 26 } // namespace internal
27 27
28 // Smart pointer wrapping a mojom structure with move-only semantics. 28 // Smart pointer wrapping a mojom structure with move-only semantics.
29 template <typename Struct> 29 template <typename S>
30 class StructPtr { 30 class StructPtr {
31 public: 31 public:
32 using Struct = S;
32 33
33 StructPtr() : ptr_(nullptr) {} 34 StructPtr() : ptr_(nullptr) {}
34 StructPtr(decltype(nullptr)) : ptr_(nullptr) {} 35 StructPtr(decltype(nullptr)) : ptr_(nullptr) {}
35 36
36 ~StructPtr() { delete ptr_; } 37 ~StructPtr() { delete ptr_; }
37 38
38 StructPtr& operator=(decltype(nullptr)) { 39 StructPtr& operator=(decltype(nullptr)) {
39 reset(); 40 reset();
40 return *this; 41 return *this;
41 } 42 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 reset(); 110 reset();
110 Swap(other); 111 Swap(other);
111 } 112 }
112 113
113 Struct* ptr_; 114 Struct* ptr_;
114 115
115 DISALLOW_COPY_AND_ASSIGN(StructPtr); 116 DISALLOW_COPY_AND_ASSIGN(StructPtr);
116 }; 117 };
117 118
118 // Designed to be used when Struct is small and copyable. 119 // Designed to be used when Struct is small and copyable.
119 template <typename Struct> 120 template <typename S>
120 class InlinedStructPtr { 121 class InlinedStructPtr {
121 public: 122 public:
123 using Struct = S;
122 124
123 InlinedStructPtr() : is_null_(true) {} 125 InlinedStructPtr() : is_null_(true) {}
124 InlinedStructPtr(decltype(nullptr)) : is_null_(true) {} 126 InlinedStructPtr(decltype(nullptr)) : is_null_(true) {}
125 127
126 ~InlinedStructPtr() {} 128 ~InlinedStructPtr() {}
127 129
128 InlinedStructPtr& operator=(decltype(nullptr)) { 130 InlinedStructPtr& operator=(decltype(nullptr)) {
129 reset(); 131 reset();
130 return *this; 132 return *this;
131 } 133 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 201
200 mutable Struct value_; 202 mutable Struct value_;
201 bool is_null_; 203 bool is_null_;
202 204
203 DISALLOW_COPY_AND_ASSIGN(InlinedStructPtr); 205 DISALLOW_COPY_AND_ASSIGN(InlinedStructPtr);
204 }; 206 };
205 207
206 } // namespace mojo 208 } // namespace mojo
207 209
208 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_ 210 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/serialization.h ('k') | mojo/public/cpp/bindings/tests/struct_traits_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698