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

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

Issue 23621021: (not for review yet) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 | cc/trees/layer_tree_host.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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 92
93 #include <assert.h> 93 #include <assert.h>
94 #include <stddef.h> 94 #include <stddef.h>
95 #include <stdlib.h> 95 #include <stdlib.h>
96 96
97 #include <algorithm> // For std::swap(). 97 #include <algorithm> // For std::swap().
98 98
99 #include "base/basictypes.h" 99 #include "base/basictypes.h"
100 #include "base/compiler_specific.h" 100 #include "base/compiler_specific.h"
101 #include "base/move.h" 101 #include "base/move.h"
102 #include "base/logging.h"
102 #include "base/template_util.h" 103 #include "base/template_util.h"
103 104
104 namespace base { 105 namespace base {
105 106
106 namespace subtle { 107 namespace subtle {
107 class RefCountedBase; 108 class RefCountedBase;
108 class RefCountedThreadSafeBase; 109 class RefCountedThreadSafeBase;
109 } // namespace subtle 110 } // namespace subtle
110 111
111 // Function object which deletes its parameter, which must be a pointer. 112 // Function object which deletes its parameter, which must be a pointer.
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 // Then takes ownership of a new object, if given. 367 // Then takes ownership of a new object, if given.
367 void reset(element_type* p = NULL) { impl_.reset(p); } 368 void reset(element_type* p = NULL) { impl_.reset(p); }
368 369
369 // Accessors to get the owned object. 370 // Accessors to get the owned object.
370 // operator* and operator-> will assert() if there is no current object. 371 // operator* and operator-> will assert() if there is no current object.
371 element_type& operator*() const { 372 element_type& operator*() const {
372 assert(impl_.get() != NULL); 373 assert(impl_.get() != NULL);
373 return *impl_.get(); 374 return *impl_.get();
374 } 375 }
375 element_type* operator->() const { 376 element_type* operator->() const {
377 CHECK(impl_.get() != NULL);
376 assert(impl_.get() != NULL); 378 assert(impl_.get() != NULL);
377 return impl_.get(); 379 return impl_.get();
378 } 380 }
379 element_type* get() const { return impl_.get(); } 381 element_type* get() const { return impl_.get(); }
380 382
381 // Access to the deleter. 383 // Access to the deleter.
382 deleter_type& get_deleter() { return impl_.get_deleter(); } 384 deleter_type& get_deleter() { return impl_.get_deleter(); }
383 const deleter_type& get_deleter() const { return impl_.get_deleter(); } 385 const deleter_type& get_deleter() const { return impl_.get_deleter(); }
384 386
385 // Allow scoped_ptr<element_type> to be used in boolean expressions, but not 387 // Allow scoped_ptr<element_type> to be used in boolean expressions, but not
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 702
701 // A function to convert T* into scoped_ptr<T> 703 // A function to convert T* into scoped_ptr<T>
702 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation 704 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation
703 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) 705 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg))
704 template <typename T> 706 template <typename T>
705 scoped_ptr<T> make_scoped_ptr(T* ptr) { 707 scoped_ptr<T> make_scoped_ptr(T* ptr) {
706 return scoped_ptr<T>(ptr); 708 return scoped_ptr<T>(ptr);
707 } 709 }
708 710
709 #endif // BASE_MEMORY_SCOPED_PTR_H_ 711 #endif // BASE_MEMORY_SCOPED_PTR_H_
OLDNEW
« no previous file with comments | « no previous file | cc/trees/layer_tree_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698