OLD | NEW |
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/environment/logging.h" | 10 #include "mojo/public/cpp/environment/logging.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 } | 34 } |
35 | 35 |
36 StructPtr(RValue other) : ptr_(NULL) { Take(other.object); } | 36 StructPtr(RValue other) : ptr_(NULL) { 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; |
40 } | 40 } |
41 | 41 |
42 template <typename U> | 42 template <typename U> |
43 U To() const { | 43 U To() const { |
44 return TypeConverter<StructPtr, U>::ConvertTo(*this); | 44 return TypeConverter<U, StructPtr>::Convert(*this); |
45 } | 45 } |
46 | 46 |
47 void reset() { | 47 void reset() { |
48 if (ptr_) { | 48 if (ptr_) { |
49 delete ptr_; | 49 delete ptr_; |
50 ptr_ = NULL; | 50 ptr_ = NULL; |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 bool is_null() const { return ptr_ == NULL; } | 54 bool is_null() const { return ptr_ == NULL; } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 ~InlinedStructPtr() {} | 99 ~InlinedStructPtr() {} |
100 | 100 |
101 InlinedStructPtr(RValue other) : is_null_(true) { Take(other.object); } | 101 InlinedStructPtr(RValue other) : is_null_(true) { Take(other.object); } |
102 InlinedStructPtr& operator=(RValue other) { | 102 InlinedStructPtr& operator=(RValue other) { |
103 Take(other.object); | 103 Take(other.object); |
104 return *this; | 104 return *this; |
105 } | 105 } |
106 | 106 |
107 template <typename U> | 107 template <typename U> |
108 U To() const { | 108 U To() const { |
109 return TypeConverter<InlinedStructPtr, U>::ConvertTo(*this); | 109 return TypeConverter<U, InlinedStructPtr>::Convert(*this); |
110 } | 110 } |
111 | 111 |
112 void reset() { | 112 void reset() { |
113 is_null_ = true; | 113 is_null_ = true; |
114 value_.~Struct(); | 114 value_.~Struct(); |
115 new (&value_) Struct(); | 115 new (&value_) Struct(); |
116 } | 116 } |
117 | 117 |
118 bool is_null() const { return is_null_; } | 118 bool is_null() const { return is_null_; } |
119 | 119 |
(...skipping 27 matching lines...) Expand all Loading... |
147 Swap(other); | 147 Swap(other); |
148 } | 148 } |
149 | 149 |
150 mutable Struct value_; | 150 mutable Struct value_; |
151 bool is_null_; | 151 bool is_null_; |
152 }; | 152 }; |
153 | 153 |
154 } // namespace mojo | 154 } // namespace mojo |
155 | 155 |
156 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_ | 156 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_ |
OLD | NEW |