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

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

Issue 15721007: Make expressions like "if (weak_ptr)" work (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comment again Created 7 years, 6 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.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 // 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 // Scopers help you manage ownership of a pointer, helping you easily manage the 5 // Scopers help you manage ownership of a pointer, helping you easily manage the
6 // a pointer within a scope, and automatically destroying the pointer at the 6 // a pointer within a scope, and automatically destroying the pointer at the
7 // end of a scope. There are two main classes you will use, which correspond 7 // end of a scope. There are two main classes you will use, which correspond
8 // to the operators new/delete and new[]/delete[]. 8 // to the operators new/delete and new[]/delete[].
9 // 9 //
10 // Example usage (scoped_ptr<T>): 10 // Example usage (scoped_ptr<T>):
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 return impl_.get(); 377 return impl_.get();
378 } 378 }
379 element_type* get() const { return impl_.get(); } 379 element_type* get() const { return impl_.get(); }
380 380
381 // Access to the deleter. 381 // Access to the deleter.
382 deleter_type& get_deleter() { return impl_.get_deleter(); } 382 deleter_type& get_deleter() { return impl_.get_deleter(); }
383 const deleter_type& get_deleter() const { return impl_.get_deleter(); } 383 const deleter_type& get_deleter() const { return impl_.get_deleter(); }
384 384
385 // Allow scoped_ptr<element_type> to be used in boolean expressions, but not 385 // Allow scoped_ptr<element_type> to be used in boolean expressions, but not
386 // implicitly convertible to a real bool (which is dangerous). 386 // implicitly convertible to a real bool (which is dangerous).
387 //
388 // Note that this trick is only safe when the == and != operators
389 // are declared explicitly, as otherwise "scoped_ptr1 ==
390 // scoped_ptr2" will compile but do the wrong thing (i.e., convert
391 // to Testable and then do the comparison).
387 private: 392 private:
388 typedef base::internal::scoped_ptr_impl<element_type, deleter_type> 393 typedef base::internal::scoped_ptr_impl<element_type, deleter_type>
389 scoped_ptr::*Testable; 394 scoped_ptr::*Testable;
390 395
391 public: 396 public:
392 operator Testable() const { return impl_.get() ? &scoped_ptr::impl_ : NULL; } 397 operator Testable() const { return impl_.get() ? &scoped_ptr::impl_ : NULL; }
393 398
394 // Comparison operators. 399 // Comparison operators.
395 // These return whether two scoped_ptr refer to the same object, not just to 400 // These return whether two scoped_ptr refer to the same object, not just to
396 // two different but equal objects. 401 // two different but equal objects.
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 697
693 // A function to convert T* into scoped_ptr<T> 698 // A function to convert T* into scoped_ptr<T>
694 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation 699 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation
695 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) 700 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg))
696 template <typename T> 701 template <typename T>
697 scoped_ptr<T> make_scoped_ptr(T* ptr) { 702 scoped_ptr<T> make_scoped_ptr(T* ptr) {
698 return scoped_ptr<T>(ptr); 703 return scoped_ptr<T>(ptr);
699 } 704 }
700 705
701 #endif // BASE_MEMORY_SCOPED_PTR_H_ 706 #endif // BASE_MEMORY_SCOPED_PTR_H_
OLDNEW
« no previous file with comments | « no previous file | base/memory/weak_ptr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698