Removed ManagerInterface, it was a bad idea
This commit is contained in:
@@ -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 <functional>
|
||||
#include <map>
|
||||
|
||||
class AccountManager:
|
||||
public Singleton<AccountManager>,
|
||||
public ManagerInterface<AccountData, std::string, int>
|
||||
{
|
||||
class AccountManager: public Singleton<AccountManager> {
|
||||
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<bool(std::pair<const int, AccountData>)> fn) override;
|
||||
void UnloadAll();
|
||||
void UnloadIf(std::function<bool(std::pair<const int, AccountData>)> fn);
|
||||
|
||||
//accessors and mutators
|
||||
AccountData* Get(int uid) override;
|
||||
int GetLoadedCount() override;
|
||||
int GetTotalCount() override;
|
||||
std::map<int, AccountData>* GetContainer() override;
|
||||
AccountData* Get(int uid);
|
||||
int GetLoadedCount();
|
||||
int GetTotalCount();
|
||||
std::map<int, AccountData>* GetContainer();
|
||||
|
||||
sqlite3* SetDatabase(sqlite3* db);
|
||||
sqlite3* GetDatabase();
|
||||
@@ -65,6 +61,8 @@ private:
|
||||
AccountManager() = default;
|
||||
~AccountManager() = default;
|
||||
|
||||
//members
|
||||
std::map<int, AccountData> elementMap;
|
||||
sqlite3* database = nullptr;
|
||||
};
|
||||
|
||||
|
||||
@@ -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 <functional>
|
||||
#include <map>
|
||||
|
||||
class CharacterManager:
|
||||
public Singleton<CharacterManager>,
|
||||
public ManagerInterface<CharacterData, int, std::string, std::string>
|
||||
{
|
||||
class CharacterManager: public Singleton<CharacterManager> {
|
||||
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<bool(std::pair<const int, CharacterData>)> fn) override;
|
||||
void UnloadAll();
|
||||
void UnloadIf(std::function<bool(std::pair<const int, CharacterData>)> fn);
|
||||
|
||||
//accessors and mutators
|
||||
CharacterData* Get(int uid) override;
|
||||
int GetLoadedCount() override;
|
||||
int GetTotalCount() override;
|
||||
std::map<int, CharacterData>* GetContainer() override;
|
||||
CharacterData* Get(int uid);
|
||||
int GetLoadedCount();
|
||||
int GetTotalCount();
|
||||
std::map<int, CharacterData>* GetContainer();
|
||||
|
||||
sqlite3* SetDatabase(sqlite3* db);
|
||||
sqlite3* GetDatabase();
|
||||
@@ -65,6 +61,8 @@ private:
|
||||
CharacterManager() = default;
|
||||
~CharacterManager() = default;
|
||||
|
||||
//members
|
||||
std::map<int, CharacterData> elementMap;
|
||||
sqlite3* database = nullptr;
|
||||
};
|
||||
|
||||
|
||||
@@ -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 <functional>
|
||||
#include <map>
|
||||
|
||||
class ClientManager:
|
||||
public Singleton<ClientManager>,
|
||||
public ManagerInterface<ClientData, IPaddress>
|
||||
{
|
||||
class ClientManager: public Singleton<ClientManager> {
|
||||
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<bool(std::pair<const int, ClientData>)> fn) override;
|
||||
void UnloadAll();
|
||||
void UnloadIf(std::function<bool(std::pair<const int, ClientData>)> fn);
|
||||
|
||||
//accessors & mutators
|
||||
ClientData* Get(int uid) override;
|
||||
int GetLoadedCount() override;
|
||||
int GetTotalCount() override;
|
||||
std::map<int, ClientData>* GetContainer() override;
|
||||
ClientData* Get(int uid);
|
||||
int GetLoadedCount();
|
||||
int GetTotalCount();
|
||||
std::map<int, ClientData>* GetContainer();
|
||||
|
||||
private:
|
||||
friend Singleton<ClientManager>;
|
||||
@@ -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<int, ClientData> elementMap;
|
||||
int counter = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -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 <functional>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
class MonsterManager:
|
||||
public Singleton<MonsterManager>,
|
||||
public ManagerInterface<MonsterData, std::string>
|
||||
{
|
||||
class MonsterManager: public Singleton<MonsterManager> {
|
||||
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<bool(std::pair<const int, MonsterData>)> fn) override;
|
||||
void UnloadAll();
|
||||
void UnloadIf(std::function<bool(std::pair<const int, MonsterData>)> fn);
|
||||
|
||||
//accessors & mutators
|
||||
MonsterData* Get(int uid) override;
|
||||
int GetLoadedCount() override;
|
||||
int GetTotalCount() override;
|
||||
std::map<int, MonsterData>* GetContainer() override;
|
||||
MonsterData* Get(int uid);
|
||||
int GetLoadedCount();
|
||||
int GetTotalCount();
|
||||
std::map<int, MonsterData>* GetContainer();
|
||||
|
||||
//hooks
|
||||
sqlite3* SetDatabase(sqlite3* db);
|
||||
@@ -70,6 +67,8 @@ private:
|
||||
MonsterManager() = default;
|
||||
~MonsterManager() = default;
|
||||
|
||||
//members
|
||||
std::map<int, MonsterData> elementMap;
|
||||
sqlite3* database = nullptr;
|
||||
lua_State* lua = nullptr;
|
||||
};
|
||||
|
||||
@@ -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<RoomManager>,
|
||||
public ManagerInterface<RoomData, std::string>
|
||||
{
|
||||
#include <functional>
|
||||
#include <map>
|
||||
|
||||
class RoomManager: public Singleton<RoomManager> {
|
||||
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<bool(std::pair<const int,RoomData>)> fn) override;
|
||||
void UnloadAll();
|
||||
void UnloadIf(std::function<bool(std::pair<const int,RoomData>)> fn);
|
||||
|
||||
//accessors and mutators
|
||||
RoomData* Get(int uid) override;
|
||||
int GetLoadedCount() override;
|
||||
int GetTotalCount() override;
|
||||
std::map<int, RoomData>* GetContainer() override;
|
||||
RoomData* Get(int uid);
|
||||
int GetLoadedCount();
|
||||
int GetTotalCount();
|
||||
std::map<int, RoomData>* 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<int, RoomData> elementMap;
|
||||
lua_State* lua = nullptr;
|
||||
int counter = 0;
|
||||
};
|
||||
|
||||
@@ -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 <functional>
|
||||
#include <map>
|
||||
|
||||
template<typename T, typename... Arguments>
|
||||
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<bool(std::pair<const int, T>)> 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<int, T>* GetContainer() = 0;
|
||||
|
||||
protected:
|
||||
ManagerInterface() = default;
|
||||
~ManagerInterface() = default;
|
||||
|
||||
//members
|
||||
std::map<int, T> elementMap;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -23,39 +23,39 @@
|
||||
#define WAYPOINTMANAGER_HPP_
|
||||
|
||||
#include "waypoint_data.hpp"
|
||||
#include "manager_interface.hpp"
|
||||
#include "singleton.hpp"
|
||||
#include "vector2.hpp"
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
class WaypointManager:
|
||||
public Singleton<WaypointManager>,
|
||||
public ManagerInterface<WaypointData>
|
||||
{
|
||||
class WaypointManager: public Singleton<WaypointManager> {
|
||||
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<bool(std::pair<const int, WaypointData>)> fn) override;
|
||||
void UnloadAll();
|
||||
void UnloadIf(std::function<bool(std::pair<const int, WaypointData>)> fn);
|
||||
|
||||
//accessors & mutators
|
||||
WaypointData* Get(int uid) override;
|
||||
int GetLoadedCount() override;
|
||||
int GetTotalCount() override;
|
||||
std::map<int, WaypointData>* GetContainer() override;
|
||||
WaypointData* Get(int uid);
|
||||
int GetLoadedCount();
|
||||
int GetTotalCount();
|
||||
std::map<int, WaypointData>* GetContainer();
|
||||
|
||||
private:
|
||||
friend Singleton<WaypointManager>;
|
||||
|
||||
WaypointManager() = default;
|
||||
~WaypointManager() = default;
|
||||
|
||||
//members
|
||||
std::map<int, WaypointData> elementMap;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user