Add ToString() methods to classes with << operators, preparing for deprecations.
Bug: webrtc:8982
Change-Id: I9b8792a229539dd9848f4d9936fe343f4bf9ad49
Reviewed-on: https://webrtc-review.googlesource.com/63200
Commit-Queue: Jonas Olsson <jonasolsson@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22705}diff --git a/api/rtcerror.cc b/api/rtcerror.cc
index f9a31d0..5a8ba03 100644
--- a/api/rtcerror.cc
+++ b/api/rtcerror.cc
@@ -94,8 +94,13 @@
}
std::ostream& operator<<(std::ostream& stream, RTCErrorType error) {
+ return stream << ToString(error);
+}
+
+// TODO(jonasolsson): Change to use absl::string_view when it's available.
+std::string ToString(RTCErrorType error) {
int index = static_cast<int>(error);
- return stream << kRTCErrorTypeNames[index];
+ return std::string(kRTCErrorTypeNames[index]);
}
} // namespace webrtc
diff --git a/api/rtcerror.h b/api/rtcerror.h
index 962f46d..760bad8 100644
--- a/api/rtcerror.h
+++ b/api/rtcerror.h
@@ -145,6 +145,8 @@
// Only intended to be used for logging/disagnostics.
std::ostream& operator<<(std::ostream& stream, RTCErrorType error);
+std::string ToString(RTCErrorType error);
+
// Helper macro that can be used by implementations to create an error with a
// message and log it. |message| should be a string literal or movable
// std::string.