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 10 matching lines...) Expand all Loading... |
21 }; | 21 }; |
22 | 22 |
23 } // namespace internal | 23 } // namespace internal |
24 | 24 |
25 template <typename Struct> | 25 template <typename Struct> |
26 class StructPtr { | 26 class StructPtr { |
27 MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(StructPtr, RValue); | 27 MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(StructPtr, RValue); |
28 public: | 28 public: |
29 typedef typename Struct::Data_ Data_; | 29 typedef typename Struct::Data_ Data_; |
30 | 30 |
31 StructPtr() : ptr_(NULL) {} | 31 StructPtr() : ptr_(nullptr) {} |
32 ~StructPtr() { | 32 ~StructPtr() { |
33 delete ptr_; | 33 delete ptr_; |
34 } | 34 } |
35 | 35 |
36 StructPtr(RValue other) : ptr_(NULL) { 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; |
40 } | 40 } |
41 | 41 |
42 template <typename U> | 42 template <typename U> |
43 U To() const { | 43 U To() const { |
44 return TypeConverter<U, StructPtr>::Convert(*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_ = nullptr; |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 bool is_null() const { return ptr_ == NULL; } | 54 bool is_null() const { return ptr_ == nullptr; } |
55 | 55 |
56 Struct& operator*() const { | 56 Struct& operator*() const { |
57 MOJO_DCHECK(ptr_); | 57 MOJO_DCHECK(ptr_); |
58 return *ptr_; | 58 return *ptr_; |
59 } | 59 } |
60 Struct* operator->() const { | 60 Struct* operator->() const { |
61 MOJO_DCHECK(ptr_); | 61 MOJO_DCHECK(ptr_); |
62 return ptr_; | 62 return ptr_; |
63 } | 63 } |
64 Struct* get() const { return ptr_; } | 64 Struct* get() const { return ptr_; } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |