OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 coorespond | 7 // end of a scope. There are two main classes you will use, which coorespond |
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): | 10 // Example usage (scoped_ptr): |
11 // { | 11 // { |
12 // scoped_ptr<Foo> foo(new Foo("wee")); | 12 // scoped_ptr<Foo> foo(new Foo("wee")); |
13 // } // foo goes out of scope, releasing the pointer with it. | 13 // } // foo goes out of scope, releasing the pointer with it. |
14 // | 14 // |
15 // { | 15 // { |
16 // scoped_ptr<Foo> foo; // No pointer managed. | 16 // scoped_ptr<Foo> foo; // No pointer managed. |
17 // foo.reset(new Foo("wee")); // Now a pointer is managed. | 17 // foo.reset(new Foo("wee")); // Now a pointer is managed. |
18 // foo.reset(new Foo("wee2")); // Foo("wee") was destroyed. | 18 // foo.reset(new Foo("wee2")); // Foo("wee") was destroyed. |
19 // foo.reset(new Foo("wee3")); // Foo("wee2") was destroyed. | 19 // foo.reset(new Foo("wee3")); // Foo("wee2") was destroyed. |
20 // foo->Method(); // Foo::Method() called. | 20 // foo->Method(); // Foo::Method() called. |
21 // foo.get()->Method(); // Foo::Method() called. | 21 // foo.get()->Method(); // Foo::Method() called. |
22 // SomeFunc(foo.Release()); // SomeFunc takes owernship, foo no longer | 22 // SomeFunc(foo.release()); // SomeFunc takes owernship, foo no longer |
23 // // manages a pointer. | 23 // // manages a pointer. |
24 // foo.reset(new Foo("wee4")); // foo manages a pointer again. | 24 // foo.reset(new Foo("wee4")); // foo manages a pointer again. |
25 // foo.reset(); // Foo("wee4") destroyed, foo no longer | 25 // foo.reset(); // Foo("wee4") destroyed, foo no longer |
26 // // manages a pointer. | 26 // // manages a pointer. |
27 // } // foo wasn't managing a pointer, so nothing was destroyed. | 27 // } // foo wasn't managing a pointer, so nothing was destroyed. |
28 // | 28 // |
29 // Example usage (scoped_array): | 29 // Example usage (scoped_array): |
30 // { | 30 // { |
31 // scoped_array<Foo> foo(new Foo[100]); | 31 // scoped_array<Foo> foo(new Foo[100]); |
32 // foo.get()->Method(); // Foo::Method on the 0th element. | 32 // foo.get()->Method(); // Foo::Method on the 0th element. |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 bool operator==(C* p, const scoped_ptr_malloc<C, FP>& b) { | 371 bool operator==(C* p, const scoped_ptr_malloc<C, FP>& b) { |
372 return p == b.get(); | 372 return p == b.get(); |
373 } | 373 } |
374 | 374 |
375 template<class C, class FP> inline | 375 template<class C, class FP> inline |
376 bool operator!=(C* p, const scoped_ptr_malloc<C, FP>& b) { | 376 bool operator!=(C* p, const scoped_ptr_malloc<C, FP>& b) { |
377 return p != b.get(); | 377 return p != b.get(); |
378 } | 378 } |
379 | 379 |
380 #endif // BASE_SCOPED_PTR_H_ | 380 #endif // BASE_SCOPED_PTR_H_ |
OLD | NEW |