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

Side by Side Diff: base/memory/weak_ptr.h

Issue 9455086: Make WeakPtr::operator* return reference instead of pointer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: _ Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | base/memory/weak_ptr_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Weak pointers help in cases where you have many objects referring back to a 5 // Weak pointers help in cases where you have many objects referring back to a
6 // shared object and you wish for the lifetime of the shared object to not be 6 // shared object and you wish for the lifetime of the shared object to not be
7 // bound to the lifetime of the referrers. In other words, this is useful when 7 // bound to the lifetime of the referrers. In other words, this is useful when
8 // reference counting is not a good fit. 8 // reference counting is not a good fit.
9 // 9 //
10 // Thread-safety notes: 10 // Thread-safety notes:
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } 164 }
165 165
166 // Allow conversion from U to T provided U "is a" T. 166 // Allow conversion from U to T provided U "is a" T.
167 template <typename U> 167 template <typename U>
168 WeakPtr(const WeakPtr<U>& other) : WeakPtrBase(other), ptr_(other.get()) { 168 WeakPtr(const WeakPtr<U>& other) : WeakPtrBase(other), ptr_(other.get()) {
169 } 169 }
170 170
171 T* get() const { return ref_.is_valid() ? ptr_ : NULL; } 171 T* get() const { return ref_.is_valid() ? ptr_ : NULL; }
172 operator T*() const { return get(); } 172 operator T*() const { return get(); }
173 173
174 T* operator*() const { 174 T& operator*() const {
175 DCHECK(get() != NULL); 175 DCHECK(get() != NULL);
176 return get(); 176 return *get();
177 } 177 }
178 T* operator->() const { 178 T* operator->() const {
179 DCHECK(get() != NULL); 179 DCHECK(get() != NULL);
180 return get(); 180 return get();
181 } 181 }
182 182
183 void reset() { 183 void reset() {
184 ref_ = internal::WeakReference(); 184 ref_ = internal::WeakReference();
185 ptr_ = NULL; 185 ptr_ = NULL;
186 } 186 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 253
254 private: 254 private:
255 internal::WeakReferenceOwner weak_reference_owner_; 255 internal::WeakReferenceOwner weak_reference_owner_;
256 T* ptr_; 256 T* ptr_;
257 DISALLOW_IMPLICIT_CONSTRUCTORS(WeakPtrFactory); 257 DISALLOW_IMPLICIT_CONSTRUCTORS(WeakPtrFactory);
258 }; 258 };
259 259
260 } // namespace base 260 } // namespace base
261 261
262 #endif // BASE_MEMORY_WEAK_PTR_H_ 262 #endif // BASE_MEMORY_WEAK_PTR_H_
OLDNEW
« no previous file with comments | « no previous file | base/memory/weak_ptr_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698