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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 81 |
82 // This is an implementation designed to match the anticipated future TR2 | 82 // This is an implementation designed to match the anticipated future TR2 |
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 #include <memory> |
91 | 92 |
92 #include "webrtc/base/constructormagic.h" | 93 #include "webrtc/base/constructormagic.h" |
93 #include "webrtc/base/deprecation.h" | 94 #include "webrtc/base/deprecation.h" |
94 #include "webrtc/base/template_util.h" | 95 #include "webrtc/base/template_util.h" |
95 #include "webrtc/typedefs.h" | 96 #include "webrtc/typedefs.h" |
96 | 97 |
97 namespace rtc { | 98 namespace rtc { |
98 | 99 |
99 // Function object which deletes its parameter, which must be a pointer. | 100 // Function object which deletes its parameter, which must be a pointer. |
100 // If C is an array type, invokes 'delete[]' on the parameter; otherwise, | 101 // If C is an array type, invokes 'delete[]' on the parameter; otherwise, |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 // scoped_ptrs. | 599 // scoped_ptrs. |
599 template <class U> bool operator==(scoped_ptr<U> const& p2) const; | 600 template <class U> bool operator==(scoped_ptr<U> const& p2) const; |
600 template <class U> bool operator!=(scoped_ptr<U> const& p2) const; | 601 template <class U> bool operator!=(scoped_ptr<U> const& p2) const; |
601 }; | 602 }; |
602 | 603 |
603 template <class T, class D> | 604 template <class T, class D> |
604 void swap(rtc::scoped_ptr<T, D>& p1, rtc::scoped_ptr<T, D>& p2) { | 605 void swap(rtc::scoped_ptr<T, D>& p1, rtc::scoped_ptr<T, D>& p2) { |
605 p1.swap(p2); | 606 p1.swap(p2); |
606 } | 607 } |
607 | 608 |
| 609 // Convert between the most common kinds of scoped_ptr and unique_ptr. |
| 610 template <typename T> |
| 611 std::unique_ptr<T> ScopedToUnique(scoped_ptr<T> sp) { |
| 612 return std::unique_ptr<T>(sp.release()); |
| 613 } |
| 614 template <typename T> |
| 615 scoped_ptr<T> UniqueToScoped(std::unique_ptr<T> up) { |
| 616 return scoped_ptr<T>(up.release()); |
| 617 } |
| 618 |
608 } // namespace rtc | 619 } // namespace rtc |
609 | 620 |
610 template <class T, class D> | 621 template <class T, class D> |
611 bool operator==(T* p1, const rtc::scoped_ptr<T, D>& p2) { | 622 bool operator==(T* p1, const rtc::scoped_ptr<T, D>& p2) { |
612 return p1 == p2.get(); | 623 return p1 == p2.get(); |
613 } | 624 } |
614 | 625 |
615 template <class T, class D> | 626 template <class T, class D> |
616 bool operator!=(T* p1, const rtc::scoped_ptr<T, D>& p2) { | 627 bool operator!=(T* p1, const rtc::scoped_ptr<T, D>& p2) { |
617 return p1 != p2.get(); | 628 return p1 != p2.get(); |
618 } | 629 } |
619 | 630 |
620 // A function to convert T* into scoped_ptr<T> | 631 // A function to convert T* into scoped_ptr<T> |
621 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation | 632 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation |
622 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) | 633 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) |
623 template <typename T> | 634 template <typename T> |
624 rtc::scoped_ptr<T> rtc_make_scoped_ptr(T* ptr) { | 635 rtc::scoped_ptr<T> rtc_make_scoped_ptr(T* ptr) { |
625 return rtc::scoped_ptr<T>(ptr); | 636 return rtc::scoped_ptr<T>(ptr); |
626 } | 637 } |
627 | 638 |
628 #endif // #ifndef WEBRTC_BASE_SCOPED_PTR_H__ | 639 #endif // #ifndef WEBRTC_BASE_SCOPED_PTR_H__ |
OLD | NEW |