| 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/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) { | 21 static void Initialize(Ptr* ptr) { |
| 21 ptr->Initialize(); | 22 ptr->Initialize(); |
| 22 } | 23 } |
| 23 }; | 24 }; |
| 24 | 25 |
| 25 } // namespace internal | 26 } // namespace internal |
| 26 | 27 |
| 27 template <typename Struct> | 28 template <typename Struct> |
| 28 class StructPtr { | 29 class StructPtr { |
| 29 MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(StructPtr, RValue); | 30 MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(StructPtr, RValue); |
| 30 | 31 |
| 31 public: | 32 public: |
| 32 typedef typename Struct::Data_ Data_; | |
| 33 | 33 |
| 34 StructPtr() : ptr_(nullptr) {} | 34 StructPtr() : ptr_(nullptr) {} |
| 35 ~StructPtr() { delete ptr_; } | 35 ~StructPtr() { delete ptr_; } |
| 36 | 36 |
| 37 StructPtr(RValue other) : ptr_(nullptr) { Take(other.object); } | 37 StructPtr(RValue other) : ptr_(nullptr) { Take(other.object); } |
| 38 StructPtr& operator=(RValue other) { | 38 StructPtr& operator=(RValue other) { |
| 39 Take(other.object); | 39 Take(other.object); |
| 40 return *this; | 40 return *this; |
| 41 } | 41 } |
| 42 | 42 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 91 |
| 92 Struct* ptr_; | 92 Struct* ptr_; |
| 93 }; | 93 }; |
| 94 | 94 |
| 95 // Designed to be used when Struct is small and copyable. | 95 // Designed to be used when Struct is small and copyable. |
| 96 template <typename Struct> | 96 template <typename Struct> |
| 97 class InlinedStructPtr { | 97 class InlinedStructPtr { |
| 98 MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(InlinedStructPtr, RValue); | 98 MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(InlinedStructPtr, RValue); |
| 99 | 99 |
| 100 public: | 100 public: |
| 101 typedef typename Struct::Data_ Data_; | |
| 102 | 101 |
| 103 InlinedStructPtr() : is_null_(true) {} | 102 InlinedStructPtr() : is_null_(true) {} |
| 104 ~InlinedStructPtr() {} | 103 ~InlinedStructPtr() {} |
| 105 | 104 |
| 106 InlinedStructPtr(RValue other) : is_null_(true) { Take(other.object); } | 105 InlinedStructPtr(RValue other) : is_null_(true) { Take(other.object); } |
| 107 InlinedStructPtr& operator=(RValue other) { | 106 InlinedStructPtr& operator=(RValue other) { |
| 108 Take(other.object); | 107 Take(other.object); |
| 109 return *this; | 108 return *this; |
| 110 } | 109 } |
| 111 | 110 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 Swap(other); | 155 Swap(other); |
| 157 } | 156 } |
| 158 | 157 |
| 159 mutable Struct value_; | 158 mutable Struct value_; |
| 160 bool is_null_; | 159 bool is_null_; |
| 161 }; | 160 }; |
| 162 | 161 |
| 163 } // namespace mojo | 162 } // namespace mojo |
| 164 | 163 |
| 165 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_ | 164 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_ |
| OLD | NEW |