From 59ce0b59d46f9ac1b49473d6ec15dd35a1c3ad98 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 19 Feb 2012 18:47:09 -0800 Subject: [PATCH] Cleanup --- main.cpp | 25 +++++++++++++------------ mc_client.cpp | 16 ++++++++-------- mc_client.hpp | 8 ++++---- mc_packet.hpp | 2 +- mc_protocol.cpp | 2 +- mc_server.cpp | 8 ++++---- mc_server.hpp | 4 ++-- mc_stream.cpp | 8 ++++---- mc_stream.hpp | 4 ++-- 9 files changed, 39 insertions(+), 38 deletions(-) diff --git a/main.cpp b/main.cpp index 4edfcf6..7fe0844 100644 --- a/main.cpp +++ b/main.cpp @@ -35,7 +35,7 @@ using namespace metacall; #define TEST_UNICODE #define TEST_ANSI -//#define TEST_C_STRING +#define TEST_C_STRING #define TEST_BASIC_STRING @@ -85,20 +85,18 @@ int main(int, char *[]) { return 1; } - server.binding()->bind(FPARAM(testCStrAnsi)); - server.binding()->bind(FPARAM(testCStrUnicode)); - - server.binding()->bind(FPARAM(testBasicStringAnsi)); - server.binding()->bind(FPARAM(testBasicStringUnicode)); + Binding& binding = server.binding(); + Protocol& protocol = client.protocol(); do { - Protocol* const protocol = client.protocol(); - // // C string // #ifdef TEST_C_STRING { + binding.bind(FPARAM(testCStrAnsi)); + binding.bind(FPARAM(testCStrUnicode)); + // // ANSI // @@ -106,7 +104,7 @@ int main(int, char *[]) { { const char* strings[] = { "Hello world", "", NULL }; for (int i = 0; i < 3; ++i) { - protocol->invoke("testCStrAnsi", strings[i]); + protocol.invoke("testCStrAnsi", strings[i]); } } #endif @@ -117,7 +115,7 @@ int main(int, char *[]) { { const wchar_t* strings[] = { L"Hello world", L"", NULL }; for (int i = 0; i < 3; ++i) { - protocol->invoke("testCStrUnicode", strings[i]); + protocol.invoke("testCStrUnicode", strings[i]); } } #endif @@ -130,6 +128,9 @@ int main(int, char *[]) { // #ifdef TEST_BASIC_STRING { + binding.bind(FPARAM(testBasicStringAnsi)); + binding.bind(FPARAM(testBasicStringUnicode)); + // // ANSI // @@ -137,7 +138,7 @@ int main(int, char *[]) { { std::string strings[] = { std::string("Hello world"), std::string() }; for (int i = 0; i < 2; ++i) { - protocol->invoke("testBasicStringAnsi", strings[i]); + protocol.invoke("testBasicStringAnsi", strings[i]); } } #endif @@ -148,7 +149,7 @@ int main(int, char *[]) { { std::wstring strings[] = { std::wstring(L"Hello world"), std::wstring() }; for (int i = 0; i < 2; ++i) { - protocol->invoke("testBasicStringUnicode", strings[i]); + protocol.invoke("testBasicStringUnicode", strings[i]); } } #endif diff --git a/mc_client.cpp b/mc_client.cpp index 8f3990f..bbd5b31 100644 --- a/mc_client.cpp +++ b/mc_client.cpp @@ -76,20 +76,20 @@ bool Client::connected() const { return m_socket.connected(); } -const Protocol* Client::protocol() const { - return &m_protocol; +const Protocol& Client::protocol() const { + return m_protocol; } -Protocol* Client::protocol() { - return &m_protocol; +Protocol& Client::protocol() { + return m_protocol; } -const Binding* Client::binding() const { - return &m_binding; +const Binding& Client::binding() const { + return m_binding; } -Binding* Client::binding() { - return &m_binding; +Binding& Client::binding() { + return m_binding; } diff --git a/mc_client.hpp b/mc_client.hpp index fe28b0e..3a99508 100644 --- a/mc_client.hpp +++ b/mc_client.hpp @@ -41,10 +41,10 @@ public: void disconnect(); bool connected() const; - const Protocol* protocol() const; - Protocol* protocol(); - const Binding* binding() const; - Binding* binding(); + const Protocol& protocol() const; + Protocol& protocol(); + const Binding& binding() const; + Binding& binding(); private: Socket m_socket; diff --git a/mc_packet.hpp b/mc_packet.hpp index 292207f..19ad4f8 100644 --- a/mc_packet.hpp +++ b/mc_packet.hpp @@ -127,7 +127,7 @@ struct PacketInvokeReply { enum { FLAG_UNBOUND_FUNC = 1 << 0, - FLAG_INVALID_ARGS = 1 << 1, + FLAG_INVALID_ARGS = 1 << 1 }; bool serialize(Serializer* serializer) const { diff --git a/mc_protocol.cpp b/mc_protocol.cpp index c1291d6..e01d984 100644 --- a/mc_protocol.cpp +++ b/mc_protocol.cpp @@ -40,7 +40,7 @@ Protocol::Protocol(Stream* stream, Binding* binding) : } void Protocol::advance() { - if (!m_stream->socket()->connected()) { + if (!m_stream->socket().connected()) { return; } diff --git a/mc_server.cpp b/mc_server.cpp index 1f36540..6548b11 100644 --- a/mc_server.cpp +++ b/mc_server.cpp @@ -48,12 +48,12 @@ void Server::advance() { advanceConnected(); } -const Binding* Server::binding() const { - return &m_binding; +const Binding& Server::binding() const { + return m_binding; } -Binding* Server::binding() { - return &m_binding; +Binding& Server::binding() { + return m_binding; } bool Server::start(int serverPort, int clientsMax) { diff --git a/mc_server.hpp b/mc_server.hpp index ce7c70b..5c64dee 100644 --- a/mc_server.hpp +++ b/mc_server.hpp @@ -63,8 +63,8 @@ public: bool clients(ClientId id, ClientData* data) const; ClientId clientActive() const; int clientCount() const; - const Binding* binding() const; - Binding* binding(); + const Binding& binding() const; + Binding& binding(); private: struct ClientEntry : public ClientData { diff --git a/mc_stream.cpp b/mc_stream.cpp index 16f30d8..b44d74b 100644 --- a/mc_stream.cpp +++ b/mc_stream.cpp @@ -110,12 +110,12 @@ Stream::State Stream::peek(PacketHeader* header, int* headerSize) { return STATE_READY; } -const Socket* Stream::socket() const { - return m_socket; +const Socket& Stream::socket() const { + return *m_socket; } -Socket* Stream::socket() { - return m_socket; +Socket& Stream::socket() { + return *m_socket; } diff --git a/mc_stream.hpp b/mc_stream.hpp index d9a7d1b..5311894 100644 --- a/mc_stream.hpp +++ b/mc_stream.hpp @@ -53,8 +53,8 @@ class Stream { State receive(T* packet); State peek(PacketHeader* header, int* headerSize); - const Socket* socket() const; - Socket* socket(); + const Socket& socket() const; + Socket& socket(); private: Socket* m_socket;