| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 #include <memory> | 91 #include <memory> |
| 92 | 92 |
| 93 #include "webrtc/base/constructormagic.h" | 93 #include "webrtc/base/constructormagic.h" |
| 94 #include "webrtc/base/deprecation.h" | |
| 95 #include "webrtc/base/template_util.h" | 94 #include "webrtc/base/template_util.h" |
| 96 #include "webrtc/typedefs.h" | 95 #include "webrtc/typedefs.h" |
| 97 | 96 |
| 98 namespace rtc { | 97 namespace rtc { |
| 99 | 98 |
| 100 // Function object which deletes its parameter, which must be a pointer. | 99 // Function object which deletes its parameter, which must be a pointer. |
| 101 // 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, |
| 102 // invokes 'delete'. The default deleter for scoped_ptr<T>. | 101 // invokes 'delete'. The default deleter for scoped_ptr<T>. |
| 103 template <class T> | 102 template <class T> |
| 104 struct DefaultDeleter { | 103 struct DefaultDeleter { |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 // object, if any. | 367 // object, if any. |
| 369 scoped_ptr& operator=(std::nullptr_t) { | 368 scoped_ptr& operator=(std::nullptr_t) { |
| 370 reset(); | 369 reset(); |
| 371 return *this; | 370 return *this; |
| 372 } | 371 } |
| 373 | 372 |
| 374 // 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. |
| 375 scoped_ptr(const scoped_ptr& other) = delete; | 374 scoped_ptr(const scoped_ptr& other) = delete; |
| 376 scoped_ptr& operator=(const scoped_ptr& other) = delete; | 375 scoped_ptr& operator=(const scoped_ptr& other) = delete; |
| 377 | 376 |
| 378 // Get an rvalue reference. (sp.Pass() does the same thing as std::move(sp).) | |
| 379 // Deprecated; remove in March 2016 (bug 5373). | |
| 380 RTC_DEPRECATED scoped_ptr&& Pass() { | |
| 381 return std::move(*this); | |
| 382 } | |
| 383 | |
| 384 // Reset. Deletes the currently owned object, if any. | 377 // Reset. Deletes the currently owned object, if any. |
| 385 // Then takes ownership of a new object, if given. | 378 // Then takes ownership of a new object, if given. |
| 386 void reset(element_type* p = nullptr) { impl_.reset(p); } | 379 void reset(element_type* p = nullptr) { impl_.reset(p); } |
| 387 | 380 |
| 388 // Accessors to get the owned object. | 381 // Accessors to get the owned object. |
| 389 // operator* and operator-> will assert() if there is no current object. | 382 // operator* and operator-> will assert() if there is no current object. |
| 390 element_type& operator*() const { | 383 element_type& operator*() const { |
| 391 assert(impl_.get() != nullptr); | 384 assert(impl_.get() != nullptr); |
| 392 return *impl_.get(); | 385 return *impl_.get(); |
| 393 } | 386 } |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 // array, if any. | 497 // array, if any. |
| 505 scoped_ptr& operator=(std::nullptr_t) { | 498 scoped_ptr& operator=(std::nullptr_t) { |
| 506 reset(); | 499 reset(); |
| 507 return *this; | 500 return *this; |
| 508 } | 501 } |
| 509 | 502 |
| 510 // Deleted copy constructor and copy assignment, to make the type move-only. | 503 // Deleted copy constructor and copy assignment, to make the type move-only. |
| 511 scoped_ptr(const scoped_ptr& other) = delete; | 504 scoped_ptr(const scoped_ptr& other) = delete; |
| 512 scoped_ptr& operator=(const scoped_ptr& other) = delete; | 505 scoped_ptr& operator=(const scoped_ptr& other) = delete; |
| 513 | 506 |
| 514 // Get an rvalue reference. (sp.Pass() does the same thing as std::move(sp).) | |
| 515 // Deprecated; remove in March 2016 (bug 5373). | |
| 516 RTC_DEPRECATED scoped_ptr&& Pass() { | |
| 517 return std::move(*this); | |
| 518 } | |
| 519 | |
| 520 // Reset. Deletes the currently owned array, if any. | 507 // Reset. Deletes the currently owned array, if any. |
| 521 // Then takes ownership of a new object, if given. | 508 // Then takes ownership of a new object, if given. |
| 522 void reset(element_type* array = nullptr) { impl_.reset(array); } | 509 void reset(element_type* array = nullptr) { impl_.reset(array); } |
| 523 | 510 |
| 524 // Accessors to get the owned array. | 511 // Accessors to get the owned array. |
| 525 element_type& operator[](size_t i) const { | 512 element_type& operator[](size_t i) const { |
| 526 assert(impl_.get() != nullptr); | 513 assert(impl_.get() != nullptr); |
| 527 return impl_.get()[i]; | 514 return impl_.get()[i]; |
| 528 } | 515 } |
| 529 element_type* get() const { return impl_.get(); } | 516 element_type* get() const { return impl_.get(); } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 | 617 |
| 631 // A function to convert T* into scoped_ptr<T> | 618 // A function to convert T* into scoped_ptr<T> |
| 632 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation | 619 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation |
| 633 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) | 620 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) |
| 634 template <typename T> | 621 template <typename T> |
| 635 rtc::scoped_ptr<T> rtc_make_scoped_ptr(T* ptr) { | 622 rtc::scoped_ptr<T> rtc_make_scoped_ptr(T* ptr) { |
| 636 return rtc::scoped_ptr<T>(ptr); | 623 return rtc::scoped_ptr<T>(ptr); |
| 637 } | 624 } |
| 638 | 625 |
| 639 #endif // #ifndef WEBRTC_BASE_SCOPED_PTR_H__ | 626 #endif // #ifndef WEBRTC_BASE_SCOPED_PTR_H__ |
| OLD | NEW |