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

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

Issue 759503002: Remove unneeded #define in ref_counted.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Bug URL Created 6 years 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 | « no previous file | no next file » | 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 #ifndef BASE_MEMORY_REF_COUNTED_H_ 5 #ifndef BASE_MEMORY_REF_COUNTED_H_
6 #define BASE_MEMORY_REF_COUNTED_H_ 6 #define BASE_MEMORY_REF_COUNTED_H_
7 7
8 #include <cassert> 8 #include <cassert>
9 #include <iosfwd> 9 #include <iosfwd>
10 10
11 #include "base/atomic_ref_count.h" 11 #include "base/atomic_ref_count.h"
12 #include "base/base_export.h" 12 #include "base/base_export.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #ifndef NDEBUG 14 #ifndef NDEBUG
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #endif 16 #endif
17 #include "base/threading/thread_collision_warner.h" 17 #include "base/threading/thread_collision_warner.h"
18 #include "build/build_config.h" 18 #include "build/build_config.h"
19 19
20 #if defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_IOS) || defined(OS_AND ROID) || defined(OS_WIN)
21 #define DISABLE_SCOPED_REFPTR_CONVERSION_OPERATOR
22 #endif
23
24 namespace base { 20 namespace base {
25 21
26 namespace subtle { 22 namespace subtle {
27 23
28 class BASE_EXPORT RefCountedBase { 24 class BASE_EXPORT RefCountedBase {
29 public: 25 public:
30 bool HasOneRef() const { return ref_count_ == 1; } 26 bool HasOneRef() const { return ref_count_ == 1; }
31 27
32 protected: 28 protected:
33 RefCountedBase() 29 RefCountedBase()
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 AddRef(ptr_); 286 AddRef(ptr_);
291 } 287 }
292 288
293 ~scoped_refptr() { 289 ~scoped_refptr() {
294 if (ptr_) 290 if (ptr_)
295 Release(ptr_); 291 Release(ptr_);
296 } 292 }
297 293
298 T* get() const { return ptr_; } 294 T* get() const { return ptr_; }
299 295
300 #if !defined(DISABLE_SCOPED_REFPTR_CONVERSION_OPERATOR)
301 // Allow scoped_refptr<C> to be used in boolean expression
302 // and comparison operations.
303 operator T*() const { return ptr_; }
304 #endif
305
306 T& operator*() const { 296 T& operator*() const {
307 assert(ptr_ != NULL); 297 assert(ptr_ != NULL);
308 return *ptr_; 298 return *ptr_;
309 } 299 }
310 300
311 T* operator->() const { 301 T* operator->() const {
312 assert(ptr_ != NULL); 302 assert(ptr_ != NULL);
313 return ptr_; 303 return ptr_;
314 } 304 }
315 305
(...skipping 20 matching lines...) Expand all
336 void swap(T** pp) { 326 void swap(T** pp) {
337 T* p = ptr_; 327 T* p = ptr_;
338 ptr_ = *pp; 328 ptr_ = *pp;
339 *pp = p; 329 *pp = p;
340 } 330 }
341 331
342 void swap(scoped_refptr<T>& r) { 332 void swap(scoped_refptr<T>& r) {
343 swap(&r.ptr_); 333 swap(&r.ptr_);
344 } 334 }
345 335
346 #if defined(DISABLE_SCOPED_REFPTR_CONVERSION_OPERATOR)
347 template <typename U> 336 template <typename U>
348 bool operator==(const scoped_refptr<U>& rhs) const { 337 bool operator==(const scoped_refptr<U>& rhs) const {
349 return ptr_ == rhs.get(); 338 return ptr_ == rhs.get();
350 } 339 }
351 340
352 template <typename U> 341 template <typename U>
353 bool operator!=(const scoped_refptr<U>& rhs) const { 342 bool operator!=(const scoped_refptr<U>& rhs) const {
354 return !operator==(rhs); 343 return !operator==(rhs);
355 } 344 }
356 345
357 template <typename U> 346 template <typename U>
358 bool operator<(const scoped_refptr<U>& rhs) const { 347 bool operator<(const scoped_refptr<U>& rhs) const {
359 return ptr_ < rhs.get(); 348 return ptr_ < rhs.get();
360 } 349 }
361 #endif
362 350
363 protected: 351 protected:
364 T* ptr_; 352 T* ptr_;
365 353
366 private: 354 private:
367 // Non-inline helpers to allow: 355 // Non-inline helpers to allow:
368 // class Opaque; 356 // class Opaque;
369 // extern template class scoped_refptr<Opaque>; 357 // extern template class scoped_refptr<Opaque>;
370 // Otherwise the compiler will complain that Opaque is an incomplete type. 358 // Otherwise the compiler will complain that Opaque is an incomplete type.
371 static void AddRef(T* ptr); 359 static void AddRef(T* ptr);
(...skipping 10 matching lines...) Expand all
382 ptr->Release(); 370 ptr->Release();
383 } 371 }
384 372
385 // Handy utility for creating a scoped_refptr<T> out of a T* explicitly without 373 // Handy utility for creating a scoped_refptr<T> out of a T* explicitly without
386 // having to retype all the template arguments 374 // having to retype all the template arguments
387 template <typename T> 375 template <typename T>
388 scoped_refptr<T> make_scoped_refptr(T* t) { 376 scoped_refptr<T> make_scoped_refptr(T* t) {
389 return scoped_refptr<T>(t); 377 return scoped_refptr<T>(t);
390 } 378 }
391 379
392 #if defined(DISABLE_SCOPED_REFPTR_CONVERSION_OPERATOR) 380 // Temporary operator overloads to facilitate the transition. See
393 // Temporary operator overloads to facilitate the transition... 381 // https://crbug.com/110610.
394 template <typename T, typename U> 382 template <typename T, typename U>
395 bool operator==(const scoped_refptr<T>& lhs, const U* rhs) { 383 bool operator==(const scoped_refptr<T>& lhs, const U* rhs) {
396 return lhs.get() == rhs; 384 return lhs.get() == rhs;
397 } 385 }
398 386
399 template <typename T, typename U> 387 template <typename T, typename U>
400 bool operator==(const T* lhs, const scoped_refptr<U>& rhs) { 388 bool operator==(const T* lhs, const scoped_refptr<U>& rhs) {
401 return lhs == rhs.get(); 389 return lhs == rhs.get();
402 } 390 }
403 391
404 template <typename T, typename U> 392 template <typename T, typename U>
405 bool operator!=(const scoped_refptr<T>& lhs, const U* rhs) { 393 bool operator!=(const scoped_refptr<T>& lhs, const U* rhs) {
406 return !operator==(lhs, rhs); 394 return !operator==(lhs, rhs);
407 } 395 }
408 396
409 template <typename T, typename U> 397 template <typename T, typename U>
410 bool operator!=(const T* lhs, const scoped_refptr<U>& rhs) { 398 bool operator!=(const T* lhs, const scoped_refptr<U>& rhs) {
411 return !operator==(lhs, rhs); 399 return !operator==(lhs, rhs);
412 } 400 }
413 401
414 template <typename T> 402 template <typename T>
415 std::ostream& operator<<(std::ostream& out, const scoped_refptr<T>& p) { 403 std::ostream& operator<<(std::ostream& out, const scoped_refptr<T>& p) {
416 return out << p.get(); 404 return out << p.get();
417 } 405 }
418 #endif // defined(DISABLE_SCOPED_REFPTR_CONVERSION_OPERATOR)
419 406
420 #endif // BASE_MEMORY_REF_COUNTED_H_ 407 #endif // BASE_MEMORY_REF_COUNTED_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698