Stop using 'using namespace'.
This CL removes all the instances of 'using namespace' from C++ code
(more info https://abseil.io/tips/153).
Bug: webrtc:9855
Change-Id: Ic940fe87c5047742cfa6d60857d2f97be380ed18
Reviewed-on: https://webrtc-review.googlesource.com/c/113948
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25985}
diff --git a/modules/audio_coding/codecs/isac/main/test/ReleaseTest-API/ReleaseTest-API.cc b/modules/audio_coding/codecs/isac/main/test/ReleaseTest-API/ReleaseTest-API.cc
index 35a8832..188e105 100644
--- a/modules/audio_coding/codecs/isac/main/test/ReleaseTest-API/ReleaseTest-API.cc
+++ b/modules/audio_coding/codecs/isac/main/test/ReleaseTest-API/ReleaseTest-API.cc
@@ -41,8 +41,6 @@
#endif
#endif
-using namespace std;
-
int main(int argc, char* argv[]) {
char inname[100], outname[100], bottleneck_file[100], vadfile[100];
FILE *inp, *outp, *f_bn = NULL, *vadp = NULL, *bandwidthp;
@@ -425,27 +423,27 @@
printf("Output file: %s\n\n", outname);
if ((inp = fopen(inname, "rb")) == NULL) {
printf(" Error iSAC Cannot read file %s.\n", inname);
- cout << flush;
+ std::cout << std::flush;
exit(1);
}
if ((outp = fopen(outname, "wb")) == NULL) {
printf(" Error iSAC Cannot write file %s.\n", outname);
- cout << flush;
+ std::cout << std::flush;
getc(stdin);
exit(1);
}
if (VADusage) {
if ((vadp = fopen(vadfile, "rb")) == NULL) {
printf(" Error iSAC Cannot read file %s.\n", vadfile);
- cout << flush;
+ std::cout << std::flush;
exit(1);
}
}
if ((bandwidthp = fopen("bwe.pcm", "wb")) == NULL) {
printf(" Error iSAC Cannot read file %s.\n", "bwe.pcm");
- cout << flush;
+ std::cout << std::flush;
exit(1);
}
@@ -472,7 +470,7 @@
/* Error check */
if (err < 0) {
printf("\n\n Error in create.\n\n");
- cout << flush;
+ std::cout << std::flush;
exit(EXIT_FAILURE);
}
}
@@ -508,7 +506,7 @@
if (testNum != 1) {
if (WebRtcIsac_EncoderInit(ISAC_main_inst, CodingMode) < 0) {
printf("Error could not initialize the encoder \n");
- cout << flush;
+ std::cout << std::flush;
return 0;
}
}
@@ -520,7 +518,7 @@
/* exit if returned with error */
errtype = WebRtcIsac_GetErrorCode(ISAC_main_inst);
printf("\n\n Error in initialization (control): %d.\n\n", errtype);
- cout << flush;
+ std::cout << std::flush;
if (testNum == 0) {
exit(EXIT_FAILURE);
}
@@ -534,7 +532,7 @@
errtype = WebRtcIsac_GetErrorCode(ISAC_main_inst);
printf("\n\n Error in Control BWE: %d.\n\n", errtype);
- cout << flush;
+ std::cout << std::flush;
exit(EXIT_FAILURE);
}
}
@@ -545,7 +543,7 @@
/* exit if returned with error */
errtype = WebRtcIsac_GetErrorCode(ISAC_main_inst);
printf("\n\n Error in SetMaxPayloadSize: %d.\n\n", errtype);
- cout << flush;
+ std::cout << std::flush;
exit(EXIT_FAILURE);
}
}
@@ -555,14 +553,14 @@
/* exit if returned with error */
errtype = WebRtcIsac_GetErrorCode(ISAC_main_inst);
printf("\n\n Error in SetMaxRateInBytes: %d.\n\n", errtype);
- cout << flush;
+ std::cout << std::flush;
exit(EXIT_FAILURE);
}
}
*speechType = 1;
- cout << "\n" << flush;
+ std::cout << "\n" << std::flush;
length_file = 0;
int16_t bnIdxTC = 0;
@@ -575,7 +573,7 @@
if (err < 0) {
errtype = WebRtcIsac_GetErrorCode(ISAC_main_inst);
printf("\n\n Error in encoderinit: %d.\n\n", errtype);
- cout << flush;
+ std::cout << std::flush;
}
WebRtcIsac_DecoderInit(ISAC_main_inst);
@@ -613,7 +611,7 @@
printf("\nError: Streamsize out of range %d\n",
stream_len_int - payloadSize);
- cout << flush;
+ std::cout << std::flush;
}
WebRtcIsac_GetUplinkBw(ISAC_main_inst, &sendBN);
@@ -671,7 +669,7 @@
/* exit if returned with error */
errtype = WebRtcIsac_GetErrorCode(ISAC_main_inst);
fprintf(stderr, "Error in encoder: %d.\n", errtype);
- cout << flush;
+ std::cout << std::flush;
exit(0);
}
stream_len = static_cast<size_t>(stream_len_int);
@@ -787,7 +785,7 @@
}
printf("Error: in decoder: %d.", errtype);
- cout << flush;
+ std::cout << std::flush;
if (testNum == 0) {
printf("\n\n");
}
@@ -804,7 +802,7 @@
printf("\n\n");
}
printf(" Error: in getFrameLen %d.", errtype);
- cout << flush;
+ std::cout << std::flush;
if (testNum == 0) {
printf("\n\n");
}
@@ -840,7 +838,7 @@
printf("\n\n");
}
printf(" Error: in decoder %d.", errtype);
- cout << flush;
+ std::cout << std::flush;
if (testNum == 0) {
printf("\n\n");
}
@@ -851,7 +849,7 @@
printf("\n\n");
}
printf(" Error: in decoding the transcoded stream");
- cout << flush;
+ std::cout << std::flush;
if (testNum == 0) {
printf("\n\n");
}
diff --git a/modules/audio_coding/codecs/isac/main/test/SwitchingSampRate/SwitchingSampRate.cc b/modules/audio_coding/codecs/isac/main/test/SwitchingSampRate/SwitchingSampRate.cc
index 59a3ade..549163f 100644
--- a/modules/audio_coding/codecs/isac/main/test/SwitchingSampRate/SwitchingSampRate.cc
+++ b/modules/audio_coding/codecs/isac/main/test/SwitchingSampRate/SwitchingSampRate.cc
@@ -23,8 +23,6 @@
#define NUM_CLIENTS 2
-using namespace std;
-
int main(int argc, char* argv[]) {
char fileNameWB[MAX_FILE_NAME];
char fileNameSWB[MAX_FILE_NAME];
@@ -306,7 +304,7 @@
// &rateIndexLB, &rateIndexUB);
// printf(" (%2d, %2d) ", rateIndexLB, rateIndexUB);
- cout << flush;
+ std::cout << std::flush;
lenEncodedInBytesTmp[senderIdx] = 0;
lenAudioIn10msTmp[senderIdx] = 0;
// if(senderIdx == (NUM_CLIENTS - 1))
diff --git a/rtc_base/base64_unittest.cc b/rtc_base/base64_unittest.cc
index a3ebc14..16dcd8d 100644
--- a/rtc_base/base64_unittest.cc
+++ b/rtc_base/base64_unittest.cc
@@ -18,8 +18,8 @@
#include "rtc_base/testbase64.h"
#include "test/gtest.h"
-using namespace std;
-using namespace rtc;
+namespace rtc {
+namespace {
static struct {
size_t plain_length;
@@ -337,7 +337,7 @@
size_t szdest) {
std::string escaped;
Base64::EncodeFromArray((const char*)src, szsrc, &escaped);
- memcpy(dest, escaped.data(), min(escaped.size(), szdest));
+ memcpy(dest, escaped.data(), std::min(escaped.size(), szdest));
return escaped.size();
}
@@ -348,7 +348,7 @@
std::string unescaped;
EXPECT_TRUE(
Base64::DecodeFromArray(src, szsrc, Base64::DO_LAX, &unescaped, nullptr));
- memcpy(dest, unescaped.data(), min(unescaped.size(), szdest));
+ memcpy(dest, unescaped.data(), std::min(unescaped.size(), szdest));
return unescaped.size();
}
@@ -1448,3 +1448,6 @@
EXPECT_FALSE(Base64::GetNextBase64Char('&', &next_char));
EXPECT_FALSE(Base64::GetNextBase64Char('Z', nullptr));
}
+
+} // namespace
+} // namespace rtc
diff --git a/rtc_base/messagequeue_unittest.cc b/rtc_base/messagequeue_unittest.cc
index d8e8b11..d04d753 100644
--- a/rtc_base/messagequeue_unittest.cc
+++ b/rtc_base/messagequeue_unittest.cc
@@ -23,7 +23,8 @@
#include "rtc_base/thread.h"
#include "rtc_base/timeutils.h"
-using namespace rtc;
+namespace rtc {
+namespace {
class MessageQueueTest : public testing::Test, public MessageQueue {
public:
@@ -231,3 +232,6 @@
t->Post(RTC_FROM_HERE, &handler, 0,
new ScopedRefMessageData<RefCountedHandler>(inner_handler));
}
+
+} // namespace
+} // namespace rtc
diff --git a/rtc_base/nat_unittest.cc b/rtc_base/nat_unittest.cc
index 8031dff..731bba6 100644
--- a/rtc_base/nat_unittest.cc
+++ b/rtc_base/nat_unittest.cc
@@ -37,7 +37,8 @@
#include "rtc_base/virtualsocketserver.h"
#include "test/gtest.h"
-using namespace rtc;
+namespace rtc {
+namespace {
bool CheckReceive(TestClient* client,
bool should_receive,
@@ -400,4 +401,6 @@
out->Send(buf, len);
EXPECT_TRUE(in->CheckNextPacket(buf, len, &trans_addr));
}
-// #endif
+
+} // namespace
+} // namespace rtc
diff --git a/rtc_base/signalthread_unittest.cc b/rtc_base/signalthread_unittest.cc
index 97c7eec..eeae030 100644
--- a/rtc_base/signalthread_unittest.cc
+++ b/rtc_base/signalthread_unittest.cc
@@ -17,7 +17,8 @@
#include "rtc_base/thread.h"
#include "test/gtest.h"
-using namespace rtc;
+namespace rtc {
+namespace {
// 10 seconds.
static const int kTimeout = 10000;
@@ -208,3 +209,6 @@
ExpectState(1, 0, 0, 1, 0);
ExpectStateWait(1, 1, 0, 1, 1, kTimeout);
}
+
+} // namespace
+} // namespace rtc
diff --git a/rtc_base/testclient_unittest.cc b/rtc_base/testclient_unittest.cc
index 742da74..d45a5a3 100644
--- a/rtc_base/testclient_unittest.cc
+++ b/rtc_base/testclient_unittest.cc
@@ -23,7 +23,8 @@
#include "rtc_base/thread.h"
#include "test/gtest.h"
-using namespace rtc;
+namespace rtc {
+namespace {
#define MAYBE_SKIP_IPV4 \
if (!HasIPv4Enabled()) { \
@@ -101,3 +102,6 @@
MAYBE_SKIP_IPV6;
TestTcpInternal(SocketAddress("::1", 0));
}
+
+} // namespace
+} // namespace rtc
diff --git a/rtc_base/testutils.h b/rtc_base/testutils.h
index 5a2a3bd..7ec0c12 100644
--- a/rtc_base/testutils.h
+++ b/rtc_base/testutils.h
@@ -23,8 +23,6 @@
namespace webrtc {
namespace testing {
-using namespace rtc;
-
///////////////////////////////////////////////////////////////////////////////
// StreamSink - Monitor asynchronously signalled events from StreamInterface
// or AsyncSocket (which should probably be a StreamInterface.
@@ -34,10 +32,10 @@
// event.
enum StreamSinkEvent {
- SSE_OPEN = SE_OPEN,
- SSE_READ = SE_READ,
- SSE_WRITE = SE_WRITE,
- SSE_CLOSE = SE_CLOSE,
+ SSE_OPEN = rtc::SE_OPEN,
+ SSE_READ = rtc::SE_READ,
+ SSE_WRITE = rtc::SE_WRITE,
+ SSE_CLOSE = rtc::SE_CLOSE,
SSE_ERROR = 16
};
@@ -46,25 +44,25 @@
StreamSink();
~StreamSink() override;
- void Monitor(StreamInterface* stream) {
+ void Monitor(rtc::StreamInterface* stream) {
stream->SignalEvent.connect(this, &StreamSink::OnEvent);
events_.erase(stream);
}
- void Unmonitor(StreamInterface* stream) {
+ void Unmonitor(rtc::StreamInterface* stream) {
stream->SignalEvent.disconnect(this);
// In case you forgot to unmonitor a previous object with this address
events_.erase(stream);
}
- bool Check(StreamInterface* stream,
+ bool Check(rtc::StreamInterface* stream,
StreamSinkEvent event,
bool reset = true) {
return DoCheck(stream, event, reset);
}
- int Events(StreamInterface* stream, bool reset = true) {
+ int Events(rtc::StreamInterface* stream, bool reset = true) {
return DoEvents(stream, reset);
}
- void Monitor(AsyncSocket* socket) {
+ void Monitor(rtc::AsyncSocket* socket) {
socket->SignalConnectEvent.connect(this, &StreamSink::OnConnectEvent);
socket->SignalReadEvent.connect(this, &StreamSink::OnReadEvent);
socket->SignalWriteEvent.connect(this, &StreamSink::OnWriteEvent);
@@ -72,33 +70,35 @@
// In case you forgot to unmonitor a previous object with this address
events_.erase(socket);
}
- void Unmonitor(AsyncSocket* socket) {
+ void Unmonitor(rtc::AsyncSocket* socket) {
socket->SignalConnectEvent.disconnect(this);
socket->SignalReadEvent.disconnect(this);
socket->SignalWriteEvent.disconnect(this);
socket->SignalCloseEvent.disconnect(this);
events_.erase(socket);
}
- bool Check(AsyncSocket* socket, StreamSinkEvent event, bool reset = true) {
+ bool Check(rtc::AsyncSocket* socket,
+ StreamSinkEvent event,
+ bool reset = true) {
return DoCheck(socket, event, reset);
}
- int Events(AsyncSocket* socket, bool reset = true) {
+ int Events(rtc::AsyncSocket* socket, bool reset = true) {
return DoEvents(socket, reset);
}
private:
typedef std::map<void*, int> EventMap;
- void OnEvent(StreamInterface* stream, int events, int error) {
+ void OnEvent(rtc::StreamInterface* stream, int events, int error) {
if (error) {
events = SSE_ERROR;
}
AddEvents(stream, events);
}
- void OnConnectEvent(AsyncSocket* socket) { AddEvents(socket, SSE_OPEN); }
- void OnReadEvent(AsyncSocket* socket) { AddEvents(socket, SSE_READ); }
- void OnWriteEvent(AsyncSocket* socket) { AddEvents(socket, SSE_WRITE); }
- void OnCloseEvent(AsyncSocket* socket, int error) {
+ void OnConnectEvent(rtc::AsyncSocket* socket) { AddEvents(socket, SSE_OPEN); }
+ void OnReadEvent(rtc::AsyncSocket* socket) { AddEvents(socket, SSE_READ); }
+ void OnWriteEvent(rtc::AsyncSocket* socket) { AddEvents(socket, SSE_WRITE); }
+ void OnCloseEvent(rtc::AsyncSocket* socket, int error) {
AddEvents(socket, (0 == error) ? SSE_CLOSE : SSE_ERROR);
}
diff --git a/rtc_base/thread_unittest.cc b/rtc_base/thread_unittest.cc
index 7e392af..68930f8 100644
--- a/rtc_base/thread_unittest.cc
+++ b/rtc_base/thread_unittest.cc
@@ -24,7 +24,8 @@
#include <comdef.h> // NOLINT
#endif
-using namespace rtc;
+namespace rtc {
+namespace {
// Generates a sequence of numbers (collaboratively).
class TestGenerator {
@@ -669,3 +670,6 @@
EXPECT_FALSE(flag1.get());
EXPECT_TRUE(flag2.get());
}
+
+} // namespace
+} // namespace rtc
diff --git a/rtc_base/virtualsocket_unittest.cc b/rtc_base/virtualsocket_unittest.cc
index 6c0ce24..77f0367 100644
--- a/rtc_base/virtualsocket_unittest.cc
+++ b/rtc_base/virtualsocket_unittest.cc
@@ -43,7 +43,8 @@
#include "rtc_base/virtualsocketserver.h"
#include "test/gtest.h"
-using namespace rtc;
+namespace rtc {
+namespace {
using webrtc::testing::SSE_CLOSE;
using webrtc::testing::SSE_ERROR;
@@ -1143,3 +1144,6 @@
}
}
}
+
+} // namespace
+} // namespace rtc