OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * Copyright (C) 2013 Intel Corporation. All rights reserved. | 3 * Copyright (C) 2013 Intel Corporation. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 18 matching lines...) Expand all Loading... | |
29 | 29 |
30 #include "WebCommon.h" | 30 #include "WebCommon.h" |
31 #include "WebNonCopyable.h" | 31 #include "WebNonCopyable.h" |
32 | 32 |
33 #if INSIDE_BLINK | 33 #if INSIDE_BLINK |
34 #include "wtf/PassOwnPtr.h" | 34 #include "wtf/PassOwnPtr.h" |
35 #endif | 35 #endif |
36 | 36 |
37 namespace blink { | 37 namespace blink { |
38 | 38 |
39 template <typename T> | |
40 class WebPrivatePassOwnPtr { | |
41 public: | |
42 WebPrivatePassOwnPtr() : m_ptr(nullptr) {} | |
43 WebPrivatePassOwnPtr(decltype(nullptr)) : m_ptr(nullptr) {} | |
44 template <typename U> | |
45 WebPrivatePassOwnPtr(const WebPrivatePassOwnPtr<U>& o) | |
kinuko
2015/07/16 05:58:57
Do we need this?
yhirano
2015/07/16 06:37:48
Yes, if we pass a WebPrivatePassOwnPtr<Derived> to
| |
46 { | |
47 m_ptr = o.m_ptr; | |
48 o.m_ptr = nullptr; | |
49 } | |
50 ~WebPrivatePassOwnPtr() { BLINK_ASSERT(!m_ptr); } | |
51 WebPrivatePassOwnPtr& operator =(const WebPrivatePassOwnPtr&) = delete; | |
52 | |
53 T* get() const { return m_ptr; } | |
kinuko
2015/07/16 05:58:57
Do we need this? I feel release() (in the other pa
yhirano
2015/07/16 06:37:48
Done.
| |
54 | |
55 template <typename U> friend class WebPrivateOwnPtr; | |
56 template <typename U> friend class WebPrivatePassOwnPtr; | |
57 template <typename U> friend WebPrivatePassOwnPtr<U> adoptWebPtr(U*); | |
58 | |
59 private: | |
60 explicit WebPrivatePassOwnPtr(T* ptr) : m_ptr(ptr) {} | |
61 | |
62 mutable T* m_ptr; | |
63 }; | |
64 | |
65 template <typename T> | |
66 WebPrivatePassOwnPtr<T> adoptWebPtr(T* p) { return WebPrivatePassOwnPtr<T>(p); } | |
67 | |
39 // This class is an implementation detail of the WebKit API. It exists | 68 // This class is an implementation detail of the WebKit API. It exists |
40 // to help simplify the implementation of WebKit interfaces that merely | 69 // to help simplify the implementation of WebKit interfaces that merely |
41 // wrap a pointer to a WebCore class. It's similar to WebPrivatePtr, but it | 70 // wrap a pointer to a WebCore class. It's similar to WebPrivatePtr, but it |
42 // wraps a naked pointer rather than a reference counted. | 71 // wraps a naked pointer rather than a reference counted. |
43 // Note: you must call reset(0) on the implementation side in order to delete | 72 // Note: you must call reset(0) on the implementation side in order to delete |
44 // the WebCore pointer. | 73 // the WebCore pointer. |
45 template <typename T> | 74 template <typename T> |
46 class WebPrivateOwnPtr : public WebNonCopyable { | 75 class WebPrivateOwnPtr : public WebNonCopyable { |
47 public: | 76 public: |
48 WebPrivateOwnPtr() : m_ptr(nullptr) {} | 77 WebPrivateOwnPtr() : m_ptr(nullptr) {} |
49 WebPrivateOwnPtr(decltype(nullptr)) : m_ptr(nullptr) {} | 78 WebPrivateOwnPtr(decltype(nullptr)) : m_ptr(nullptr) {} |
79 template <typename U> | |
80 WebPrivateOwnPtr(const WebPrivatePassOwnPtr<U>& o) | |
kinuko
2015/07/16 05:58:57
Do we actually use this?
yhirano
2015/07/16 06:37:48
Deleted.
| |
81 { | |
82 m_ptr = o.m_ptr; | |
83 o.m_ptr = nullptr; | |
84 } | |
50 ~WebPrivateOwnPtr() { BLINK_ASSERT(!m_ptr); } | 85 ~WebPrivateOwnPtr() { BLINK_ASSERT(!m_ptr); } |
51 | 86 |
52 explicit WebPrivateOwnPtr(T* ptr) | 87 explicit WebPrivateOwnPtr(T* ptr) : m_ptr(ptr) {} |
53 : m_ptr(ptr) | |
54 { | |
55 } | |
56 | 88 |
57 T* get() const { return m_ptr; } | 89 T* get() const { return m_ptr; } |
58 | 90 |
59 #if INSIDE_BLINK | 91 #if INSIDE_BLINK |
60 template<typename U> WebPrivateOwnPtr(const PassOwnPtr<U>&, EnsurePtrConvert ibleArgDecl(U, T)); | 92 template<typename U> WebPrivateOwnPtr(const PassOwnPtr<U>&, EnsurePtrConvert ibleArgDecl(U, T)); |
61 | 93 |
62 void reset(T* ptr) | 94 void reset(T* ptr) |
63 { | 95 { |
64 delete m_ptr; | 96 delete m_ptr; |
65 m_ptr = ptr; | 97 m_ptr = ptr; |
(...skipping 26 matching lines...) Expand all Loading... | |
92 template<typename T> template<typename U> inline WebPrivateOwnPtr<T>::WebPrivate OwnPtr(const PassOwnPtr<U>& o, EnsurePtrConvertibleArgDefn(U, T)) | 124 template<typename T> template<typename U> inline WebPrivateOwnPtr<T>::WebPrivate OwnPtr(const PassOwnPtr<U>& o, EnsurePtrConvertibleArgDefn(U, T)) |
93 : m_ptr(o.leakPtr()) | 125 : m_ptr(o.leakPtr()) |
94 { | 126 { |
95 static_assert(!WTF::IsArray<T>::value, "Pointers to array must never be conv erted"); | 127 static_assert(!WTF::IsArray<T>::value, "Pointers to array must never be conv erted"); |
96 } | 128 } |
97 #endif | 129 #endif |
98 | 130 |
99 } // namespace blink | 131 } // namespace blink |
100 | 132 |
101 #endif | 133 #endif |
OLD | NEW |