From 7356e8ae77b5dbe5df60ee0f8b3c65d38ce3bdbb Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 17 Jan 2015 21:46:12 +1100 Subject: [PATCH] Removed the dependencies on utility.*pp --- client/scenes/in_world.cpp | 5 +-- client/scenes/lobby_menu.cpp | 13 +++++--- common/utilities/utility.cpp | 48 --------------------------- common/utilities/utility.hpp | 34 ------------------- server/server_logic.cpp | 3 +- server/server_utilities/makefile | 2 +- server/server_utilities/sql_tools.cpp | 8 ++--- 7 files changed, 18 insertions(+), 95 deletions(-) delete mode 100644 common/utilities/utility.cpp delete mode 100644 common/utilities/utility.hpp diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index ec03408..42f35a2 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -22,7 +22,6 @@ #include "in_world.hpp" #include "channels.hpp" -#include "utility.hpp" #include "terminal_error.hpp" #include @@ -197,7 +196,9 @@ void InWorld::Render(SDL_Surface* const screen) { //draw UI disconnectButton.DrawTo(screen); shutDownButton.DrawTo(screen); - font.DrawStringTo(to_string_custom(fps.GetFrameRate()), screen, 0, 0); + std::ostringstream msg; + msg << fps.GetFrameRate(); + font.DrawStringTo(msg.str(), screen, 0, 0); } //------------------------- diff --git a/client/scenes/lobby_menu.cpp b/client/scenes/lobby_menu.cpp index 0776242..befc6f5 100644 --- a/client/scenes/lobby_menu.cpp +++ b/client/scenes/lobby_menu.cpp @@ -22,9 +22,9 @@ #include "lobby_menu.hpp" #include "channels.hpp" -#include "utility.hpp" #include +#include //------------------------- //Public access members @@ -123,7 +123,9 @@ void LobbyMenu::Render(SDL_Surface* const screen) { font.DrawStringTo(serverInfo[i].name, screen, listBox.x, listBox.y + i*listBox.h); //draw the player count - font.DrawStringTo(to_string_custom(serverInfo[i].playerCount), screen, listBox.x + listBox.w, listBox.y + i*listBox.h); + std::ostringstream msg; + msg << serverInfo[i].playerCount; + font.DrawStringTo(msg.str(), screen, listBox.x + listBox.w, listBox.y + i*listBox.h); //compatible? if (!serverInfo[i].compatible) { @@ -210,8 +212,11 @@ void LobbyMenu::HandlePacket(SerialPacket* const argPacket) { break; //handle errors - default: - throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in LobbyMenu: " + to_string_custom(static_cast(argPacket->type)) )); + default: { + std::ostringstream msg; + msg << "Unknown SerialPacketType encountered in LobbyMenu: " << static_cast(argPacket->type); + throw(std::runtime_error( msg.str() )); + } break; } } diff --git a/common/utilities/utility.cpp b/common/utilities/utility.cpp deleted file mode 100644 index 64b135b..0000000 --- a/common/utilities/utility.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. -*/ -#include "utility.hpp" - -#include - -std::string truncatePath(std::string pathname) { - return std::string( - std::find_if( - pathname.rbegin(), - pathname.rend(), - [](char ch) -> bool { - //windows & unix tested - return ch == '/' || ch == '\\'; - }).base(), - pathname.end()); -} - -std::string to_string_custom(int i) { - char buffer[20]; - snprintf(buffer, 20, "%d", i); - return std::string(buffer); -} - -int to_integer_custom(std::string s) { - int ret = 0; - sscanf(s.c_str(), "%d", &ret); - return ret; -} \ No newline at end of file diff --git a/common/utilities/utility.hpp b/common/utilities/utility.hpp deleted file mode 100644 index 53cb426..0000000 --- a/common/utilities/utility.hpp +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. -*/ -#ifndef UTILITY_HPP_ -#define UTILITY_HPP_ - -#include - -std::string truncatePath(std::string pathname); - -//fixing known bugs in g++ -std::string to_string_custom(int i); - -int to_integer_custom(std::string); - -#endif diff --git a/server/server_logic.cpp b/server/server_logic.cpp index 802c8c9..96ca1fe 100644 --- a/server/server_logic.cpp +++ b/server/server_logic.cpp @@ -23,7 +23,6 @@ //utility functions #include "sql_tools.hpp" -#include "utility.hpp" //std & STL #include @@ -307,7 +306,7 @@ void ServerApplication::HandlePacket(SerialPacket* const argPacket) { default: { std::ostringstream msg; msg << "Unknown SerialPacketType encountered in the server: "; - msg << to_string_custom(static_cast(argPacket->type)); + msg << static_cast(argPacket->type); throw(std::runtime_error(msg.str())); } break; diff --git a/server/server_utilities/makefile b/server/server_utilities/makefile index f24e1ba..8d12afe 100644 --- a/server/server_utilities/makefile +++ b/server/server_utilities/makefile @@ -1,5 +1,5 @@ #config -INCLUDES+=. ../../common/utilities +INCLUDES+=. LIBS+= CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) diff --git a/server/server_utilities/sql_tools.cpp b/server/server_utilities/sql_tools.cpp index d83acba..78e1065 100644 --- a/server/server_utilities/sql_tools.cpp +++ b/server/server_utilities/sql_tools.cpp @@ -21,10 +21,9 @@ */ #include "sql_tools.hpp" -#include "utility.hpp" - #include #include +#include #include int runSQLScript(sqlite3* db, std::string fname, int (*callback)(void*,int,char**,char**), void* argPtr) { @@ -42,9 +41,10 @@ int runSQLScript(sqlite3* db, std::string fname, int (*callback)(void*,int,char* int ret = sqlite3_exec(db, script.c_str(), callback, argPtr, &errmsg); if (ret != SQLITE_OK) { //handle any errors received from the SQL - std::runtime_error e(std::string() + "SQL Script Error " + to_string_custom(ret) + ": " + errmsg); + std::ostringstream msg; + msg << "SQL Script Error " << ret << ": " << errmsg; free(errmsg); - throw(e); + throw(std::runtime_error( msg.str() )); } return ret; } \ No newline at end of file