| OLD | NEW |
| 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): | 10 // Example usage (scoped_ptr): |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 // scoped_ptr<Foo> CreateFoo() { | 79 // scoped_ptr<Foo> CreateFoo() { |
| 80 // scoped_ptr<FooChild> result(new FooChild()); | 80 // scoped_ptr<FooChild> result(new FooChild()); |
| 81 // return result.PassAs<Foo>(); | 81 // return result.PassAs<Foo>(); |
| 82 // } | 82 // } |
| 83 // | 83 // |
| 84 // Note that PassAs<>() is implemented only for scoped_ptr, but not for | 84 // Note that PassAs<>() is implemented only for scoped_ptr, but not for |
| 85 // scoped_array. This is because casting array pointers may not be safe. | 85 // scoped_array. This is because casting array pointers may not be safe. |
| 86 | 86 |
| 87 #ifndef BASE_MEMORY_SCOPED_PTR_H_ | 87 #ifndef BASE_MEMORY_SCOPED_PTR_H_ |
| 88 #define BASE_MEMORY_SCOPED_PTR_H_ | 88 #define BASE_MEMORY_SCOPED_PTR_H_ |
| 89 #pragma once | |
| 90 | 89 |
| 91 // This is an implementation designed to match the anticipated future TR2 | 90 // This is an implementation designed to match the anticipated future TR2 |
| 92 // implementation of the scoped_ptr class, and its closely-related brethren, | 91 // implementation of the scoped_ptr class, and its closely-related brethren, |
| 93 // scoped_array, scoped_ptr_malloc. | 92 // scoped_array, scoped_ptr_malloc. |
| 94 | 93 |
| 95 #include <assert.h> | 94 #include <assert.h> |
| 96 #include <stddef.h> | 95 #include <stddef.h> |
| 97 #include <stdlib.h> | 96 #include <stdlib.h> |
| 98 | 97 |
| 99 #include "base/basictypes.h" | 98 #include "base/basictypes.h" |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 | 509 |
| 511 // A function to convert T* into scoped_ptr<T> | 510 // A function to convert T* into scoped_ptr<T> |
| 512 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation | 511 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation |
| 513 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) | 512 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) |
| 514 template <typename T> | 513 template <typename T> |
| 515 scoped_ptr<T> make_scoped_ptr(T* ptr) { | 514 scoped_ptr<T> make_scoped_ptr(T* ptr) { |
| 516 return scoped_ptr<T>(ptr); | 515 return scoped_ptr<T>(ptr); |
| 517 } | 516 } |
| 518 | 517 |
| 519 #endif // BASE_MEMORY_SCOPED_PTR_H_ | 518 #endif // BASE_MEMORY_SCOPED_PTR_H_ |
| OLD | NEW |