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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 private: | 237 private: |
238 C* ptr_; | 238 C* ptr_; |
239 | 239 |
240 // Forbid comparison of scoped_ptr types. If C2 != C, it totally doesn't | 240 // Forbid comparison of scoped_ptr types. If C2 != C, it totally doesn't |
241 // make sense, and if C2 == C, it still doesn't make sense because you should | 241 // make sense, and if C2 == C, it still doesn't make sense because you should |
242 // never have the same object owned by two different scoped_ptrs. | 242 // never have the same object owned by two different scoped_ptrs. |
243 template <class C2> bool operator==(scoped_ptr<C2> const& p2) const; | 243 template <class C2> bool operator==(scoped_ptr<C2> const& p2) const; |
244 template <class C2> bool operator!=(scoped_ptr<C2> const& p2) const; | 244 template <class C2> bool operator!=(scoped_ptr<C2> const& p2) const; |
245 | 245 |
246 }; | 246 }; |
247 /* | 247 |
248 class SkRefCnt; | |
249 template <> | |
250 class scoped_ptr <SkRefCnt> { | |
251 private: | |
252 scoped_ptr() { } | |
253 ~scoped_ptr() { }; | |
254 }; | |
255 */ | |
256 // Free functions | 248 // Free functions |
257 template <class C> | 249 template <class C> |
258 void swap(scoped_ptr<C>& p1, scoped_ptr<C>& p2) { | 250 void swap(scoped_ptr<C>& p1, scoped_ptr<C>& p2) { |
259 p1.swap(p2); | 251 p1.swap(p2); |
260 } | 252 } |
261 | 253 |
262 template <class C> | 254 template <class C> |
263 bool operator==(C* p1, const scoped_ptr<C>& p2) { | 255 bool operator==(C* p1, const scoped_ptr<C>& p2) { |
264 return p1 == p2.get(); | 256 return p1 == p2.get(); |
265 } | 257 } |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 | 515 |
524 // A function to convert T* into scoped_ptr<T> | 516 // A function to convert T* into scoped_ptr<T> |
525 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation | 517 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation |
526 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) | 518 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) |
527 template <typename T> | 519 template <typename T> |
528 scoped_ptr<T> make_scoped_ptr(T* ptr) { | 520 scoped_ptr<T> make_scoped_ptr(T* ptr) { |
529 return scoped_ptr<T>(ptr); | 521 return scoped_ptr<T>(ptr); |
530 } | 522 } |
531 | 523 |
532 #endif // BASE_MEMORY_SCOPED_PTR_H_ | 524 #endif // BASE_MEMORY_SCOPED_PTR_H_ |
OLD | NEW |