mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 13:50:40 +01:00

This is a reland ofd7ee72041f
Original change's description: > Reland "Remove our stream << overloads from non-test build targets." > > This is a reland ofc841d18d25
> > Original change's description: > > Remove our stream << overloads from non-test build targets. > > > > Most are removed entirely, but RtcErrorType, RtpTransceiverDirection, IPAddress and > > SocketAddress are kept behind gtest's #ifdef UNIT_TEST. > > > > Bug: webrtc:8982 > > Change-Id: I36db19891e7d25aeacb08b9a08aa2b4004765e70 > > Reviewed-on: https://webrtc-review.googlesource.com/64143 > > Commit-Queue: Jonas Olsson <jonasolsson@webrtc.org> > > Reviewed-by: Benjamin Wright <benwright@webrtc.org> > > Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org> > > Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> > > Reviewed-by: Åsa Persson <asapersson@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#22916} > > > Bug: webrtc:8982 > Change-Id: Ibe08c6270e5e693eb661a6ce9e8f074b34ef8123 > Reviewed-on: https://webrtc-review.googlesource.com/71161 > Commit-Queue: Jonas Olsson <jonasolsson@webrtc.org> > Reviewed-by: Jonas Olsson <jonasolsson@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#22949} TBR=deadbeef@webrtc.org,kwiberg@webrtc.org,asapersson@webrtc.org,jonasolsson@webrtc.org,benwright@webrtc.org Bug: webrtc:8982 Change-Id: I29247d1c28e99af36ef228d8c75b4adecbd7b199 Reviewed-on: https://webrtc-review.googlesource.com/72681 Commit-Queue: Jonas Olsson <jonasolsson@webrtc.org> Reviewed-by: Jonas Olsson <jonasolsson@webrtc.org> Cr-Commit-Position: refs/heads/master@{#23092}
102 lines
2.6 KiB
C++
102 lines
2.6 KiB
C++
/*
|
|
* Copyright 2017 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include "api/rtcerror.h"
|
|
|
|
#include "rtc_base/arraysize.h"
|
|
|
|
namespace {
|
|
|
|
static const char* const kRTCErrorTypeNames[] = {
|
|
"NONE",
|
|
"UNSUPPORTED_OPERATION",
|
|
"UNSUPPORTED_PARAMETER",
|
|
"INVALID_PARAMETER",
|
|
"INVALID_RANGE",
|
|
"SYNTAX_ERROR",
|
|
"INVALID_STATE",
|
|
"INVALID_MODIFICATION",
|
|
"NETWORK_ERROR",
|
|
"RESOURCE_EXHAUSTED",
|
|
"INTERNAL_ERROR",
|
|
};
|
|
static_assert(static_cast<int>(webrtc::RTCErrorType::INTERNAL_ERROR) ==
|
|
(arraysize(kRTCErrorTypeNames) - 1),
|
|
"kRTCErrorTypeNames must have as many strings as RTCErrorType "
|
|
"has values.");
|
|
|
|
} // namespace
|
|
|
|
namespace webrtc {
|
|
|
|
RTCError::RTCError(RTCError&& other)
|
|
: type_(other.type_), have_string_message_(other.have_string_message_) {
|
|
if (have_string_message_) {
|
|
new (&string_message_) std::string(std::move(other.string_message_));
|
|
} else {
|
|
static_message_ = other.static_message_;
|
|
}
|
|
}
|
|
|
|
RTCError& RTCError::operator=(RTCError&& other) {
|
|
type_ = other.type_;
|
|
if (other.have_string_message_) {
|
|
set_message(std::move(other.string_message_));
|
|
} else {
|
|
set_message(other.static_message_);
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
RTCError::~RTCError() {
|
|
// If we hold a message string that was built, rather than a static string,
|
|
// we need to delete it.
|
|
if (have_string_message_) {
|
|
string_message_.~basic_string();
|
|
}
|
|
}
|
|
|
|
// static
|
|
RTCError RTCError::OK() {
|
|
return RTCError();
|
|
}
|
|
|
|
const char* RTCError::message() const {
|
|
if (have_string_message_) {
|
|
return string_message_.c_str();
|
|
} else {
|
|
return static_message_;
|
|
}
|
|
}
|
|
|
|
void RTCError::set_message(const char* message) {
|
|
if (have_string_message_) {
|
|
string_message_.~basic_string();
|
|
have_string_message_ = false;
|
|
}
|
|
static_message_ = message;
|
|
}
|
|
|
|
void RTCError::set_message(std::string&& message) {
|
|
if (!have_string_message_) {
|
|
new (&string_message_) std::string(std::move(message));
|
|
have_string_message_ = true;
|
|
} else {
|
|
string_message_ = message;
|
|
}
|
|
}
|
|
|
|
// TODO(jonasolsson): Change to use absl::string_view when it's available.
|
|
std::string ToString(RTCErrorType error) {
|
|
int index = static_cast<int>(error);
|
|
return std::string(kRTCErrorTypeNames[index]);
|
|
}
|
|
|
|
} // namespace webrtc
|