Prepare for deletion of implicit conversion from rtc::scoped_refptr<T> to T*

Bug: webrtc:13464
Change-Id: I4c7095d3a1c7c1a9ab609f5f1595545f6cad18db
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/249087
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#36693}
This commit is contained in:
Niels Möller 2022-04-28 13:20:29 +02:00 committed by WebRTC LUCI CQ
parent 3801604bc7
commit 9432768024
5 changed files with 49 additions and 3 deletions

View File

@ -105,6 +105,7 @@ class scoped_refptr {
T* get() const { return ptr_; }
explicit operator bool() const { return ptr_ != nullptr; }
// TODO(bugs.webrtc.org/13464): Delete this conversion operator.
operator T*() const { return ptr_; }
T& operator*() const { return *ptr_; }
T* operator->() const { return ptr_; }
@ -162,6 +163,43 @@ class scoped_refptr {
T* ptr_;
};
template <typename T, typename U>
bool operator==(const rtc::scoped_refptr<T>& a,
const rtc::scoped_refptr<U>& b) {
return a.get() == b.get();
}
template <typename T, typename U>
bool operator!=(const rtc::scoped_refptr<T>& a,
const rtc::scoped_refptr<U>& b) {
return !(a == b);
}
template <typename T>
bool operator==(const rtc::scoped_refptr<T>& a, std::nullptr_t) {
return a.get() == nullptr;
}
template <typename T>
bool operator!=(const rtc::scoped_refptr<T>& a, std::nullptr_t) {
return !(a == nullptr);
}
template <typename T>
bool operator==(std::nullptr_t, const rtc::scoped_refptr<T>& a) {
return a.get() == nullptr;
}
template <typename T>
bool operator!=(std::nullptr_t, const rtc::scoped_refptr<T>& a) {
return !(a == nullptr);
}
// Ordered comparison, needed for use as a std::map key.
template <typename T, typename U>
bool operator<(const rtc::scoped_refptr<T>& a, const rtc::scoped_refptr<U>& b) {
return a.get() < b.get();
}
} // namespace rtc
#endif // API_SCOPED_REFPTR_H_

View File

@ -107,7 +107,7 @@ class ObserverForUsageHistogramTest : public MockPeerConnectionObserver {
candidate_target_ = other;
}
bool HaveDataChannel() { return last_datachannel_; }
bool HaveDataChannel() { return last_datachannel_ != nullptr; }
absl::optional<int> interesting_usage_detected() {
return interesting_usage_detected_;

View File

@ -587,6 +587,7 @@ rtc_library("checks") {
]
deps = [
":safe_compare",
"../api:scoped_refptr",
"system:inline",
"system:rtc_export",
]

View File

@ -56,6 +56,7 @@ RTC_NORETURN void rtc_FatalMessage(const char* file, int line, const char* msg);
#include "absl/meta/type_traits.h"
#include "absl/strings/string_view.h"
#include "api/scoped_refptr.h"
#include "rtc_base/numerics/safe_compare.h"
#include "rtc_base/system/inline.h"
#include "rtc_base/system/rtc_export.h"
@ -192,6 +193,12 @@ inline Val<CheckArgType::kVoidP, const void*> MakeVal(const void* x) {
return {x};
}
template <typename T>
inline Val<CheckArgType::kVoidP, const void*> MakeVal(
const rtc::scoped_refptr<T>& p) {
return {p.get()};
}
// The enum class types are not implicitly convertible to arithmetic types.
template <typename T,
absl::enable_if_t<std::is_enum<T>::value &&

View File

@ -31,11 +31,11 @@
#define WAIT_(ex, timeout, res) \
do { \
int64_t start = rtc::SystemTimeMillis(); \
res = (ex); \
res = (ex) && true; \
while (!res && rtc::SystemTimeMillis() < start + (timeout)) { \
rtc::Thread::Current()->ProcessMessages(0); \
rtc::Thread::Current()->SleepMs(1); \
res = (ex); \
res = (ex) && true; \
} \
} while (0)