From 78c04718e0819cf1a2208c5f60cd1a1d60c09fb8 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 31 Dec 2014 03:05:19 +1100 Subject: [PATCH] Removed ManagerInterface, it was a bad idea --- server/accounts/account_manager.hpp | 30 +++++----- server/characters/character_manager.hpp | 30 +++++----- server/clients/client_manager.hpp | 30 ++++------ server/monsters/monster_manager.hpp | 31 +++++------ server/rooms/room_manager.hpp | 31 +++++------ server/server_utilities/manager_interface.hpp | 55 ------------------- server/waypoints/waypoint_manager.hpp | 32 +++++------ 7 files changed, 85 insertions(+), 154 deletions(-) delete mode 100644 server/server_utilities/manager_interface.hpp diff --git a/server/accounts/account_manager.hpp b/server/accounts/account_manager.hpp index 9e6e550..ad65836 100644 --- a/server/accounts/account_manager.hpp +++ b/server/accounts/account_manager.hpp @@ -24,7 +24,6 @@ #include "account_data.hpp" #include "singleton.hpp" -#include "manager_interface.hpp" #if defined(__MINGW32__) #include "sqlite3/sqlite3.h" @@ -35,26 +34,23 @@ #include #include -class AccountManager: - public Singleton, - public ManagerInterface -{ +class AccountManager: public Singleton { public: //common public methods - int Create(std::string username, int clientIndex) override; - int Load(std::string username, int clientIndex) override; - int Save(int uid) override; - void Unload(int uid) override; - void Delete(int uid) override; + int Create(std::string username, int clientIndex); + int Load(std::string username, int clientIndex); + int Save(int uid); + void Unload(int uid); + void Delete(int uid); - void UnloadAll() override; - void UnloadIf(std::function)> fn) override; + void UnloadAll(); + void UnloadIf(std::function)> fn); //accessors and mutators - AccountData* Get(int uid) override; - int GetLoadedCount() override; - int GetTotalCount() override; - std::map* GetContainer() override; + AccountData* Get(int uid); + int GetLoadedCount(); + int GetTotalCount(); + std::map* GetContainer(); sqlite3* SetDatabase(sqlite3* db); sqlite3* GetDatabase(); @@ -65,6 +61,8 @@ private: AccountManager() = default; ~AccountManager() = default; + //members + std::map elementMap; sqlite3* database = nullptr; }; diff --git a/server/characters/character_manager.hpp b/server/characters/character_manager.hpp index fadf54c..2263d46 100644 --- a/server/characters/character_manager.hpp +++ b/server/characters/character_manager.hpp @@ -24,7 +24,6 @@ #include "character_data.hpp" #include "singleton.hpp" -#include "manager_interface.hpp" #if defined(__MINGW32__) #include "sqlite3/sqlite3.h" @@ -35,26 +34,23 @@ #include #include -class CharacterManager: - public Singleton, - public ManagerInterface -{ +class CharacterManager: public Singleton { public: //common public methods - int Create(int owner, std::string handle, std::string avatar) override; - int Load(int owner, std::string handle, std::string avatar) override; - int Save(int uid) override; - void Unload(int uid) override; - void Delete(int uid) override; + int Create(int owner, std::string handle, std::string avatar); + int Load(int owner, std::string handle, std::string avatar); + int Save(int uid); + void Unload(int uid); + void Delete(int uid); - void UnloadAll() override; - void UnloadIf(std::function)> fn) override; + void UnloadAll(); + void UnloadIf(std::function)> fn); //accessors and mutators - CharacterData* Get(int uid) override; - int GetLoadedCount() override; - int GetTotalCount() override; - std::map* GetContainer() override; + CharacterData* Get(int uid); + int GetLoadedCount(); + int GetTotalCount(); + std::map* GetContainer(); sqlite3* SetDatabase(sqlite3* db); sqlite3* GetDatabase(); @@ -65,6 +61,8 @@ private: CharacterManager() = default; ~CharacterManager() = default; + //members + std::map elementMap; sqlite3* database = nullptr; }; diff --git a/server/clients/client_manager.hpp b/server/clients/client_manager.hpp index 4e0b0d1..165199b 100644 --- a/server/clients/client_manager.hpp +++ b/server/clients/client_manager.hpp @@ -23,35 +23,32 @@ #define CLIENTMANAGER_HPP_ #include "client_data.hpp" -#include "manager_interface.hpp" #include "server_packet.hpp" #include "singleton.hpp" #include "SDL/SDL_net.h" #include +#include -class ClientManager: - public Singleton, - public ManagerInterface -{ +class ClientManager: public Singleton { public: //methods int CheckConnections(); void HandlePong(ServerPacket* const argPacket); //common public methods - int Create(IPaddress) override; - void Unload(int uid) override; + int Create(IPaddress); + void Unload(int uid); - void UnloadAll() override; - void UnloadIf(std::function)> fn) override; + void UnloadAll(); + void UnloadIf(std::function)> fn); //accessors & mutators - ClientData* Get(int uid) override; - int GetLoadedCount() override; - int GetTotalCount() override; - std::map* GetContainer() override; + ClientData* Get(int uid); + int GetLoadedCount(); + int GetTotalCount(); + std::map* GetContainer(); private: friend Singleton; @@ -59,11 +56,8 @@ private: ClientManager() = default; ~ClientManager() = default; - //EMPTY - int Load(IPaddress) override { return -1; } - int Save(int uid) override { return -1; } - void Delete(int uid) override { return; } - + //members + std::map elementMap; int counter = 0; }; diff --git a/server/monsters/monster_manager.hpp b/server/monsters/monster_manager.hpp index de19e2c..24f980f 100644 --- a/server/monsters/monster_manager.hpp +++ b/server/monsters/monster_manager.hpp @@ -22,7 +22,6 @@ #ifndef MONSTERMANAGER_HPP_ #define MONSTERMANAGER_HPP_ -#include "manager_interface.hpp" #include "monster_data.hpp" #include "singleton.hpp" @@ -35,28 +34,26 @@ #endif #include +#include #include -class MonsterManager: - public Singleton, - public ManagerInterface -{ +class MonsterManager: public Singleton { public: //common public methods - int Create(std::string) override; - int Load(std::string) override; - int Save(int uid) override; - void Unload(int uid) override; - void Delete(int uid) override; + int Create(std::string); + int Load(std::string); + int Save(int uid); + void Unload(int uid); + void Delete(int uid); - void UnloadAll() override; - void UnloadIf(std::function)> fn) override; + void UnloadAll(); + void UnloadIf(std::function)> fn); //accessors & mutators - MonsterData* Get(int uid) override; - int GetLoadedCount() override; - int GetTotalCount() override; - std::map* GetContainer() override; + MonsterData* Get(int uid); + int GetLoadedCount(); + int GetTotalCount(); + std::map* GetContainer(); //hooks sqlite3* SetDatabase(sqlite3* db); @@ -70,6 +67,8 @@ private: MonsterManager() = default; ~MonsterManager() = default; + //members + std::map elementMap; sqlite3* database = nullptr; lua_State* lua = nullptr; }; diff --git a/server/rooms/room_manager.hpp b/server/rooms/room_manager.hpp index e5ae344..2371d5e 100644 --- a/server/rooms/room_manager.hpp +++ b/server/rooms/room_manager.hpp @@ -24,7 +24,6 @@ #include "room_data.hpp" #include "singleton.hpp" -#include "manager_interface.hpp" #if defined(__MINGW32__) #include "lua/lua.hpp" @@ -32,23 +31,23 @@ #include "lua.hpp" #endif -class RoomManager: - public Singleton, - public ManagerInterface -{ +#include +#include + +class RoomManager: public Singleton { public: //common public methods - int Create(std::string) override; - void Unload(int uid) override; + int Create(std::string); + void Unload(int uid); - void UnloadAll() override; - void UnloadIf(std::function)> fn) override; + void UnloadAll(); + void UnloadIf(std::function)> fn); //accessors and mutators - RoomData* Get(int uid) override; - int GetLoadedCount() override; - int GetTotalCount() override; - std::map* GetContainer() override; + RoomData* Get(int uid); + int GetLoadedCount(); + int GetTotalCount(); + std::map* GetContainer(); //hooks lua_State* SetLuaState(lua_State* L) { return lua = L; } @@ -60,10 +59,8 @@ private: RoomManager() = default; ~RoomManager() = default; - int Load(std::string) override { return -1; } - int Save(int uid) override { return -1; } - void Delete(int uid) override { } - + //members + std::map elementMap; lua_State* lua = nullptr; int counter = 0; }; diff --git a/server/server_utilities/manager_interface.hpp b/server/server_utilities/manager_interface.hpp deleted file mode 100644 index c10e6d2..0000000 --- a/server/server_utilities/manager_interface.hpp +++ /dev/null @@ -1,55 +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 MANAGERINTERFACE_HPP_ -#define MANAGERINTERFACE_HPP_ - -#include -#include - -template -class ManagerInterface { -public: - //common public methods - virtual int Create(Arguments... parameters) = 0; - virtual int Load(Arguments... parameters) = 0; - virtual int Save(int uid) = 0; - virtual void Unload(int uid) = 0; - virtual void Delete(int uid) = 0; - - virtual void UnloadAll() = 0; - virtual void UnloadIf(std::function)> fn) = 0; - - //accessors & mutators - virtual T* Get(int uid) = 0; - virtual int GetLoadedCount() = 0; - virtual int GetTotalCount() = 0; //can be an alias of GetLoadedCount() - virtual std::map* GetContainer() = 0; - -protected: - ManagerInterface() = default; - ~ManagerInterface() = default; - - //members - std::map elementMap; -}; - -#endif \ No newline at end of file diff --git a/server/waypoints/waypoint_manager.hpp b/server/waypoints/waypoint_manager.hpp index f4975aa..7139363 100644 --- a/server/waypoints/waypoint_manager.hpp +++ b/server/waypoints/waypoint_manager.hpp @@ -23,39 +23,39 @@ #define WAYPOINTMANAGER_HPP_ #include "waypoint_data.hpp" -#include "manager_interface.hpp" #include "singleton.hpp" #include "vector2.hpp" #include +#include #include -class WaypointManager: - public Singleton, - public ManagerInterface -{ +class WaypointManager: public Singleton { public: //common public methods - int Create() override; - int Load() override; - int Save(int uid) override; - void Unload(int uid) override; - void Delete(int uid) override; + int Create(); + int Load(); + int Save(int uid); + void Unload(int uid); + void Delete(int uid); - void UnloadAll() override; - void UnloadIf(std::function)> fn) override; + void UnloadAll(); + void UnloadIf(std::function)> fn); //accessors & mutators - WaypointData* Get(int uid) override; - int GetLoadedCount() override; - int GetTotalCount() override; - std::map* GetContainer() override; + WaypointData* Get(int uid); + int GetLoadedCount(); + int GetTotalCount(); + std::map* GetContainer(); private: friend Singleton; WaypointManager() = default; ~WaypointManager() = default; + + //members + std::map elementMap; }; #endif \ No newline at end of file