Removed the dependencies on utility.*pp

This commit is contained in:
Kayne Ruse
2015-01-17 21:46:12 +11:00
parent de6eb38516
commit 7356e8ae77
7 changed files with 18 additions and 95 deletions
+3 -2
View File
@@ -22,7 +22,6 @@
#include "in_world.hpp" #include "in_world.hpp"
#include "channels.hpp" #include "channels.hpp"
#include "utility.hpp"
#include "terminal_error.hpp" #include "terminal_error.hpp"
#include <stdexcept> #include <stdexcept>
@@ -197,7 +196,9 @@ void InWorld::Render(SDL_Surface* const screen) {
//draw UI //draw UI
disconnectButton.DrawTo(screen); disconnectButton.DrawTo(screen);
shutDownButton.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);
} }
//------------------------- //-------------------------
+9 -4
View File
@@ -22,9 +22,9 @@
#include "lobby_menu.hpp" #include "lobby_menu.hpp"
#include "channels.hpp" #include "channels.hpp"
#include "utility.hpp"
#include <stdexcept> #include <stdexcept>
#include <sstream>
//------------------------- //-------------------------
//Public access members //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); font.DrawStringTo(serverInfo[i].name, screen, listBox.x, listBox.y + i*listBox.h);
//draw the player count //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? //compatible?
if (!serverInfo[i].compatible) { if (!serverInfo[i].compatible) {
@@ -210,8 +212,11 @@ void LobbyMenu::HandlePacket(SerialPacket* const argPacket) {
break; break;
//handle errors //handle errors
default: default: {
throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in LobbyMenu: " + to_string_custom(static_cast<int>(argPacket->type)) )); std::ostringstream msg;
msg << "Unknown SerialPacketType encountered in LobbyMenu: " << static_cast<int>(argPacket->type);
throw(std::runtime_error( msg.str() ));
}
break; break;
} }
} }
-48
View File
@@ -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 <algorithm>
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;
}
-34
View File
@@ -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 <string>
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
+1 -2
View File
@@ -23,7 +23,6 @@
//utility functions //utility functions
#include "sql_tools.hpp" #include "sql_tools.hpp"
#include "utility.hpp"
//std & STL //std & STL
#include <stdexcept> #include <stdexcept>
@@ -307,7 +306,7 @@ void ServerApplication::HandlePacket(SerialPacket* const argPacket) {
default: { default: {
std::ostringstream msg; std::ostringstream msg;
msg << "Unknown SerialPacketType encountered in the server: "; msg << "Unknown SerialPacketType encountered in the server: ";
msg << to_string_custom(static_cast<int>(argPacket->type)); msg << static_cast<int>(argPacket->type);
throw(std::runtime_error(msg.str())); throw(std::runtime_error(msg.str()));
} }
break; break;
+1 -1
View File
@@ -1,5 +1,5 @@
#config #config
INCLUDES+=. ../../common/utilities INCLUDES+=.
LIBS+= LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
+4 -4
View File
@@ -21,10 +21,9 @@
*/ */
#include "sql_tools.hpp" #include "sql_tools.hpp"
#include "utility.hpp"
#include <stdexcept> #include <stdexcept>
#include <fstream> #include <fstream>
#include <sstream>
#include <cstdlib> #include <cstdlib>
int runSQLScript(sqlite3* db, std::string fname, int (*callback)(void*,int,char**,char**), void* argPtr) { 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); int ret = sqlite3_exec(db, script.c_str(), callback, argPtr, &errmsg);
if (ret != SQLITE_OK) { if (ret != SQLITE_OK) {
//handle any errors received from the SQL //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); free(errmsg);
throw(e); throw(std::runtime_error( msg.str() ));
} }
return ret; return ret;
} }