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. | |
jeffbrown
2016/02/02 05:35:48
+1, get rid of this thing entirely
dalesat
2016/02/02 21:46:40
Acknowledged.
| |
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>() {} | |
jeffbrown
2016/02/02 05:35:48
All one-arg constructors should be explicit.
dalesat
2016/02/02 21:46:40
True for std::nullptr_t as well? What I have here
jeffbrown
2016/02/03 01:46:56
Ahh, unique_ptr may be a special case to allow som
| |
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 { | |
jeffbrown
2016/02/02 05:35:48
Avoid conversion operators.
dalesat
2016/02/02 21:46:40
This is used to solve a specific problem, namely h
| |
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 |