From d9526499d6ab53b7d13d1434f748f6f2161c2e0a Mon Sep 17 00:00:00 2001 From: Sebastien Gonzalve Date: Thu, 20 Feb 2014 22:28:03 +0100 Subject: Remove using std::XXX from headers This is a bad practice to have using in headers because it pollutes the namespace of any user of that header. --- remote-processor/AnswerMessage.cpp | 2 ++ remote-processor/AnswerMessage.h | 8 ++++---- remote-processor/ConnectionSocket.cpp | 4 +++- remote-processor/ConnectionSocket.h | 4 +--- remote-processor/ListeningSocket.cpp | 6 ++++-- remote-processor/Message.cpp | 2 ++ remote-processor/Message.h | 8 +++----- remote-processor/RemoteProcessorServer.cpp | 8 +++++--- remote-processor/RemoteProcessorServerInterface.h | 2 -- remote-processor/RequestMessage.cpp | 2 ++ remote-processor/RequestMessage.h | 21 +++++++++++---------- remote-processor/Socket.h | 2 -- 12 files changed, 37 insertions(+), 32 deletions(-) (limited to 'remote-processor') diff --git a/remote-processor/AnswerMessage.cpp b/remote-processor/AnswerMessage.cpp index 30f2c4f..341917e 100644 --- a/remote-processor/AnswerMessage.cpp +++ b/remote-processor/AnswerMessage.cpp @@ -33,6 +33,8 @@ #define base CMessage +using std::string; + CAnswerMessage::CAnswerMessage(const string& strAnswer, bool bSuccess) : base(bSuccess ? ESuccessAnswer : EFailureAnswer), _strAnswer(strAnswer) { } diff --git a/remote-processor/AnswerMessage.h b/remote-processor/AnswerMessage.h index 9b865e8..3f50e7e 100644 --- a/remote-processor/AnswerMessage.h +++ b/remote-processor/AnswerMessage.h @@ -34,11 +34,11 @@ class CAnswerMessage : public CMessage { public: - CAnswerMessage(const string& strAnswer, bool bSuccess); + CAnswerMessage(const std::string& strAnswer, bool bSuccess); CAnswerMessage(); // Answer - const string& getAnswer() const; + const std::string& getAnswer() const; // Status bool success() const; @@ -50,9 +50,9 @@ private: // Size virtual uint32_t getDataSize() const; // Answer - void setAnswer(const string& strAnswer); + void setAnswer(const std::string& strAnswer); // Answer - string _strAnswer; + std::string _strAnswer; }; diff --git a/remote-processor/ConnectionSocket.cpp b/remote-processor/ConnectionSocket.cpp index 41edeaa..5b5de45 100644 --- a/remote-processor/ConnectionSocket.cpp +++ b/remote-processor/ConnectionSocket.cpp @@ -37,6 +37,8 @@ #define base CSocket +using std::string; + CConnectionSocket::CConnectionSocket() { } @@ -63,7 +65,7 @@ bool CConnectionSocket::connect(const string& strRemote, uint16_t uiPort, string // Connect if (::connect(getFd(), (struct sockaddr *)&server_addr, sizeof(struct sockaddr))) { - ostringstream oss; + std::ostringstream oss; oss << "CConnectionSocket::connect::connect on port: " << uiPort; perror(oss.str().c_str()); diff --git a/remote-processor/ConnectionSocket.h b/remote-processor/ConnectionSocket.h index c90fc66..707579b 100644 --- a/remote-processor/ConnectionSocket.h +++ b/remote-processor/ConnectionSocket.h @@ -33,14 +33,12 @@ #include -using namespace std; - class CConnectionSocket : public CSocket { public: CConnectionSocket(); // Connection - bool connect(const string& strRemote, uint16_t uiPort, string& strError); + bool connect(const std::string& strRemote, uint16_t uiPort, std::string& strError); }; diff --git a/remote-processor/ListeningSocket.cpp b/remote-processor/ListeningSocket.cpp index 7d6f9e8..1677d71 100644 --- a/remote-processor/ListeningSocket.cpp +++ b/remote-processor/ListeningSocket.cpp @@ -42,6 +42,8 @@ #define base CSocket +using std::string; + CListeningSocket::CListeningSocket() { int iOption = true; @@ -60,7 +62,7 @@ bool CListeningSocket::listen(uint16_t uiPort) // Bind if (bind(getFd(), (struct sockaddr*)&server_addr, sizeof(struct sockaddr)) == -1) { - ostringstream oss; + std::ostringstream oss; oss << "CListeningSocket::listen::bind port " << uiPort; perror(oss.str().c_str()); @@ -69,7 +71,7 @@ bool CListeningSocket::listen(uint16_t uiPort) if (::listen(getFd(), 5) == -1) { - ostringstream oss; + std::ostringstream oss; oss << "CListeningSocket::listen::bind port " << uiPort; perror(oss.str().c_str()); diff --git a/remote-processor/Message.cpp b/remote-processor/Message.cpp index 8591847..9df038c 100644 --- a/remote-processor/Message.cpp +++ b/remote-processor/Message.cpp @@ -35,6 +35,8 @@ #include #include +using std::string; + CMessage::CMessage(uint8_t ucMsgId) : _ucMsgId(ucMsgId), _pucData(NULL), _uiDataSize(0), _uiIndex(0) { } diff --git a/remote-processor/Message.h b/remote-processor/Message.h index feafc83..2e52c09 100644 --- a/remote-processor/Message.h +++ b/remote-processor/Message.h @@ -32,8 +32,6 @@ #include #include -using namespace std; - class CSocket; class CMessage @@ -69,9 +67,9 @@ protected: // Data void writeData(const void* pvData, uint32_t uiSize); void readData(void* pvData, uint32_t uiSize); - void writeString(const string& strData); - void readString(string& strData); - uint32_t getStringSize(const string& strData) const; + void writeString(const std::string& strData); + void readString(std::string& strData); + uint32_t getStringSize(const std::string& strData) const; // Remaining data size uint32_t getRemainingDataSize() const; private: diff --git a/remote-processor/RemoteProcessorServer.cpp b/remote-processor/RemoteProcessorServer.cpp index 8c66109..dff935b 100644 --- a/remote-processor/RemoteProcessorServer.cpp +++ b/remote-processor/RemoteProcessorServer.cpp @@ -39,6 +39,8 @@ #include "AnswerMessage.h" #include "RemoteCommandHandler.h" +using std::string; + CRemoteProcessorServer::CRemoteProcessorServer(uint16_t uiPort, IRemoteCommandHandler* pCommandHandler) : _uiPort(uiPort), _pCommandHandler(pCommandHandler), _bIsStarted(false), _pListeningSocket(NULL), _ulThreadId(0) { @@ -148,7 +150,7 @@ void CRemoteProcessorServer::run() // New connection void CRemoteProcessorServer::handleNewConnection() { - const auto_ptr clientSocket(_pListeningSocket->accept()); + const std::auto_ptr clientSocket(_pListeningSocket->accept()); if (clientSocket.get() == NULL) { @@ -172,7 +174,7 @@ void CRemoteProcessorServer::handleNewConnection() switch (res) { case CRequestMessage::error: - cout << "Error while receiving message: " << strError << endl; + std::cout << "Error while receiving message: " << strError << std::endl; // fall through case CRequestMessage::peerDisconnected: // Consider peer disconnection as normal, no log @@ -209,7 +211,7 @@ void CRemoteProcessorServer::handleNewConnection() // Peer should not disconnect while waiting for an answer // Fall through to log the error and bail out case CRequestMessage::error: - cout << "Error while receiving message: " << strError << endl; + std::cout << "Error while receiving message: " << strError << std::endl; return; // Bail out case CRequestMessage::success: break; // No error, continue diff --git a/remote-processor/RemoteProcessorServerInterface.h b/remote-processor/RemoteProcessorServerInterface.h index 9b1b0a5..19a799c 100644 --- a/remote-processor/RemoteProcessorServerInterface.h +++ b/remote-processor/RemoteProcessorServerInterface.h @@ -31,8 +31,6 @@ #include "RequestMessage.h" -using namespace std; - class IRemoteProcessorServerInterface { public: diff --git a/remote-processor/RequestMessage.cpp b/remote-processor/RequestMessage.cpp index cc48cc3..32b25f6 100644 --- a/remote-processor/RequestMessage.cpp +++ b/remote-processor/RequestMessage.cpp @@ -35,6 +35,8 @@ #define base CMessage +using std::string; + const char* const CRequestMessage::gacDelimiters = " \t\n\v\f\r"; CRequestMessage::CRequestMessage(const string& strCommand) : base(ECommandRequest), _strCommand(strCommand) diff --git a/remote-processor/RequestMessage.h b/remote-processor/RequestMessage.h index 7104e36..17f433b 100644 --- a/remote-processor/RequestMessage.h +++ b/remote-processor/RequestMessage.h @@ -32,22 +32,23 @@ #include "Message.h" #include "RemoteCommand.h" #include +#include class CRequestMessage : public CMessage, public IRemoteCommand { public: - CRequestMessage(const string& strCommand); + CRequestMessage(const std::string& strCommand); CRequestMessage(); // Command Name - void setCommand(const string& strCommand); - virtual const string& getCommand() const; + void setCommand(const std::string& strCommand); + virtual const std::string& getCommand() const; // Arguments - virtual void addArgument(const string& strArgument); + virtual void addArgument(const std::string& strArgument); virtual uint32_t getArgumentCount() const; - virtual const string& getArgument(uint32_t uiArgument) const; - virtual const string packArguments(uint32_t uiStartArgument, uint32_t uiNbArguments) const; + virtual const std::string& getArgument(uint32_t uiArgument) const; + virtual const std::string packArguments(uint32_t uiStartArgument, uint32_t uiNbArguments) const; private: @@ -64,12 +65,12 @@ private: virtual void collectReceivedData(); // Size virtual uint32_t getDataSize() const; - // Trim input string - static string trim(const string& strToTrim); + // Trim input std::string + static std::string trim(const std::string& strToTrim); // Command - string _strCommand; + std::string _strCommand; // Arguments - vector _argumentVector; + std::vector _argumentVector; }; diff --git a/remote-processor/Socket.h b/remote-processor/Socket.h index e8d360f..00bd8bc 100644 --- a/remote-processor/Socket.h +++ b/remote-processor/Socket.h @@ -32,8 +32,6 @@ #include #include -using namespace std; - struct sockaddr_in; struct in_addr; -- cgit v1.1