| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef SERVICES_MEDIA_FRAMEWORK_PTR_H_ | |
| 6 #define SERVICES_MEDIA_FRAMEWORK_PTR_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 namespace mojo { | |
| 11 namespace media { | |
| 12 | |
| 13 // unique_ptr with Clone. | |
| 14 // TODO(dalesat): Remove in favor of unique_ptr and a Clone template function. | |
| 15 template<class T, class Deleter = std::default_delete<T>> | |
| 16 class UniquePtr : public std::unique_ptr<T, Deleter> { | |
| 17 public: | |
| 18 UniquePtr() : std::unique_ptr<T, Deleter>() {} | |
| 19 | |
| 20 UniquePtr(std::nullptr_t) : std::unique_ptr<T, Deleter>() {} | |
| 21 | |
| 22 explicit UniquePtr(T* ptr) : std::unique_ptr<T, Deleter>(ptr) {} | |
| 23 | |
| 24 UniquePtr(UniquePtr&& other) : | |
| 25 std::unique_ptr<T, Deleter>(std::move(other)) {} | |
| 26 | |
| 27 UniquePtr& operator=(std::nullptr_t) { | |
| 28 this->reset(); | |
| 29 return *this; | |
| 30 } | |
| 31 | |
| 32 UniquePtr& operator=(UniquePtr&& other) { | |
| 33 *static_cast<std::unique_ptr<T, Deleter>*>(this) = std::move(other); | |
| 34 return *this; | |
| 35 } | |
| 36 | |
| 37 UniquePtr Clone() const { return *this ? this->get()->Clone() : UniquePtr(); } | |
| 38 }; | |
| 39 | |
| 40 // shared_ptr with upcast to TBase. | |
| 41 // TODO(dalesat): Remove in favor of shared_ptr. | |
| 42 template<class T, typename TBase> | |
| 43 class SharedPtr : public std::shared_ptr<T> { | |
| 44 public: | |
| 45 SharedPtr() : std::shared_ptr<T>() {} | |
| 46 | |
| 47 SharedPtr(std::nullptr_t) : std::shared_ptr<T>() {} | |
| 48 | |
| 49 explicit SharedPtr(T* ptr) : std::shared_ptr<T>(ptr) {} | |
| 50 | |
| 51 SharedPtr& operator=(std::nullptr_t) { | |
| 52 this->reset(); | |
| 53 return *this; | |
| 54 } | |
| 55 | |
| 56 operator std::shared_ptr<TBase>() const { | |
| 57 return std::shared_ptr<TBase>(*this, this->get()); | |
| 58 } | |
| 59 }; | |
| 60 | |
| 61 } // namespace media | |
| 62 } // namespace mojo | |
| 63 | |
| 64 #endif // SERVICES_MEDIA_FRAMEWORK_PTR_H_ | |
| OLD | NEW |