| 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) { 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 93 } |
| 94 | 94 |
| 95 Struct* ptr_; | 95 Struct* ptr_; |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 // Designed to be used when Struct is small and copyable. | 98 // Designed to be used when Struct is small and copyable. |
| 99 template <typename Struct> | 99 template <typename Struct> |
| 100 class InlinedStructPtr { | 100 class InlinedStructPtr { |
| 101 MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(InlinedStructPtr, RValue); | 101 MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(InlinedStructPtr, RValue); |
| 102 public: | 102 public: |
| 103 typedef typename Struct::Data_ Data_; | |
| 104 | 103 |
| 105 InlinedStructPtr() : is_null_(true) {} | 104 InlinedStructPtr() : is_null_(true) {} |
| 106 ~InlinedStructPtr() {} | 105 ~InlinedStructPtr() {} |
| 107 | 106 |
| 108 InlinedStructPtr(RValue other) : is_null_(true) { Take(other.object); } | 107 InlinedStructPtr(RValue other) : is_null_(true) { Take(other.object); } |
| 109 InlinedStructPtr& operator=(RValue other) { | 108 InlinedStructPtr& operator=(RValue other) { |
| 110 Take(other.object); | 109 Take(other.object); |
| 111 return *this; | 110 return *this; |
| 112 } | 111 } |
| 113 | 112 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 Swap(other); | 157 Swap(other); |
| 159 } | 158 } |
| 160 | 159 |
| 161 mutable Struct value_; | 160 mutable Struct value_; |
| 162 bool is_null_; | 161 bool is_null_; |
| 163 }; | 162 }; |
| 164 | 163 |
| 165 } // namespace mojo | 164 } // namespace mojo |
| 166 | 165 |
| 167 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_ | 166 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_ |
| OLD | NEW |