| 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 <cstddef> | 8 #include <cstddef> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <new> | 10 #include <new> |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 return *this; | 120 return *this; |
| 121 } | 121 } |
| 122 | 122 |
| 123 template <typename U> | 123 template <typename U> |
| 124 U To() const { | 124 U To() const { |
| 125 return TypeConverter<U, InlinedStructPtr>::Convert(*this); | 125 return TypeConverter<U, InlinedStructPtr>::Convert(*this); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void reset() { | 128 void reset() { |
| 129 is_null_ = true; | 129 is_null_ = true; |
| 130 value_. ~Struct(); | 130 value_.~Struct(); |
| 131 new (&value_) Struct(); | 131 new (&value_) Struct(); |
| 132 } | 132 } |
| 133 | 133 |
| 134 // Tests as true if non-null, false if null. | 134 // Tests as true if non-null, false if null. |
| 135 explicit operator bool() const { return !is_null_; } | 135 explicit operator bool() const { return !is_null_; } |
| 136 | 136 |
| 137 bool is_null() const { return is_null_; } | 137 bool is_null() const { return is_null_; } |
| 138 | 138 |
| 139 Struct& operator*() const { | 139 Struct& operator*() const { |
| 140 MOJO_DCHECK(!is_null_); | 140 MOJO_DCHECK(!is_null_); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 171 | 171 |
| 172 mutable Struct value_; | 172 mutable Struct value_; |
| 173 bool is_null_; | 173 bool is_null_; |
| 174 | 174 |
| 175 MOJO_MOVE_ONLY_TYPE(InlinedStructPtr); | 175 MOJO_MOVE_ONLY_TYPE(InlinedStructPtr); |
| 176 }; | 176 }; |
| 177 | 177 |
| 178 } // namespace mojo | 178 } // namespace mojo |
| 179 | 179 |
| 180 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_ | 180 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_ |
| OLD | NEW |