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

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

Issue 622593002: mojo: Allow circular dependencies between structs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 "mojo/public/cpp/bindings/type_converter.h"
10 #include "mojo/public/cpp/environment/logging.h" 11 #include "mojo/public/cpp/environment/logging.h"
11 #include "mojo/public/cpp/system/macros.h" 12 #include "mojo/public/cpp/system/macros.h"
12 13
13 namespace mojo { 14 namespace mojo {
14 namespace internal { 15 namespace internal {
15 16
16 template <typename Struct> 17 template <typename Struct>
17 class StructHelper { 18 class StructHelper {
18 public: 19 public:
19 template <typename Ptr> 20 template <typename Ptr>
20 static void Initialize(Ptr* ptr) { ptr->Initialize(); } 21 static void Initialize(Ptr* ptr) { ptr->Initialize(); }
21 }; 22 };
22 23
23 } // namespace internal 24 } // namespace internal
24 25
25 template <typename Struct> 26 template <typename Struct>
26 class StructPtr { 27 class StructPtr {
27 MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(StructPtr, RValue); 28 MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(StructPtr, RValue);
28 public: 29 public:
29 typedef typename Struct::Data_ Data_;
30 30
31 StructPtr() : ptr_(nullptr) {} 31 StructPtr() : ptr_(nullptr) {}
32 ~StructPtr() { 32 ~StructPtr() {
33 delete ptr_; 33 delete ptr_;
34 } 34 }
35 35
36 StructPtr(RValue other) : ptr_(nullptr) { Take(other.object); } 36 StructPtr(RValue other) : ptr_(nullptr) { Take(other.object); }
37 StructPtr& operator=(RValue other) { 37 StructPtr& operator=(RValue other) {
38 Take(other.object); 38 Take(other.object);
39 return *this; 39 return *this;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 86 }
87 87
88 Struct* ptr_; 88 Struct* ptr_;
89 }; 89 };
90 90
91 // Designed to be used when Struct is small and copyable. 91 // Designed to be used when Struct is small and copyable.
92 template <typename Struct> 92 template <typename Struct>
93 class InlinedStructPtr { 93 class InlinedStructPtr {
94 MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(InlinedStructPtr, RValue); 94 MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(InlinedStructPtr, RValue);
95 public: 95 public:
96 typedef typename Struct::Data_ Data_;
97 96
98 InlinedStructPtr() : is_null_(true) {} 97 InlinedStructPtr() : is_null_(true) {}
99 ~InlinedStructPtr() {} 98 ~InlinedStructPtr() {}
100 99
101 InlinedStructPtr(RValue other) : is_null_(true) { Take(other.object); } 100 InlinedStructPtr(RValue other) : is_null_(true) { Take(other.object); }
102 InlinedStructPtr& operator=(RValue other) { 101 InlinedStructPtr& operator=(RValue other) {
103 Take(other.object); 102 Take(other.object);
104 return *this; 103 return *this;
105 } 104 }
106 105
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 Swap(other); 146 Swap(other);
148 } 147 }
149 148
150 mutable Struct value_; 149 mutable Struct value_;
151 bool is_null_; 150 bool is_null_;
152 }; 151 };
153 152
154 } // namespace mojo 153 } // namespace mojo
155 154
156 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_ 155 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698