Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: webrtc/base/scoped_ref_ptr.h

Issue 2877023002: Move webrtc/{base => rtc_base} (Closed)
Patch Set: update presubmit.py and DEPS include rules Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/base/sanitizer.h ('k') | webrtc/base/sequenced_task_checker.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // scoped_refptr<MyFoo> b; 56 // scoped_refptr<MyFoo> b;
57 // 57 //
58 // b = a; 58 // b = a;
59 // // now, |a| and |b| each own a reference to the same MyFoo object. 59 // // now, |a| and |b| each own a reference to the same MyFoo object.
60 // } 60 // }
61 // 61 //
62 62
63 #ifndef WEBRTC_BASE_SCOPED_REF_PTR_H_ 63 #ifndef WEBRTC_BASE_SCOPED_REF_PTR_H_
64 #define WEBRTC_BASE_SCOPED_REF_PTR_H_ 64 #define WEBRTC_BASE_SCOPED_REF_PTR_H_
65 65
66 #include <memory>
67 66
68 namespace rtc { 67 // This header is deprecated and is just left here temporarily during
69 68 // refactoring. See https://bugs.webrtc.org/7634 for more details.
70 template <class T> 69 #include "webrtc/rtc_base/scoped_ref_ptr.h"
71 class scoped_refptr {
72 public:
73 scoped_refptr() : ptr_(nullptr) {}
74
75 scoped_refptr(T* p) : ptr_(p) {
76 if (ptr_)
77 ptr_->AddRef();
78 }
79
80 scoped_refptr(const scoped_refptr<T>& r) : ptr_(r.ptr_) {
81 if (ptr_)
82 ptr_->AddRef();
83 }
84
85 template <typename U>
86 scoped_refptr(const scoped_refptr<U>& r) : ptr_(r.get()) {
87 if (ptr_)
88 ptr_->AddRef();
89 }
90
91 // Move constructors.
92 scoped_refptr(scoped_refptr<T>&& r) : ptr_(r.release()) {}
93
94 template <typename U>
95 scoped_refptr(scoped_refptr<U>&& r) : ptr_(r.release()) {}
96
97 ~scoped_refptr() {
98 if (ptr_)
99 ptr_->Release();
100 }
101
102 T* get() const { return ptr_; }
103 operator T*() const { return ptr_; }
104 T* operator->() const { return ptr_; }
105
106 // Release a pointer.
107 // The return value is the current pointer held by this object.
108 // If this object holds a null pointer, the return value is null.
109 // After this operation, this object will hold a null pointer,
110 // and will not own the object any more.
111 T* release() {
112 T* retVal = ptr_;
113 ptr_ = nullptr;
114 return retVal;
115 }
116
117 scoped_refptr<T>& operator=(T* p) {
118 // AddRef first so that self assignment should work
119 if (p)
120 p->AddRef();
121 if (ptr_ )
122 ptr_ ->Release();
123 ptr_ = p;
124 return *this;
125 }
126
127 scoped_refptr<T>& operator=(const scoped_refptr<T>& r) {
128 return *this = r.ptr_;
129 }
130
131 template <typename U>
132 scoped_refptr<T>& operator=(const scoped_refptr<U>& r) {
133 return *this = r.get();
134 }
135
136 scoped_refptr<T>& operator=(scoped_refptr<T>&& r) {
137 scoped_refptr<T>(std::move(r)).swap(*this);
138 return *this;
139 }
140
141 template <typename U>
142 scoped_refptr<T>& operator=(scoped_refptr<U>&& r) {
143 scoped_refptr<T>(std::move(r)).swap(*this);
144 return *this;
145 }
146
147 void swap(T** pp) {
148 T* p = ptr_;
149 ptr_ = *pp;
150 *pp = p;
151 }
152
153 void swap(scoped_refptr<T>& r) {
154 swap(&r.ptr_);
155 }
156
157 protected:
158 T* ptr_;
159 };
160
161 } // namespace rtc
162 70
163 #endif // WEBRTC_BASE_SCOPED_REF_PTR_H_ 71 #endif // WEBRTC_BASE_SCOPED_REF_PTR_H_
OLDNEW
« no previous file with comments | « webrtc/base/sanitizer.h ('k') | webrtc/base/sequenced_task_checker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698