OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 // implementation of the scoped_ptr class. | 83 // implementation of the scoped_ptr class. |
84 | 84 |
85 #include <assert.h> | 85 #include <assert.h> |
86 #include <stddef.h> | 86 #include <stddef.h> |
87 #include <stdlib.h> | 87 #include <stdlib.h> |
88 | 88 |
89 #include <algorithm> // For std::swap(). | 89 #include <algorithm> // For std::swap(). |
90 #include <cstddef> | 90 #include <cstddef> |
91 | 91 |
92 #include "webrtc/base/constructormagic.h" | 92 #include "webrtc/base/constructormagic.h" |
| 93 #include "webrtc/base/deprecation.h" |
93 #include "webrtc/base/template_util.h" | 94 #include "webrtc/base/template_util.h" |
94 #include "webrtc/typedefs.h" | 95 #include "webrtc/typedefs.h" |
95 | 96 |
96 namespace rtc { | 97 namespace rtc { |
97 | 98 |
98 // Function object which deletes its parameter, which must be a pointer. | 99 // Function object which deletes its parameter, which must be a pointer. |
99 // If C is an array type, invokes 'delete[]' on the parameter; otherwise, | 100 // If C is an array type, invokes 'delete[]' on the parameter; otherwise, |
100 // invokes 'delete'. The default deleter for scoped_ptr<T>. | 101 // invokes 'delete'. The default deleter for scoped_ptr<T>. |
101 template <class T> | 102 template <class T> |
102 struct DefaultDeleter { | 103 struct DefaultDeleter { |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 scoped_ptr& operator=(std::nullptr_t) { | 368 scoped_ptr& operator=(std::nullptr_t) { |
368 reset(); | 369 reset(); |
369 return *this; | 370 return *this; |
370 } | 371 } |
371 | 372 |
372 // Deleted copy constructor and copy assignment, to make the type move-only. | 373 // Deleted copy constructor and copy assignment, to make the type move-only. |
373 scoped_ptr(const scoped_ptr& other) = delete; | 374 scoped_ptr(const scoped_ptr& other) = delete; |
374 scoped_ptr& operator=(const scoped_ptr& other) = delete; | 375 scoped_ptr& operator=(const scoped_ptr& other) = delete; |
375 | 376 |
376 // Get an rvalue reference. (sp.Pass() does the same thing as std::move(sp).) | 377 // Get an rvalue reference. (sp.Pass() does the same thing as std::move(sp).) |
377 scoped_ptr&& Pass() { return std::move(*this); } | 378 // Deprecated; remove in March 2016 (bug 5373). |
| 379 RTC_DEPRECATED scoped_ptr&& Pass() { |
| 380 return std::move(*this); |
| 381 } |
378 | 382 |
379 // Reset. Deletes the currently owned object, if any. | 383 // Reset. Deletes the currently owned object, if any. |
380 // Then takes ownership of a new object, if given. | 384 // Then takes ownership of a new object, if given. |
381 void reset(element_type* p = nullptr) { impl_.reset(p); } | 385 void reset(element_type* p = nullptr) { impl_.reset(p); } |
382 | 386 |
383 // Accessors to get the owned object. | 387 // Accessors to get the owned object. |
384 // operator* and operator-> will assert() if there is no current object. | 388 // operator* and operator-> will assert() if there is no current object. |
385 element_type& operator*() const { | 389 element_type& operator*() const { |
386 assert(impl_.get() != nullptr); | 390 assert(impl_.get() != nullptr); |
387 return *impl_.get(); | 391 return *impl_.get(); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 scoped_ptr& operator=(std::nullptr_t) { | 504 scoped_ptr& operator=(std::nullptr_t) { |
501 reset(); | 505 reset(); |
502 return *this; | 506 return *this; |
503 } | 507 } |
504 | 508 |
505 // Deleted copy constructor and copy assignment, to make the type move-only. | 509 // Deleted copy constructor and copy assignment, to make the type move-only. |
506 scoped_ptr(const scoped_ptr& other) = delete; | 510 scoped_ptr(const scoped_ptr& other) = delete; |
507 scoped_ptr& operator=(const scoped_ptr& other) = delete; | 511 scoped_ptr& operator=(const scoped_ptr& other) = delete; |
508 | 512 |
509 // Get an rvalue reference. (sp.Pass() does the same thing as std::move(sp).) | 513 // Get an rvalue reference. (sp.Pass() does the same thing as std::move(sp).) |
510 scoped_ptr&& Pass() { return std::move(*this); } | 514 // Deprecated; remove in March 2016 (bug 5373). |
| 515 RTC_DEPRECATED scoped_ptr&& Pass() { |
| 516 return std::move(*this); |
| 517 } |
511 | 518 |
512 // Reset. Deletes the currently owned array, if any. | 519 // Reset. Deletes the currently owned array, if any. |
513 // Then takes ownership of a new object, if given. | 520 // Then takes ownership of a new object, if given. |
514 void reset(element_type* array = nullptr) { impl_.reset(array); } | 521 void reset(element_type* array = nullptr) { impl_.reset(array); } |
515 | 522 |
516 // Accessors to get the owned array. | 523 // Accessors to get the owned array. |
517 element_type& operator[](size_t i) const { | 524 element_type& operator[](size_t i) const { |
518 assert(impl_.get() != nullptr); | 525 assert(impl_.get() != nullptr); |
519 return impl_.get()[i]; | 526 return impl_.get()[i]; |
520 } | 527 } |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 | 619 |
613 // A function to convert T* into scoped_ptr<T> | 620 // A function to convert T* into scoped_ptr<T> |
614 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation | 621 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation |
615 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) | 622 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) |
616 template <typename T> | 623 template <typename T> |
617 rtc::scoped_ptr<T> rtc_make_scoped_ptr(T* ptr) { | 624 rtc::scoped_ptr<T> rtc_make_scoped_ptr(T* ptr) { |
618 return rtc::scoped_ptr<T>(ptr); | 625 return rtc::scoped_ptr<T>(ptr); |
619 } | 626 } |
620 | 627 |
621 #endif // #ifndef WEBRTC_BASE_SCOPED_PTR_H__ | 628 #endif // #ifndef WEBRTC_BASE_SCOPED_PTR_H__ |
OLD | NEW |