diff options
Diffstat (limited to 'src/framework')
33 files changed, 0 insertions, 3330 deletions
diff --git a/src/framework/CMakeLists.txt b/src/framework/CMakeLists.txt deleted file mode 100644 index bcf3603cb5e..00000000000 --- a/src/framework/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -SET(trinityframework_STAT_SRCS - Policies/ObjectLifeTime.cpp - Utilities/EventProcessor.cpp -) - -include_directories( - ${ACE_INCLUDE_DIR} - ${CMAKE_SOURCE_DIR}/src/framework -) - -add_library(trinityframework STATIC ${trinityframework_STAT_SRCS}) diff --git a/src/framework/Dynamic/FactoryHolder.h b/src/framework/Dynamic/FactoryHolder.h deleted file mode 100644 index 282968d6097..00000000000 --- a/src/framework/Dynamic/FactoryHolder.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_FACTORY_HOLDER -#define TRINITY_FACTORY_HOLDER - -#include "Platform/Define.h" -#include "Utilities/TypeList.h" -#include "ObjectRegistry.h" -#include "Policies/SingletonImp.h" - -/** FactoryHolder holds a factory object of a specific type - */ -template<class T, class Key = std::string> -class FactoryHolder -{ - public: - typedef ObjectRegistry<FactoryHolder<T, Key >, Key > FactoryHolderRegistry; - typedef Trinity::Singleton<FactoryHolderRegistry > FactoryHolderRepository; - - FactoryHolder(Key k) : i_key(k) {} - virtual ~FactoryHolder() {} - inline Key key() const { return i_key; } - - void RegisterSelf(void) { FactoryHolderRepository::Instance().InsertItem(this, i_key); } - void DeregisterSelf(void) { FactoryHolderRepository::Instance().RemoveItem(this, false); } - - /// Abstract Factory create method - virtual T* Create(void *data = NULL) const = 0; - private: - Key i_key; -}; - -/** Permissible is a classic way of letting the object decide - * whether how good they handle things. This is not retricted - * to factory selectors. - */ -template<class T> -class Permissible -{ - public: - virtual ~Permissible() {} - virtual int Permit(const T *) const = 0; -}; -#endif - diff --git a/src/framework/Dynamic/ObjectRegistry.h b/src/framework/Dynamic/ObjectRegistry.h deleted file mode 100644 index e6619427885..00000000000 --- a/src/framework/Dynamic/ObjectRegistry.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_OBJECTREGISTRY_H -#define TRINITY_OBJECTREGISTRY_H - -#include "Platform/Define.h" -#include "Utilities/UnorderedMap.h" -#include "Policies/Singleton.h" - -#include <string> -#include <vector> -#include <map> - -/** ObjectRegistry holds all registry item of the same type - */ -template<class T, class Key = std::string> -class ObjectRegistry -{ - public: - typedef std::map<Key, T *> RegistryMapType; - - /// Returns a registry item - const T* GetRegistryItem(Key key) const - { - typename RegistryMapType::const_iterator iter = i_registeredObjects.find(key); - return( iter == i_registeredObjects.end() ? NULL : iter->second ); - } - - /// Inserts a registry item - bool InsertItem(T *obj, Key key, bool override = false) - { - typename RegistryMapType::iterator iter = i_registeredObjects.find(key); - if( iter != i_registeredObjects.end() ) - { - if( !override ) - return false; - delete iter->second; - i_registeredObjects.erase(iter); - } - - i_registeredObjects[key] = obj; - return true; - } - - /// Removes a registry item - void RemoveItem(Key key, bool delete_object = true) - { - typename RegistryMapType::iterator iter = i_registeredObjects.find(key); - if( iter != i_registeredObjects.end() ) - { - if( delete_object ) - delete iter->second; - i_registeredObjects.erase(iter); - } - } - - /// Returns true if registry contains an item - bool HasItem(Key key) const - { - return (i_registeredObjects.find(key) != i_registeredObjects.end()); - } - - /// Inefficiently return a vector of registered items - unsigned int GetRegisteredItems(std::vector<Key> &l) const - { - unsigned int sz = l.size(); - l.resize(sz + i_registeredObjects.size()); - for (typename RegistryMapType::const_iterator iter = i_registeredObjects.begin(); iter != i_registeredObjects.end(); ++iter) - l[sz++] = iter->first; - return i_registeredObjects.size(); - } - - /// Return the map of registered items - RegistryMapType const &GetRegisteredItems() const - { - return i_registeredObjects; - } - - private: - RegistryMapType i_registeredObjects; - friend class Trinity::OperatorNew<ObjectRegistry<T, Key> >; - - // protected for friend use since it should be a singleton - ObjectRegistry() {} - ~ObjectRegistry() - { - for (typename RegistryMapType::iterator iter=i_registeredObjects.begin(); iter != i_registeredObjects.end(); ++iter) - delete iter->second; - i_registeredObjects.clear(); - } -}; -#endif - diff --git a/src/framework/GameSystem/Grid.h b/src/framework/GameSystem/Grid.h deleted file mode 100644 index 65bf3c92f9d..00000000000 --- a/src/framework/GameSystem/Grid.h +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_GRID_H -#define TRINITY_GRID_H - -/* - @class Grid - Grid is a logical segment of the game world represented inside TrinIty. - Grid is bind at compile time to a particular type of object which - we call it the object of interested. There are many types of loader, - specially, dynamic loader, static loader, or on-demand loader. There's - a subtle difference between dynamic loader and on-demand loader but - this is implementation specific to the loader class. From the - Grid's perspective, the loader meets its API requirement is suffice. -*/ - -#include "Platform/Define.h" -#include "Policies/ThreadingModel.h" -#include "TypeContainer.h" -#include "TypeContainerVisitor.h" - -// forward declaration -template<class A, class T, class O> class GridLoader; - -template -< -class ACTIVE_OBJECT, -class WORLD_OBJECT_TYPES, -class GRID_OBJECT_TYPES, -class ThreadModel = Trinity::SingleThreaded<ACTIVE_OBJECT> -> -class Grid -{ - // allows the GridLoader to access its internals - template<class A, class T, class O> friend class GridLoader; - public: - - /** destructor to clean up its resources. This includes unloading the - grid if it has not been unload. - */ - ~Grid() {} - - /** an object of interested enters the grid - */ - template<class SPECIFIC_OBJECT> void AddWorldObject(SPECIFIC_OBJECT *obj) - { - if(!i_objects.template insert<SPECIFIC_OBJECT>(obj)) - assert(false); - } - - /** an object of interested exits the grid - */ - template<class SPECIFIC_OBJECT> void RemoveWorldObject(SPECIFIC_OBJECT *obj) - { - if(!i_objects.template remove<SPECIFIC_OBJECT>(obj)) - assert(false); - } - - /** Refreshes/update the grid. This required for remote grids. - */ - void RefreshGrid(void) { /* TBI */} - - /** Locks a grid. Any object enters must wait until the grid is unlock. - */ - void LockGrid(void) { /* TBI */ } - - /** Unlocks the grid. - */ - void UnlockGrid(void) { /* TBI */ } - - /** Grid visitor for grid objects - */ - template<class T> void Visit(TypeContainerVisitor<T, TypeMapContainer<GRID_OBJECT_TYPES> > &visitor) - { - visitor.Visit(i_container); - } - - /** Grid visitor for world objects - */ - template<class T> void Visit(TypeContainerVisitor<T, TypeMapContainer<WORLD_OBJECT_TYPES> > &visitor) - { - visitor.Visit(i_objects); - } - - /** Returns the number of object within the grid. - */ - unsigned int ActiveObjectsInGrid(void) const { return /*m_activeGridObjects.size()+*/i_objects.template Count<ACTIVE_OBJECT>(); } - - /** Inserts a container type object into the grid. - */ - template<class SPECIFIC_OBJECT> void AddGridObject(SPECIFIC_OBJECT *obj) - { - if(!i_container.template insert<SPECIFIC_OBJECT>(obj)) - assert(false); - } - - /** Removes a containter type object from the grid - */ - template<class SPECIFIC_OBJECT> void RemoveGridObject(SPECIFIC_OBJECT *obj) - { - if(!i_container.template remove<SPECIFIC_OBJECT>(obj)) - assert(false); - } - - /*bool NoWorldObjectInGrid() const - { - return i_objects.GetElements().isEmpty(); - } - - bool NoGridObjectInGrid() const - { - return i_container.GetElements().isEmpty(); - }*/ - private: - - typedef typename ThreadModel::Lock Guard; - typedef typename ThreadModel::VolatileType VolatileType; - - TypeMapContainer<GRID_OBJECT_TYPES> i_container; - TypeMapContainer<WORLD_OBJECT_TYPES> i_objects; - //typedef std::set<void*> ActiveGridObjects; - //ActiveGridObjects m_activeGridObjects; -}; -#endif - diff --git a/src/framework/GameSystem/GridLoader.h b/src/framework/GameSystem/GridLoader.h deleted file mode 100644 index 03fa0f5b813..00000000000 --- a/src/framework/GameSystem/GridLoader.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_GRIDLOADER_H -#define TRINITY_GRIDLOADER_H - -/** - @class GridLoader - The GridLoader is working in conjuction with the Grid and responsible - for loading and unloading object-types (one or more) when objects - enters a grid. Unloading is scheduled and might be canceled if - an interested object re-enters. GridLoader does not do the actuall - loading and unloading but implements as a template pattern that - delicate its loading and unloading for the actualy loader and unloader. - GridLoader manages the grid (both local and remote). - */ - -#include "Platform/Define.h" -#include "Grid.h" -#include "TypeContainerVisitor.h" - -template -< -class ACTIVE_OBJECT, -class WORLD_OBJECT_TYPES, -class GRID_OBJECT_TYPES -> -class GridLoader -{ - public: - - /** Loads the grid - */ - template<class LOADER> - void Load(Grid<ACTIVE_OBJECT,WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> &grid, LOADER &loader) - { - grid.LockGrid(); - loader.Load(grid); - grid.UnlockGrid(); - } - - /** Stop the grid - */ - template<class STOPER> - void Stop(Grid<ACTIVE_OBJECT,WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> &grid, STOPER &stoper) - { - grid.LockGrid(); - stoper.Stop(grid); - grid.UnlockGrid(); - } - /** Unloads the grid - */ - template<class UNLOADER> - void Unload(Grid<ACTIVE_OBJECT,WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> &grid, UNLOADER &unloader) - { - grid.LockGrid(); - unloader.Unload(grid); - grid.UnlockGrid(); - } -}; -#endif - diff --git a/src/framework/GameSystem/GridRefManager.h b/src/framework/GameSystem/GridRefManager.h deleted file mode 100644 index 79799105fb7..00000000000 --- a/src/framework/GameSystem/GridRefManager.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _GRIDREFMANAGER -#define _GRIDREFMANAGER - -#include "Utilities/LinkedReference/RefManager.h" - -template<class OBJECT> -class GridReference; - -template<class OBJECT> -class GridRefManager : public RefManager<GridRefManager<OBJECT>, OBJECT> -{ - public: - typedef LinkedListHead::Iterator< GridReference<OBJECT> > iterator; - - GridReference<OBJECT>* getFirst() { return (GridReference<OBJECT>*)RefManager<GridRefManager<OBJECT>, OBJECT>::getFirst(); } - GridReference<OBJECT>* getLast() { return (GridReference<OBJECT>*)RefManager<GridRefManager<OBJECT>, OBJECT>::getLast(); } - - iterator begin() { return iterator(getFirst()); } - iterator end() { return iterator(NULL); } - iterator rbegin() { return iterator(getLast()); } - iterator rend() { return iterator(NULL); } -}; -#endif - diff --git a/src/framework/GameSystem/GridReference.h b/src/framework/GameSystem/GridReference.h deleted file mode 100644 index d2e3a455895..00000000000 --- a/src/framework/GameSystem/GridReference.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _GRIDREFERENCE_H -#define _GRIDREFERENCE_H - -#include "Utilities/LinkedReference/Reference.h" - -template<class OBJECT> -class GridRefManager; - -template<class OBJECT> -class GridReference : public Reference<GridRefManager<OBJECT>, OBJECT> -{ - protected: - void targetObjectBuildLink() - { - // called from link() - this->getTarget()->insertFirst(this); - this->getTarget()->incSize(); - } - void targetObjectDestroyLink() - { - // called from unlink() - if(this->isValid()) this->getTarget()->decSize(); - } - void sourceObjectDestroyLink() - { - // called from invalidate() - this->getTarget()->decSize(); - } - public: - GridReference() : Reference<GridRefManager<OBJECT>, OBJECT>() {} - ~GridReference() { this->unlink(); } - GridReference *next() { return (GridReference*)Reference<GridRefManager<OBJECT>, OBJECT>::next(); } -}; -#endif - diff --git a/src/framework/GameSystem/NGrid.h b/src/framework/GameSystem/NGrid.h deleted file mode 100644 index 3810286e123..00000000000 --- a/src/framework/GameSystem/NGrid.h +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_NGRID_H -#define TRINITY_NGRID_H - -/** NGrid is nothing more than a wrapper of the Grid with an NxN cells - */ - -#include "GameSystem/Grid.h" -#include "GameSystem/GridReference.h" -#include "Timer.h" -#include "Util.h" - -#define DEFAULT_VISIBILITY_NOTIFY_PERIOD 1000 - -class GridInfo -{ -public: - GridInfo() - : i_timer(0), i_unloadActiveLockCount(0), i_unloadExplicitLock(false), i_unloadReferenceLock(false), - vis_Update(0, irand(0,DEFAULT_VISIBILITY_NOTIFY_PERIOD)) {} - GridInfo(time_t expiry, bool unload = true ) - : i_timer(expiry), i_unloadActiveLockCount(0), i_unloadExplicitLock(!unload), i_unloadReferenceLock(false), - vis_Update(0, irand(0,DEFAULT_VISIBILITY_NOTIFY_PERIOD)) {} - const TimeTracker& getTimeTracker() const { return i_timer; } - bool getUnloadLock() const { return i_unloadActiveLockCount || i_unloadExplicitLock || i_unloadReferenceLock; } - void setUnloadExplicitLock( bool on ) { i_unloadExplicitLock = on; } - void setUnloadReferenceLock( bool on ) { i_unloadReferenceLock = on; } - void incUnloadActiveLock() { ++i_unloadActiveLockCount; } - void decUnloadActiveLock() { if(i_unloadActiveLockCount) --i_unloadActiveLockCount; } - - void setTimer(const TimeTracker& pTimer) { i_timer = pTimer; } - void ResetTimeTracker(time_t interval) { i_timer.Reset(interval); } - void UpdateTimeTracker(time_t diff) { i_timer.Update(diff); } - PeriodicTimer& getRelocationTimer() { return vis_Update; } -private: - TimeTracker i_timer; - PeriodicTimer vis_Update; - - uint16 i_unloadActiveLockCount : 16; // lock from active object spawn points (prevent clone loading) - bool i_unloadExplicitLock : 1; // explicit manual lock or config setting - bool i_unloadReferenceLock : 1; // lock from instance map copy -}; - -typedef enum -{ - GRID_STATE_INVALID = 0, - GRID_STATE_ACTIVE = 1, - GRID_STATE_IDLE = 2, - GRID_STATE_REMOVAL= 3, - MAX_GRID_STATE = 4 -} grid_state_t; - -template -< -unsigned int N, -class ACTIVE_OBJECT, -class WORLD_OBJECT_TYPES, -class GRID_OBJECT_TYPES, -class ThreadModel = Trinity::SingleThreaded<ACTIVE_OBJECT> -> -class NGrid -{ - public: - - typedef Grid<ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES, ThreadModel> GridType; - NGrid(uint32 id, int32 x, int32 y, time_t expiry, bool unload = true) - : i_gridId(id), i_x(x), i_y(y), i_cellstate(GRID_STATE_INVALID), i_GridObjectDataLoaded(false) - { - i_GridInfo = GridInfo(expiry, unload); - } - - const GridType& operator()(unsigned short x, unsigned short y) const - { - ASSERT(x < N); - ASSERT(y < N); - return i_cells[x][y]; - } - - GridType& operator()(unsigned short x, unsigned short y) - { - ASSERT(x < N); - ASSERT(y < N); - return i_cells[x][y]; - } - - const uint32& GetGridId(void) const { return i_gridId; } - void SetGridId(const uint32 id) const { i_gridId = id; } - grid_state_t GetGridState(void) const { return i_cellstate; } - void SetGridState(grid_state_t s) { i_cellstate = s; } - int32 getX() const { return i_x; } - int32 getY() const { return i_y; } - - void link(GridRefManager<NGrid<N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES, ThreadModel> >* pTo) - { - i_Reference.link(pTo, this); - } - bool isGridObjectDataLoaded() const { return i_GridObjectDataLoaded; } - void setGridObjectDataLoaded(bool pLoaded) { i_GridObjectDataLoaded = pLoaded; } - - GridInfo* getGridInfoRef() { return &i_GridInfo; } - const TimeTracker& getTimeTracker() const { return i_GridInfo.getTimeTracker(); } - bool getUnloadLock() const { return i_GridInfo.getUnloadLock(); } - void setUnloadExplicitLock( bool on ) { i_GridInfo.setUnloadExplicitLock(on); } - void setUnloadReferenceLock( bool on ) { i_GridInfo.setUnloadReferenceLock(on); } - void incUnloadActiveLock() { i_GridInfo.incUnloadActiveLock(); } - void decUnloadActiveLock() { i_GridInfo.decUnloadActiveLock(); } - void ResetTimeTracker(time_t interval) { i_GridInfo.ResetTimeTracker(interval); } - void UpdateTimeTracker(time_t diff) { i_GridInfo.UpdateTimeTracker(diff); } - - template<class SPECIFIC_OBJECT> void AddWorldObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj) - { - getGridType(x, y).AddWorldObject(obj); - } - - template<class SPECIFIC_OBJECT> void RemoveWorldObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj) - { - getGridType(x, y).RemoveWorldObject(obj); - } - - template<class T, class TT> void Visit(TypeContainerVisitor<T, TypeMapContainer<TT> > &visitor) - { - for (unsigned int x=0; x < N; ++x) - for (unsigned int y=0; y < N; ++y) - getGridType(x, y).Visit(visitor); - } - - template<class T, class TT> void Visit(const uint32 &x, const uint32 &y, TypeContainerVisitor<T, TypeMapContainer<TT> > &visitor) - { - getGridType(x, y).Visit(visitor); - } - - unsigned int ActiveObjectsInGrid(void) const - { - unsigned int count=0; - for (unsigned int x=0; x < N; ++x) - for (unsigned int y=0; y < N; ++y) - count += i_cells[x][y].ActiveObjectsInGrid(); - return count; - } - - template<class SPECIFIC_OBJECT> bool AddGridObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj) - { - return getGridType(x, y).AddGridObject(obj); - } - - template<class SPECIFIC_OBJECT> bool RemoveGridObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj) - { - return getGridType(x, y).RemoveGridObject(obj); - } - - private: - - GridType& getGridType(const uint32& x, const uint32& y) - { - ASSERT(x < N); - ASSERT(y < N); - return i_cells[x][y]; - } - - uint32 i_gridId; - GridInfo i_GridInfo; - GridReference<NGrid<N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES, ThreadModel> > i_Reference; - int32 i_x; - int32 i_y; - grid_state_t i_cellstate; - GridType i_cells[N][N]; - bool i_GridObjectDataLoaded; -}; -#endif - diff --git a/src/framework/GameSystem/TypeContainer.h b/src/framework/GameSystem/TypeContainer.h deleted file mode 100644 index c2c9b4fcdea..00000000000 --- a/src/framework/GameSystem/TypeContainer.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_TYPECONTAINER_H -#define TRINITY_TYPECONTAINER_H - -/* - * Here, you'll find a series of containers that allow you to hold multiple - * types of object at the same time. - */ - -#include <map> -#include <vector> -#include "Platform/Define.h" -#include "Utilities/TypeList.h" -#include "GameSystem/GridRefManager.h" - -/* - * @class ContainerMapList is a mulit-type container for map elements - * By itself its meaningless but collaborate along with TypeContainers, - * it become the most powerfully container in the whole system. - */ -template<class OBJECT> struct ContainerMapList -{ - //std::map<OBJECT_HANDLE, OBJECT *> _element; - GridRefManager<OBJECT> _element; -}; - -template<> struct ContainerMapList<TypeNull> /* nothing is in type null */ -{ -}; -template<class H, class T> struct ContainerMapList<TypeList<H, T> > -{ - ContainerMapList<H> _elements; - ContainerMapList<T> _TailElements; -}; - -/* - * @class ContaierArrayList is a multi-type container for - * array of elements. - */ -template<class OBJECT> struct ContainerArrayList -{ - std::vector<OBJECT> _element; -}; - -// termination condition -template<> struct ContainerArrayList<TypeNull> {}; -// recursion -template<class H, class T> struct ContainerArrayList<TypeList<H, T> > -{ - ContainerArrayList<H> _elements; - ContainerArrayList<T> _TailElements; -}; - -/* - * @class ContainerList is a simple list of different types of elements - * - */ -template<class OBJECT> struct ContainerList -{ - OBJECT _element; -}; - -/* TypeNull is underfined */ -template<> struct ContainerList<TypeNull> {}; -template<class H, class T> struct ContainerList<TypeList<H, T> > -{ - ContainerList<H> _elements; - ContainerMapList<T> _TailElements; -}; - -#include "TypeContainerFunctions.h" - -/* - * @class TypeMapContainer contains a fixed number of types and is - * determined at compile time. This is probably the most complicated - * class and do its simplest thing, that is, holds objects - * of different types. - */ - -template<class OBJECT_TYPES> -class TypeMapContainer -{ - public: - template<class SPECIFIC_TYPE> size_t Count() const { return Trinity::Count(i_elements, (SPECIFIC_TYPE*)NULL); } - - /// inserts a specific object into the container - template<class SPECIFIC_TYPE> bool insert(SPECIFIC_TYPE *obj) - { - SPECIFIC_TYPE* t = Trinity::Insert(i_elements, obj); - return (t != NULL); - } - - /// Removes the object from the container, and returns the removed object - template<class SPECIFIC_TYPE> bool remove(SPECIFIC_TYPE* obj) - { - SPECIFIC_TYPE* t = Trinity::Remove(i_elements, obj); - return (t != NULL); - } - - ContainerMapList<OBJECT_TYPES> & GetElements(void) { return i_elements; } - const ContainerMapList<OBJECT_TYPES> & GetElements(void) const { return i_elements;} - - private: - ContainerMapList<OBJECT_TYPES> i_elements; -}; -#endif - diff --git a/src/framework/GameSystem/TypeContainerFunctions.h b/src/framework/GameSystem/TypeContainerFunctions.h deleted file mode 100644 index edfbb40e659..00000000000 --- a/src/framework/GameSystem/TypeContainerFunctions.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TYPECONTAINER_FUNCTIONS_H -#define TYPECONTAINER_FUNCTIONS_H - -/* - * Here you'll find a list of helper functions to make - * the TypeContainer usefull. Without it, its hard - * to access or mutate the container. - */ - -#include "Platform/Define.h" -#include "Utilities/TypeList.h" -#include <map> - -namespace Trinity -{ - /* ContainerMapList Helpers */ - // count functions - template<class SPECIFIC_TYPE> size_t Count(const ContainerMapList<SPECIFIC_TYPE> &elements, SPECIFIC_TYPE* /*fake*/) - { - return elements._element.getSize(); - }; - - template<class SPECIFIC_TYPE> size_t Count(const ContainerMapList<TypeNull> &/*elements*/, SPECIFIC_TYPE* /*fake*/) - { - return 0; - } - - template<class SPECIFIC_TYPE, class T> size_t Count(const ContainerMapList<T> &/*elements*/, SPECIFIC_TYPE* /*fake*/) - { - return 0; - } - - template<class SPECIFIC_TYPE, class T> size_t Count(const ContainerMapList<TypeList<SPECIFIC_TYPE, T> >&elements, SPECIFIC_TYPE* fake) - { - return Count(elements._elements,fake); - } - - template<class SPECIFIC_TYPE, class H, class T> size_t Count(const ContainerMapList<TypeList<H, T> >&elements, SPECIFIC_TYPE* fake) - { - return Count(elements._TailElements, fake); - } - - // non-const insert functions - template<class SPECIFIC_TYPE> SPECIFIC_TYPE* Insert(ContainerMapList<SPECIFIC_TYPE> &elements, SPECIFIC_TYPE *obj) - { - //elements._element[hdl] = obj; - obj->GetGridRef().link(&elements._element, obj); - return obj; - }; - - template<class SPECIFIC_TYPE> SPECIFIC_TYPE* Insert(ContainerMapList<TypeNull> &/*elements*/, SPECIFIC_TYPE * /*obj*/) - { - return NULL; - } - - // this is a missed - template<class SPECIFIC_TYPE, class T> SPECIFIC_TYPE* Insert(ContainerMapList<T> &/*elements*/, SPECIFIC_TYPE * /*obj*/) - { - return NULL; // a missed - } - - // Recursion - template<class SPECIFIC_TYPE, class H, class T> SPECIFIC_TYPE* Insert(ContainerMapList<TypeList<H, T> >&elements, SPECIFIC_TYPE *obj) - { - SPECIFIC_TYPE* t= Insert(elements._elements, obj); - return (t != NULL ? t : Insert(elements._TailElements, obj)); - } - - // non-const remove method - template<class SPECIFIC_TYPE> SPECIFIC_TYPE* Remove(ContainerMapList<SPECIFIC_TYPE> & /*elements*/, SPECIFIC_TYPE *obj) - { - obj->GetGridRef().unlink(); - return obj; - } - - template<class SPECIFIC_TYPE> SPECIFIC_TYPE* Remove(ContainerMapList<TypeNull> &/*elements*/, SPECIFIC_TYPE * /*obj*/) - { - return NULL; - } - - // this is a missed - template<class SPECIFIC_TYPE, class T> SPECIFIC_TYPE* Remove(ContainerMapList<T> &/*elements*/, SPECIFIC_TYPE * /*obj*/) - { - return NULL; // a missed - } - - template<class SPECIFIC_TYPE, class T, class H> SPECIFIC_TYPE* Remove(ContainerMapList<TypeList<H, T> > &elements, SPECIFIC_TYPE *obj) - { - // The head element is bad - SPECIFIC_TYPE* t = Remove(elements._elements, obj); - return ( t != NULL ? t : Remove(elements._TailElements, obj) ); - } - -} -#endif - diff --git a/src/framework/GameSystem/TypeContainerFunctionsPtr.h b/src/framework/GameSystem/TypeContainerFunctionsPtr.h deleted file mode 100644 index 2affcc457cc..00000000000 --- a/src/framework/GameSystem/TypeContainerFunctionsPtr.h +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TYPECONTAINER_FUNCTIONS_PTR_H -#define TYPECONTAINER_FUNCTIONS_PTR_H - -/* - * Here you'll find a list of helper functions to make - * the TypeContainer usefull. Without it, its hard - * to access or mutate the container. - */ - -#include "Platform/Define.h" -#include "Utilities/TypeList.h" -#include <map> - -namespace Trinity -{ - /* ContainerMapList Helpers */ - // count functions - // template<class SPECIFIC_TYPE> size_t Count(const ContainerMapList<SPECIFIC_TYPE> &elements, CountedPtr<SPECIFIC_TYPE>* /*fake*/) - // { - // return elements._element.size(); - // }; - // - // template<class SPECIFIC_TYPE> size_t Count(const ContainerMapList<TypeNull> &elements, CountedPtr<SPECIFIC_TYPE>* /*fake*/) - // { - // return 0; - // } - // - // template<class SPECIFIC_TYPE, class T> size_t Count(const ContainerMapList<T> &elements, CountedPtr<SPECIFIC_TYPE>* /*fake*/) - // { - // return 0; - // } - // - // template<class SPECIFIC_TYPE, class T> size_t Count(const ContainerMapList<TypeList<SPECIFIC_TYPE, T> >&elements, SPECIFIC_TYPE* fake) - // { - // return Count(elements._elements,fake); - // } - // - // template<class SPECIFIC_TYPE, class H, class T> size_t Count(const ContainerMapList<TypeList<H, T> >&elements, SPECIFIC_TYPE* fake) - // { - // return Count(elements._TailElements, fake); - // } - - // non-const find functions - template<class SPECIFIC_TYPE> CountedPtr<SPECIFIC_TYPE>& Find(ContainerMapList<SPECIFIC_TYPE> &elements, OBJECT_HANDLE hdl, CountedPtr<SPECIFIC_TYPE>* /*fake*/) - { - typename std::map<OBJECT_HANDLE, CountedPtr<SPECIFIC_TYPE> >::iterator iter = elements._element.find(hdl); - return (iter == elements._element.end() ? NullPtr<SPECIFIC_TYPE>((SPECIFIC_TYPE*)NULL) : iter->second); - }; - - template<class SPECIFIC_TYPE> CountedPtr<SPECIFIC_TYPE>& Find(ContainerMapList<TypeNull> &elements, OBJECT_HANDLE hdl, CountedPtr<SPECIFIC_TYPE>* /*fake*/) - { - return NullPtr<SPECIFIC_TYPE>((SPECIFIC_TYPE*)NULL);// terminate recursion - } - - template<class SPECIFIC_TYPE, class T> CountedPtr<SPECIFIC_TYPE>& Find(ContainerMapList<T> &elements, OBJECT_HANDLE hdl, CountedPtr<SPECIFIC_TYPE>* /*fake*/) - { - return NullPtr<SPECIFIC_TYPE>((SPECIFIC_TYPE*)NULL);// this is a missed - } - - template<class SPECIFIC_TYPE, class H, class T> CountedPtr<SPECIFIC_TYPE>& Find(ContainerMapList<TypeList<H, T> >&elements, OBJECT_HANDLE hdl, CountedPtr<SPECIFIC_TYPE>* fake) - { - CountedPtr<SPECIFIC_TYPE> &t = Find(elements._elements, hdl,fake); - return (!t ? Find(elements._TailElements, hdl,fake) : t); - } - - // const find functions - template<class SPECIFIC_TYPE> const CountedPtr<SPECIFIC_TYPE>& Find(const ContainerMapList<SPECIFIC_TYPE> &elements, OBJECT_HANDLE hdl, CountedPtr<SPECIFIC_TYPE>* /*fake*/) - { - typename CountedPtr<SPECIFIC_TYPE>::iterator iter = elements._element.find(hdl); - return (iter == elements._element.end() ? NullPtr<SPECIFIC_TYPE>((SPECIFIC_TYPE*)NULL) : iter->second); - }; - - template<class SPECIFIC_TYPE> const CountedPtr<SPECIFIC_TYPE>& Find(const ContainerMapList<TypeNull> &elements, OBJECT_HANDLE hdl, CountedPtr<SPECIFIC_TYPE>* /*fake*/) - { - return NullPtr<SPECIFIC_TYPE>((SPECIFIC_TYPE*)NULL); - } - - template<class SPECIFIC_TYPE, class T> const CountedPtr<SPECIFIC_TYPE>& Find(const ContainerMapList<T> &elements, OBJECT_HANDLE hdl, CountedPtr<SPECIFIC_TYPE>* /*fake*/) - { - return NullPtr<SPECIFIC_TYPE>((SPECIFIC_TYPE*)NULL); - } - - template<class SPECIFIC_TYPE, class H, class T> CountedPtr<SPECIFIC_TYPE>& Find(const ContainerMapList<TypeList<H, T> >&elements, OBJECT_HANDLE hdl, CountedPtr<SPECIFIC_TYPE>* fake) - { - CountedPtr<SPECIFIC_TYPE> &t = Find(elements._elements, hdl,fake); - if(!t) - t = Find(elements._TailElement, hdl,fake); - - return t; - } - - // non-const insert functions - template<class SPECIFIC_TYPE> CountedPtr<SPECIFIC_TYPE>& Insert(ContainerMapList<SPECIFIC_TYPE> &elements, CountedPtr<SPECIFIC_TYPE> &obj, OBJECT_HANDLE hdl) - { - elements._element[hdl] = obj; - return obj; - }; - - template<class SPECIFIC_TYPE> CountedPtr<SPECIFIC_TYPE>& Insert(ContainerMapList<TypeNull> &elements, CountedPtr<SPECIFIC_TYPE> &obj, OBJECT_HANDLE hdl) - { - return NullPtr<SPECIFIC_TYPE>((SPECIFIC_TYPE*)NULL); - } - - // this is a missed - template<class SPECIFIC_TYPE, class T> CountedPtr<SPECIFIC_TYPE>& Insert(ContainerMapList<T> &elements, CountedPtr<SPECIFIC_TYPE> &obj, OBJECT_HANDLE hdl) - { - return NullPtr<SPECIFIC_TYPE>((SPECIFIC_TYPE*)NULL);// a missed - } - - // Recursion - template<class SPECIFIC_TYPE, class H, class T> CountedPtr<SPECIFIC_TYPE>& Insert(ContainerMapList<TypeList<H, T> >&elements, CountedPtr<SPECIFIC_TYPE> &obj, OBJECT_HANDLE hdl) - { - CountedPtr<SPECIFIC_TYPE> &t= Insert(elements._elements, obj, hdl); - return (!t ? Insert(elements._TailElements, obj, hdl) : t); - } - - // non-const remove method - template<class SPECIFIC_TYPE> bool Remove(ContainerMapList<SPECIFIC_TYPE> &elements, CountedPtr<SPECIFIC_TYPE> &obj, OBJECT_HANDLE hdl) - { - typename std::map<OBJECT_HANDLE, CountedPtr<SPECIFIC_TYPE> >::iterator iter = elements._element.find(hdl); - if( iter != elements._element.end() ) - { - elements._element.erase(iter); - return true; - } - - return false; // found... terminate the search - } - - template<class SPECIFIC_TYPE> bool Remove(ContainerMapList<TypeNull> &elements, CountedPtr<SPECIFIC_TYPE> &obj, OBJECT_HANDLE hdl) - { - return false; - } - - // this is a missed - template<class SPECIFIC_TYPE, class T> bool Remove(ContainerMapList<T> &elements, CountedPtr<SPECIFIC_TYPE> &obj, OBJECT_HANDLE hdl) - { - return false; - } - - template<class SPECIFIC_TYPE, class T, class H> bool Remove(ContainerMapList<TypeList<H, T> > &elements, CountedPtr<SPECIFIC_TYPE> &obj, OBJECT_HANDLE hdl) - { - // The head element is bad - bool t = Remove(elements._elements, obj, hdl); - return ( !t ? Remove(elements._TailElements, obj, hdl) : t ); - } - -} -#endif - diff --git a/src/framework/GameSystem/TypeContainerVisitor.h b/src/framework/GameSystem/TypeContainerVisitor.h deleted file mode 100644 index f15075e5afd..00000000000 --- a/src/framework/GameSystem/TypeContainerVisitor.h +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_TYPECONTAINERVISITOR_H -#define TRINITY_TYPECONTAINERVISITOR_H - -/* - * @class TypeContainerVisitor is implemented as a visitor pattern. It is - * a visitor to the TypeContainerList or TypeContainerMapList. The visitor has - * to overload its types as a visit method is called. - */ - -#include "Platform/Define.h" -#include "TypeContainer.h" - -// forward declaration -template<class T, class Y> class TypeContainerVisitor; - -// visitor helper -template<class VISITOR, class TYPE_CONTAINER> void VisitorHelper(VISITOR &v, TYPE_CONTAINER &c) -{ - v.Visit(c); -}; - -// terminate condition for container list -template<class VISITOR> void VisitorHelper(VISITOR &v, ContainerList<TypeNull> &c) -{ -} - -template<class VISITOR, class T> void VisitorHelper(VISITOR &v, ContainerList<T> &c) -{ - v.Visit(c._element); -} - -// recursion for container list -template<class VISITOR, class H, class T> void VisitorHelper(VISITOR &v, ContainerList<TypeList<H, T> > &c) -{ - VisitorHelper(v, c._elements); - VisitorHelper(v, c._TailElements); -} - -// terminate condition container map list -template<class VISITOR> void VisitorHelper(VISITOR &/*v*/, ContainerMapList<TypeNull> &/*c*/) -{ -} - -template<class VISITOR, class T> void VisitorHelper(VISITOR &v, ContainerMapList<T> &c) -{ - v.Visit(c._element); -} - -// recursion container map list -template<class VISITOR, class H, class T> void VisitorHelper(VISITOR &v, ContainerMapList<TypeList<H, T> > &c) -{ - VisitorHelper(v, c._elements); - VisitorHelper(v, c._TailElements); -} - -// array list -template<class VISITOR, class T> void VisitorHelper(VISITOR &v, ContainerArrayList<T> &c) -{ - v.Visit(c._element); -} - -template<class VISITOR> void VisitorHelper(VISITOR &/*v*/, ContainerArrayList<TypeNull> &/*c*/) -{ -} - -// recursion -template<class VISITOR, class H, class T> void VisitorHelper(VISITOR &v, ContainerArrayList<TypeList<H, T> > &c) -{ - VisitorHelper(v, c._elements); - VisitorHelper(v, c._TailElements); -} - -// for TypeMapContainer -template<class VISITOR, class OBJECT_TYPES> void VisitorHelper(VISITOR &v, TypeMapContainer<OBJECT_TYPES> &c) -{ - VisitorHelper(v, c.GetElements()); -} - -template<class VISITOR, class TYPE_CONTAINER> -class TypeContainerVisitor -{ - public: - TypeContainerVisitor(VISITOR &v) : i_visitor(v) {} - - void Visit(TYPE_CONTAINER &c) - { - VisitorHelper(i_visitor, c); - } - - void Visit(const TYPE_CONTAINER &c) const - { - VisitorHelper(i_visitor, c); - } - - private: - VISITOR &i_visitor; -}; -#endif - diff --git a/src/framework/Network/SocketDefines.h b/src/framework/Network/SocketDefines.h deleted file mode 100644 index 49366097ae6..00000000000 --- a/src/framework/Network/SocketDefines.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_SOCKETDEFINES_H -#define TRINITY_SOCKETDEFINES_H - -#ifdef WIN32 - -/* Windows socket definitions - */ -#define FD_SETSIZE 1024 -#include <winsock2.h> -#include <Ws2tcpip.h> - -typedef SOCKET SocketHandle; -typedef fd_set SelectSet; - -#else - -/* The unix socket definitions - */ -#include <sys/socket.h> -#include <netinet/in.h> -#ifdef __APPLE_CC__ -#include <sys/select.h> -#endif - -typedef int SocketHandle; -typedef fd_set SelectSet; -#endif -#endif - diff --git a/src/framework/Platform/CompilerDefs.h b/src/framework/Platform/CompilerDefs.h deleted file mode 100644 index fb7dbfe4caa..00000000000 --- a/src/framework/Platform/CompilerDefs.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_COMPILERDEFS_H -#define TRINITY_COMPILERDEFS_H - -#define PLATFORM_WINDOWS 0 -#define PLATFORM_UNIX 1 -#define PLATFORM_APPLE 2 -#define PLATFORM_INTEL 3 - -// must be first (win 64 also define WIN32) -#if defined( _WIN64 ) -# define PLATFORM PLATFORM_WINDOWS -#elif defined( __WIN32__ ) || defined( WIN32 ) || defined( _WIN32 ) -# define PLATFORM PLATFORM_WINDOWS -#elif defined( __APPLE_CC__ ) -# define PLATFORM PLATFORM_APPLE -#elif defined( __INTEL_COMPILER ) -# define PLATFORM PLATFORM_INTEL -#else -# define PLATFORM PLATFORM_UNIX -#endif - -#define COMPILER_MICROSOFT 0 -#define COMPILER_GNU 1 -#define COMPILER_BORLAND 2 -#define COMPILER_INTEL 3 - -#ifdef _MSC_VER -# define COMPILER COMPILER_MICROSOFT -#elif defined( __BORLANDC__ ) -# define COMPILER COMPILER_BORLAND -#elif defined( __INTEL_COMPILER ) -# define COMPILER COMPILER_INTEL -#elif defined( __GNUC__ ) -# define COMPILER COMPILER_GNU -#else -# pragma error "FATAL ERROR: Unknown compiler." -#endif - -#if COMPILER == COMPILER_MICROSOFT -# pragma warning( disable : 4267 ) // conversion from 'size_t' to 'int', possible loss of data -# pragma warning( disable : 4786 ) // identifier was truncated to '255' characters in the debug information -#endif -#endif - diff --git a/src/framework/Platform/Define.h b/src/framework/Platform/Define.h deleted file mode 100644 index 9285bf289f9..00000000000 --- a/src/framework/Platform/Define.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_DEFINE_H -#define TRINITY_DEFINE_H - -#include <sys/types.h> - -#include <ace/Basic_Types.h> -#include <ace/ACE_export.h> - -#include "Platform/CompilerDefs.h" - -#define TRINITY_LITTLEENDIAN 0 -#define TRINITY_BIGENDIAN 1 - -#if !defined(TRINITY_ENDIAN) -# if defined (ACE_BIG_ENDIAN) -# define TRINITY_ENDIAN TRINITY_BIGENDIAN -# else //ACE_BYTE_ORDER != ACE_BIG_ENDIAN -# define TRINITY_ENDIAN TRINITY_LITTLEENDIAN -# endif //ACE_BYTE_ORDER -#endif //TRINITY_ENDIAN - -#if PLATFORM == PLATFORM_WINDOWS -# define TRINITY_PATH_MAX MAX_PATH -# ifndef DECLSPEC_NORETURN -# define DECLSPEC_NORETURN __declspec(noreturn) -# endif //DECLSPEC_NORETURN -#else //PLATFORM != PLATFORM_WINDOWS -# define TRINITY_PATH_MAX PATH_MAX -# define DECLSPEC_NORETURN -#endif //PLATFORM - -#if !defined(DEBUG) -# define TRINITY_INLINE inline -#else //DEBUG -# if !defined(TRINITY_DEBUG) -# define TRINITY_DEBUG -# endif //TRINITY_DEBUG -# define TRINITY_INLINE -#endif //!DEBUG - -#if COMPILER == COMPILER_GNU -# define ATTR_NORETURN __attribute__((noreturn)) -# define ATTR_PRINTF(F,V) __attribute__ ((format (printf, F, V))) -#else //COMPILER != COMPILER_GNU -# define ATTR_NORETURN -# define ATTR_PRINTF(F,V) -#endif //COMPILER == COMPILER_GNU - -typedef ACE_INT64 int64; -typedef ACE_INT32 int32; -typedef ACE_INT16 int16; -typedef ACE_INT8 int8; -typedef ACE_UINT64 uint64; -typedef ACE_UINT32 uint32; -typedef ACE_UINT16 uint16; -typedef ACE_UINT8 uint8; - -#if COMPILER != COMPILER_MICROSOFT -typedef uint16 WORD; -typedef uint32 DWORD; -#endif //COMPILER - -typedef uint64 OBJECT_HANDLE; - -#endif //TRINITY_DEFINE_H diff --git a/src/framework/Policies/CreationPolicy.h b/src/framework/Policies/CreationPolicy.h deleted file mode 100644 index 8552ce7da52..00000000000 --- a/src/framework/Policies/CreationPolicy.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_CREATIONPOLICY_H -#define TRINITY_CREATIONPOLICY_H - -#include <stdlib.h> -#include "Platform/Define.h" - -namespace Trinity -{ - /** - * OperatorNew policy creates an object on the heap using new. - */ - template <class T> - class OperatorNew - { - public: - static T* Create(void) { return (new T); } - static void Destroy(T *obj) { delete obj; } - }; - - /** - * LocalStaticCreation policy creates an object on the stack - * the first time call Create. - */ - template <class T> - class LocalStaticCreation - { - union MaxAlign - { - char t_[sizeof(T)]; - short int shortInt_; - int int_; - long int longInt_; - float float_; - double double_; - long double longDouble_; - struct Test; - int Test::* pMember_; - int (Test::*pMemberFn_)(int); - }; - public: - static T* Create(void) - { - static MaxAlign si_localStatic; - return new(&si_localStatic) T; - } - - static void Destroy(T *obj) { obj->~T(); } - }; - - /** - * CreateUsingMalloc by pass the memory manger. - */ - template<class T> - class CreateUsingMalloc - { - public: - static T* Create() - { - void* p = ::malloc(sizeof(T)); - if (!p) return 0; - return new(p) T; - } - - static void Destroy(T* p) - { - p->~T(); - ::free(p); - } - }; - - /** - * CreateOnCallBack creates the object base on the call back. - */ - template<class T, class CALL_BACK> - class CreateOnCallBack - { - public: - static T* Create() - { - return CALL_BACK::createCallBack(); - } - - static void Destroy(T *p) - { - CALL_BACK::destroyCallBack(p); - } - }; -} -#endif - diff --git a/src/framework/Policies/ObjectLifeTime.cpp b/src/framework/Policies/ObjectLifeTime.cpp deleted file mode 100644 index fd16873ae92..00000000000 --- a/src/framework/Policies/ObjectLifeTime.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include <cstdlib> -#include "ObjectLifeTime.h" - -namespace Trinity -{ - extern "C" void external_wrapper(void *p) - { - std::atexit( (void (*)())p ); - } - - void at_exit( void (*func)() ) - { - external_wrapper((void*)func); - } -} - diff --git a/src/framework/Policies/ObjectLifeTime.h b/src/framework/Policies/ObjectLifeTime.h deleted file mode 100644 index 61b90b59f6e..00000000000 --- a/src/framework/Policies/ObjectLifeTime.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_OBJECTLIFETIME_H -#define TRINITY_OBJECTLIFETIME_H - -#include <stdexcept> -#include "Platform/Define.h" - -typedef void (* Destroyer)(void); - -namespace Trinity -{ - void at_exit( void (*func)() ); - - template <class T> - class ObjectLifeTime - { - public: - static void ScheduleCall(void (*destroyer)() ) - { - at_exit( destroyer ); - } - - DECLSPEC_NORETURN static void OnDeadReference(void) ATTR_NORETURN; - - }; - - template <class T> - void ObjectLifeTime<T>::OnDeadReference(void) // We don't handle Dead Reference for now - { - throw std::runtime_error("Dead Reference"); - } -} -#endif - diff --git a/src/framework/Policies/Singleton.h b/src/framework/Policies/Singleton.h deleted file mode 100644 index da898558ca5..00000000000 --- a/src/framework/Policies/Singleton.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_SINGLETON_H -#define TRINITY_SINGLETON_H - -/** - * @brief class Singleton - */ - -#include "CreationPolicy.h" -#include "ThreadingModel.h" -#include "ObjectLifeTime.h" - -namespace Trinity -{ - template - < - typename T, - class ThreadingModel = Trinity::SingleThreaded<T>, - class CreatePolicy = Trinity::OperatorNew<T>, - class LifeTimePolicy = Trinity::ObjectLifeTime<T> - > - class Singleton - { - public: - static T& Instance(); - - protected: - Singleton() {}; - - private: - - // Prohibited actions...this does not prevent hijacking. - Singleton(const Singleton &); - Singleton& operator=(const Singleton &); - - // Singleton Helpers - static void DestroySingleton(); - - // data structure - typedef typename ThreadingModel::Lock Guard; - static T *si_instance; - static bool si_destroyed; - }; -} -#endif - diff --git a/src/framework/Policies/SingletonImp.h b/src/framework/Policies/SingletonImp.h deleted file mode 100644 index 3e985cd5c64..00000000000 --- a/src/framework/Policies/SingletonImp.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_SINGLETONIMPL_H -#define TRINITY_SINGLETONIMPL_H - -#include "Singleton.h" - -// avoid the using namespace here cuz -// its a .h file afterall - -template -< -typename T, -class ThreadingModel, -class CreatePolicy, -class LifeTimePolicy -> -T& -Trinity::Singleton<T, ThreadingModel, CreatePolicy, LifeTimePolicy >::Instance() -{ - if( !si_instance ) - { - // double-checked Locking pattern - Guard(); - if( !si_instance ) - { - if( si_destroyed ) - { - si_destroyed = false; - LifeTimePolicy::OnDeadReference(); - } - si_instance = CreatePolicy::Create(); - LifeTimePolicy::ScheduleCall(&DestroySingleton); - } - } - - return *si_instance; -} - -template -< -typename T, -class ThreadingModel, -class CreatePolicy, -class LifeTimePolicy -> -void -Trinity::Singleton<T, ThreadingModel, CreatePolicy, LifeTimePolicy>::DestroySingleton() -{ - CreatePolicy::Destroy(si_instance); - si_instance = NULL; - si_destroyed = true; -} - -#define INSTANTIATE_SINGLETON_1(TYPE) \ - template class Trinity::Singleton<TYPE, Trinity::SingleThreaded<TYPE>, Trinity::OperatorNew<TYPE>, Trinity::ObjectLifeTime<TYPE> >; \ - template<> TYPE* Trinity::Singleton<TYPE, Trinity::SingleThreaded<TYPE>, Trinity::OperatorNew<TYPE>, Trinity::ObjectLifeTime<TYPE> >::si_instance = 0; \ - template<> bool Trinity::Singleton<TYPE, Trinity::SingleThreaded<TYPE>, Trinity::OperatorNew<TYPE>, Trinity::ObjectLifeTime<TYPE> >::si_destroyed = false - -#define INSTANTIATE_SINGLETON_2(TYPE, THREADINGMODEL) \ - template class Trinity::Singleton<TYPE, THREADINGMODEL, Trinity::OperatorNew<TYPE>, Trinity::ObjectLifeTime<TYPE> >; \ - template<> TYPE* Trinity::Singleton<TYPE, THREADINGMODEL, Trinity::OperatorNew<TYPE>, Trinity::ObjectLifeTime<TYPE> >::si_instance = 0; \ - template<> bool Trinity::Singleton<TYPE, THREADINGMODEL, Trinity::OperatorNew<TYPE>, Trinity::ObjectLifeTime<TYPE> >::si_destroyed = false - -#define INSTANTIATE_SINGLETON_3(TYPE, THREADINGMODEL, CREATIONPOLICY ) \ - template class Trinity::Singleton<TYPE, THREADINGMODEL, CREATIONPOLICY, Trinity::ObjectLifeTime<TYPE> >; \ - template<> TYPE* Trinity::Singleton<TYPE, THREADINGMODEL, CREATIONPOLICY, Trinity::ObjectLifeTime<TYPE> >::si_instance = 0; \ - template<> bool Trinity::Singleton<TYPE, THREADINGMODEL, CREATIONPOLICY, Trinity::ObjectLifeType<TYPE> >::si_destroyed = false - -#define INSTANTIATE_SINGLETON_4(TYPE, THREADINGMODEL, CREATIONPOLICY, OBJECTLIFETIME) \ - template class Trinity::Singleton<TYPE, THREADINGMODEL, CREATIONPOLICY, OBJECTLIFETIME >; \ - template<> TYPE* Trinity::Singleton<TYPE, THREADINGMODEL, CREATIONPOLICY, OBJECTLIFETIME >::si_instance = 0; \ - template<> bool Trinity::Singleton<TYPE, THREADINGMODEL, CREATIONPOLICY, OBJECTLIFETIME >::si_destroyed = false -#endif - diff --git a/src/framework/Policies/ThreadingModel.h b/src/framework/Policies/ThreadingModel.h deleted file mode 100644 index d4c5e9a2333..00000000000 --- a/src/framework/Policies/ThreadingModel.h +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_THREADINGMODEL_H -#define TRINITY_THREADINGMODEL_H - -/** - * @class ThreadingModel<T> - * - */ - -#include "Platform/Define.h" - -namespace Trinity -{ - inline void Guard(void *) {} - - template<typename MUTEX> class GeneralLock - { - public: - GeneralLock(MUTEX &m) : i_mutex(m) - { - i_mutex.acquire(); - } - - ~GeneralLock() - { - i_mutex.release(); - } - private: - GeneralLock(const GeneralLock &); - GeneralLock& operator=(const GeneralLock &); - MUTEX &i_mutex; - }; - - template <class T> - class SingleThreaded - { - public: - - struct Lock // empty object - { - Lock() {} - Lock(const T &) {} - Lock(const SingleThreaded<T> &) // for single threaded we ignore this - { - } - }; - - typedef T VolatileType; - }; - - // object level lockable - template<class T, class MUTEX> - class ObjectLevelLockable - { - public: - ObjectLevelLockable() : i_mtx() {} - - friend class Lock; - - class Lock - { - public: - Lock(ObjectLevelLockable<T, MUTEX> &host) : i_lock(host.i_mtx) - { - } - - private: - GeneralLock<MUTEX> i_lock; - }; - - typedef volatile T VolatileType; - - private: - // prevent the compiler creating a copy construct - ObjectLevelLockable(const ObjectLevelLockable<T, MUTEX> &); - ObjectLevelLockable<T, MUTEX>& operator=(const ObjectLevelLockable<T, MUTEX> &); - - MUTEX i_mtx; - }; - - template<class T, class MUTEX> - class ClassLevelLockable - { - public: - class Lock; - friend class Lock; - typedef volatile T VolatileType; - - ClassLevelLockable() {} - - class Lock - { - public: - Lock(T& /*host*/) { ClassLevelLockable<T, MUTEX>::si_mtx.acquire(); } - Lock(ClassLevelLockable<T, MUTEX> &) { ClassLevelLockable<T, MUTEX>::si_mtx.acquire(); } - Lock() { ClassLevelLockable<T, MUTEX>::si_mtx.acquire(); } - ~Lock() { ClassLevelLockable<T, MUTEX>::si_mtx.release(); } - }; - - private: - static MUTEX si_mtx; - }; - -} - -template<class T, class MUTEX> MUTEX Trinity::ClassLevelLockable<T, MUTEX>::si_mtx; - -#define INSTANTIATE_CLASS_MUTEX(CTYPE,MUTEX) \ - template class Trinity::ClassLevelLockable<CTYPE, MUTEX > -#endif - diff --git a/src/framework/Utilities/ByteConverter.h b/src/framework/Utilities/ByteConverter.h deleted file mode 100644 index f8b6bd72498..00000000000 --- a/src/framework/Utilities/ByteConverter.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_BYTECONVERTER_H -#define TRINITY_BYTECONVERTER_H - -/** ByteConverter reverse your byte order. This is use - for cross platform where they have different endians. - */ - -#include<Platform/Define.h> -#include<algorithm> - -namespace ByteConverter -{ - template<size_t T> - inline void convert(char *val) - { - std::swap(*val, *(val + T - 1)); - convert<T - 2>(val + 1); - } - - template<> inline void convert<0>(char *) {} - template<> inline void convert<1>(char *) {} // ignore central byte - - template<typename T> inline void apply(T *val) - { - convert<sizeof(T)>((char *)(val)); - } -} - -#if TRINITY_ENDIAN == TRINITY_BIGENDIAN -template<typename T> inline void EndianConvert(T& val) { ByteConverter::apply<T>(&val); } -template<typename T> inline void EndianConvertReverse(T&) { } -#else -template<typename T> inline void EndianConvert(T&) { } -template<typename T> inline void EndianConvertReverse(T& val) { ByteConverter::apply<T>(&val); } -#endif - -template<typename T> void EndianConvert(T*); // will generate link error -template<typename T> void EndianConvertReverse(T*); // will generate link error - -inline void EndianConvert(uint8&) { } -inline void EndianConvert( int8&) { } -inline void EndianConvertReverse(uint8&) { } -inline void EndianConvertReverse( int8&) { } - -#endif - diff --git a/src/framework/Utilities/Callback.h b/src/framework/Utilities/Callback.h deleted file mode 100644 index d2e2c36851a..00000000000 --- a/src/framework/Utilities/Callback.h +++ /dev/null @@ -1,386 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_CALLBACK_H -#define TRINITY_CALLBACK_H - -/// ------------ BASE CLASSES ------------ - -namespace Trinity -{ - template < class Class, typename ParamType1 = void, typename ParamType2 = void, typename ParamType3 = void, typename ParamType4 = void > - class _Callback - { - protected: - typedef void (Class::*Method)(ParamType1, ParamType2, ParamType3, ParamType4); - Class *m_object; - Method m_method; - ParamType1 m_param1; - ParamType2 m_param2; - ParamType3 m_param3; - ParamType4 m_param4; - void _Execute() { (m_object->*m_method)(m_param1, m_param2, m_param3, m_param4); } - public: - _Callback(Class *object, Method method, ParamType1 param1, ParamType2 param2, ParamType3 param3, ParamType4 param4) - : m_object(object), m_method(method), m_param1(param1), m_param2(param2), m_param3(param3), m_param4(param4) {} - _Callback(_Callback < Class, ParamType1, ParamType2, ParamType3, ParamType4> const& cb) - : m_object(cb.object), m_method(cb.m_method), m_param1(cb.m_param1), m_param2(cb.m_param2), m_param3(cb.m_param3), m_param4(cb.m_param4) {} - }; - - template < class Class, typename ParamType1, typename ParamType2, typename ParamType3 > - class _Callback < Class, ParamType1, ParamType2, ParamType3 > - { - protected: - typedef void (Class::*Method)(ParamType1, ParamType2, ParamType3); - Class *m_object; - Method m_method; - ParamType1 m_param1; - ParamType2 m_param2; - ParamType3 m_param3; - void _Execute() { (m_object->*m_method)(m_param1, m_param2, m_param3); } - public: - _Callback(Class *object, Method method, ParamType1 param1, ParamType2 param2, ParamType3 param3) - : m_object(object), m_method(method), m_param1(param1), m_param2(param2) {} - _Callback(_Callback < Class, ParamType1, ParamType2, ParamType3 > const& cb) - : m_object(cb.object), m_method(cb.m_method), m_param1(cb.m_param1), m_param2(cb.m_param2), m_param3(cb.m_param3) {} - }; - - template < class Class, typename ParamType1, typename ParamType2 > - class _Callback < Class, ParamType1, ParamType2 > - { - protected: - typedef void (Class::*Method)(ParamType1, ParamType2); - Class *m_object; - Method m_method; - ParamType1 m_param1; - ParamType2 m_param2; - void _Execute() { (m_object->*m_method)(m_param1, m_param2); } - public: - _Callback(Class *object, Method method, ParamType1 param1, ParamType2 param2) - : m_object(object), m_method(method), m_param1(param1), m_param2(param2) {} - _Callback(_Callback < Class, ParamType1, ParamType2 > const& cb) - : m_object(cb.m_object), m_method(cb.m_method), m_param1(cb.m_param1), m_param2(cb.m_param2) {} - }; - - template < class Class, typename ParamType1 > - class _Callback < Class, ParamType1 > - { - protected: - typedef void (Class::*Method)(ParamType1); - Class *m_object; - Method m_method; - ParamType1 m_param1; - void _Execute() { (m_object->*m_method)(m_param1); } - public: - _Callback(Class *object, Method method, ParamType1 param1) - : m_object(object), m_method(method), m_param1(param1) {} - _Callback(_Callback < Class, ParamType1 > const& cb) - : m_object(cb.m_object), m_method(cb.m_method), m_param1(cb.m_param1) {} - }; - - template < class Class > - class _Callback < Class > - { - protected: - typedef void (Class::*Method)(); - Class *m_object; - Method m_method; - void _Execute() { (m_object->*m_method)(); } - public: - _Callback(Class *object, Method method) - : m_object(object), m_method(method) {} - _Callback(_Callback < Class > const& cb) - : m_object(cb.m_object), m_method(cb.m_method) {} - }; - - /// ---- Statics ---- - - template < typename ParamType1 = void, typename ParamType2 = void, typename ParamType3 = void, typename ParamType4 = void > - class _SCallback - { - protected: - typedef void (*Method)(ParamType1, ParamType2, ParamType3, ParamType4); - Method m_method; - ParamType1 m_param1; - ParamType2 m_param2; - ParamType3 m_param3; - ParamType4 m_param4; - void _Execute() { (*m_method)(m_param1, m_param2, m_param3, m_param4); } - public: - _SCallback(Method method, ParamType1 param1, ParamType2 param2, ParamType3 param3, ParamType4 param4) - : m_method(method), m_param1(param1), m_param2(param2), m_param3(param3), m_param4(param4) {} - _SCallback(_SCallback < ParamType1, ParamType2, ParamType3, ParamType4> const& cb) - : m_method(cb.m_method), m_param1(cb.m_param1), m_param2(cb.m_param2), m_param3(cb.m_param3), m_param4(cb.m_param4) {} - }; - - template < typename ParamType1, typename ParamType2, typename ParamType3 > - class _SCallback < ParamType1, ParamType2, ParamType3 > - { - protected: - typedef void (*Method)(ParamType1, ParamType2, ParamType3); - Method m_method; - ParamType1 m_param1; - ParamType2 m_param2; - ParamType3 m_param3; - void _Execute() { (*m_method)(m_param1, m_param2, m_param3); } - public: - _SCallback(Method method, ParamType1 param1, ParamType2 param2, ParamType3 param3) - : m_method(method), m_param1(param1), m_param2(param2), m_param3(param3) {} - _SCallback(_SCallback < ParamType1, ParamType2, ParamType3 > const& cb) - : m_method(cb.m_method), m_param1(cb.m_param1), m_param2(cb.m_param2), m_param3(cb.m_param3) {} - }; - - template < typename ParamType1, typename ParamType2 > - class _SCallback < ParamType1, ParamType2 > - { - protected: - typedef void (*Method)(ParamType1, ParamType2); - Method m_method; - ParamType1 m_param1; - ParamType2 m_param2; - void _Execute() { (*m_method)(m_param1, m_param2); } - public: - _SCallback(Method method, ParamType1 param1, ParamType2 param2) - : m_method(method), m_param1(param1), m_param2(param2) {} - _SCallback(_SCallback < ParamType1, ParamType2 > const& cb) - : m_method(cb.m_method), m_param1(cb.m_param1), m_param2(cb.m_param2) {} - }; - - template < typename ParamType1 > - class _SCallback < ParamType1 > - { - protected: - typedef void (*Method)(ParamType1); - Method m_method; - ParamType1 m_param1; - void _Execute() { (*m_method)(m_param1); } - public: - _SCallback(Method method, ParamType1 param1) - : m_method(method), m_param1(param1) {} - _SCallback(_SCallback < ParamType1 > const& cb) - : m_method(cb.m_method), m_param1(cb.m_param1) {} - }; - - template < > - class _SCallback < > - { - protected: - typedef void (*Method)(); - Method m_method; - void _Execute() { (*m_method)(); } - public: - _SCallback(Method method) - : m_method(method) {} - _SCallback(_SCallback <> const& cb) - : m_method(cb.m_method) {} - }; -} - -/// --------- GENERIC CALLBACKS ---------- - -namespace Trinity -{ - class ICallback - { - public: - virtual void Execute() = 0; - virtual ~ICallback() {} - }; - - template < class CB > - class _ICallback : public CB, public ICallback - { - public: - _ICallback(CB const& cb) : CB(cb) {} - void Execute() { CB::_Execute(); } - }; - - template < class Class, typename ParamType1 = void, typename ParamType2 = void, typename ParamType3 = void, typename ParamType4 = void > - class Callback : - public _ICallback< _Callback < Class, ParamType1, ParamType2, ParamType3, ParamType4 > > - { - private: - typedef _Callback < Class, ParamType1, ParamType2, ParamType3, ParamType4 > C4; - public: - Callback(Class *object, typename C4::Method method, ParamType1 param1, ParamType2 param2, ParamType3 param3, ParamType4 param4) - : _ICallback< C4 >(C4(object, method, param1, param2, param3, param4)) {} - }; - - template < class Class, typename ParamType1, typename ParamType2, typename ParamType3 > - class Callback < Class, ParamType1, ParamType2, ParamType3 > : - public _ICallback< _Callback < Class, ParamType1, ParamType2, ParamType3 > > - { - private: - typedef _Callback < Class, ParamType1, ParamType2, ParamType3 > C3; - public: - Callback(Class *object, typename C3::Method method, ParamType1 param1, ParamType2 param2, ParamType3 param3) - : _ICallback< C3 >(C3(object, method, param1, param2, param3)) {} - }; - - template < class Class, typename ParamType1, typename ParamType2 > - class Callback < Class, ParamType1, ParamType2 > : - public _ICallback< _Callback < Class, ParamType1, ParamType2 > > - { - private: - typedef _Callback < Class, ParamType1, ParamType2 > C2; - public: - Callback(Class *object, typename C2::Method method, ParamType1 param1, ParamType2 param2) - : _ICallback< C2 >(C2(object, method, param1, param2)) {} - }; - - template < class Class, typename ParamType1 > - class Callback < Class, ParamType1 > : - public _ICallback< _Callback < Class, ParamType1 > > - { - private: - typedef _Callback < Class, ParamType1 > C1; - public: - Callback(Class *object, typename C1::Method method, ParamType1 param1) - : _ICallback< C1 >(C1(object, method, param1)) {} - }; - - template < class Class > - class Callback < Class > : public _ICallback< _Callback < Class > > - { - private: - typedef _Callback < Class > C0; - public: - Callback(Class *object, typename C0::Method method) - : _ICallback< C0 >(C0(object, method)) {} - }; -} - -/// ---------- QUERY CALLBACKS ----------- - -#include "QueryResult.h" -class QueryResult; - -namespace Trinity -{ - class IQueryCallback - { - public: - virtual void Execute() = 0; - virtual ~IQueryCallback() {} - virtual void SetResult(QueryResult_AutoPtr result) = 0; - virtual QueryResult_AutoPtr GetResult() = 0; - }; - - template < class CB > - class _IQueryCallback : public CB, public IQueryCallback - { - public: - _IQueryCallback(CB const& cb) : CB(cb) {} - void Execute() { CB::_Execute(); } - void SetResult(QueryResult_AutoPtr result) { CB::m_param1 = result; } - QueryResult_AutoPtr GetResult() { return CB::m_param1; } - }; - - template < class Class, typename ParamType1 = void, typename ParamType2 = void, typename ParamType3 = void > - class QueryCallback : - public _IQueryCallback< _Callback < Class, QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3 > > - { - private: - typedef _Callback < Class, QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3 > QC3; - public: - QueryCallback(Class *object, typename QC3::Method method, QueryResult_AutoPtr result, ParamType1 param1, ParamType2 param2, ParamType3 param3) - : _IQueryCallback< QC3 >(QC3(object, method, result, param1, param2, param3)) {} - }; - - template < class Class, typename ParamType1, typename ParamType2 > - class QueryCallback < Class, ParamType1, ParamType2 > : - public _IQueryCallback< _Callback < Class, QueryResult_AutoPtr, ParamType1, ParamType2 > > - { - private: - typedef _Callback < Class, QueryResult_AutoPtr, ParamType1, ParamType2 > QC2; - public: - QueryCallback(Class *object, typename QC2::Method method, QueryResult_AutoPtr result, ParamType1 param1, ParamType2 param2) - : _IQueryCallback< QC2 >(QC2(object, method, result, param1, param2)) {} - }; - - template < class Class, typename ParamType1 > - class QueryCallback < Class, ParamType1 > : - public _IQueryCallback< _Callback < Class, QueryResult_AutoPtr, ParamType1 > > - { - private: - typedef _Callback < Class, QueryResult_AutoPtr, ParamType1 > QC1; - public: - QueryCallback(Class *object, typename QC1::Method method, QueryResult_AutoPtr result, ParamType1 param1) - : _IQueryCallback< QC1 >(QC1(object, method, result, param1)) {} - }; - - template < class Class > - class QueryCallback < Class > : public _IQueryCallback< _Callback < Class, QueryResult_AutoPtr > > - { - private: - typedef _Callback < Class, QueryResult_AutoPtr > QC0; - public: - QueryCallback(Class *object, typename QC0::Method method, QueryResult_AutoPtr result) - : _IQueryCallback< QC0 >(QC0(object, method, result)) {} - }; - - /// ---- Statics ---- - - template < typename ParamType1 = void, typename ParamType2 = void, typename ParamType3 = void > - class SQueryCallback : - public _IQueryCallback< _SCallback < QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3 > > - { - private: - typedef _SCallback < QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3 > QC3; - public: - SQueryCallback(typename QC3::Method method, QueryResult_AutoPtr result, ParamType1 param1, ParamType2 param2, ParamType3 param3) - : _IQueryCallback< QC3 >(QC3(method, result, param1, param2, param3)) {} - }; - - template < typename ParamType1, typename ParamType2 > - class SQueryCallback < ParamType1, ParamType2 > : - public _IQueryCallback< _SCallback < QueryResult_AutoPtr, ParamType1, ParamType2 > > - { - private: - typedef _SCallback < QueryResult_AutoPtr, ParamType1, ParamType2 > QC2; - public: - SQueryCallback(typename QC2::Method method, QueryResult_AutoPtr result, ParamType1 param1, ParamType2 param2) - : _IQueryCallback< QC2 >(QC2(method, result, param1, param2)) {} - }; - - template < typename ParamType1 > - class SQueryCallback < ParamType1 > : - public _IQueryCallback< _SCallback < QueryResult_AutoPtr, ParamType1 > > - { - private: - typedef _SCallback < QueryResult_AutoPtr, ParamType1 > QC1; - public: - SQueryCallback(typename QC1::Method method, QueryResult_AutoPtr result, ParamType1 param1) - : _IQueryCallback< QC1 >(QC1(method, result, param1)) {} - }; - - template < > - class SQueryCallback < > : public _IQueryCallback< _SCallback < QueryResult_AutoPtr > > - { - private: - typedef _SCallback < QueryResult_AutoPtr > QC0; - public: - SQueryCallback(QC0::Method method, QueryResult_AutoPtr result) - : _IQueryCallback< QC0 >(QC0(method, result)) {} - }; -} - -#endif - diff --git a/src/framework/Utilities/CountedReference/Reference.h b/src/framework/Utilities/CountedReference/Reference.h deleted file mode 100644 index d3cfe55ffc0..00000000000 --- a/src/framework/Utilities/CountedReference/Reference.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_REFERENCE_H -#define TRINITY_REFERENCE_H - -/** - * Referencer<T> - * Referencer is an object that holds a reference holder that hold a reference - * counted object. When an object's reference count drop to zero, it removes - * the object. This is a non intrusive mechanism and any object at any point - * in time can be referenced. When and object is reference counted, do not - * pass the object directly to other methods but rather, pass its - * reference around. Objects can be reference counted in both single threaded - * model and multi-threaded model - */ - -#include <stdexcept> -#include "Platform/Define.h" -#include "Policies/ThreadingModel.h" -#include "ReferenceHolder.h" - -template -< -typename T, -class THREADING_MODEL = Trinity::SingleThreaded<T> -> -class Referencer -{ - typedef typename THREADING_MODEL::Lock Lock; - typedef ReferenceHolder<T, THREADING_MODEL> ReferenceeHolder; - public: - - /// Constructs a referencer. - Referencer(T *ref = NULL); - - /// Copy constructor - Referencer(const Referencer &obj) : i_holder(NULL) { *this = obj; } - - /// Destructor - ~Referencer(); - - /// Referencee accessor - T* referencee(void) { return (i_holder == NULL ? NULL : i_holder->i_referencee); } - const T* referencee(void) const { return (i_holder == NULL ? NULL : i_holder->i_referencee); } - - //T& referencee(void){ return _referencee(); } - //const T& referencee(void) const { return const_cast<Referencer *>(this)->_referencee(); } - operator T&(void) { return _referencee(); } - operator const T&(void) const { return *const_cast<Referencer *>(this)->_referencee(); } - - /// cast operators - T* operator*() { return (i_holder == NULL ? NULL : i_holder->i_referencee); } - T const * operator*() const { return (i_holder == NULL ? NULL : i_holder->i_referencee); } - - /// overload operators - T* operator->() { return (i_holder == NULL ? NULL : i_holder->i_referencee); } - const T * operator->() const { return (i_holder == NULL ? NULL : i_holder->i_referencee); } - - /// operator = - Referencer& operator=(const Referencer &obj); - Referencer& operator=(T *); - - /// returns true if i_referencee is null - bool isNull(void) const { return i_holder == NULL; } - - private: - - T& _referencee(void) - { - if( i_holder == NULL ) - throw std::runtime_error("Invalid access to null pointer"); - return *i_holder->i_referencee; - } - - void deReference(ReferenceeHolder *); - void addReference(ReferenceeHolder *); - - // private data - ReferenceeHolder *i_holder; -}; -#endif - diff --git a/src/framework/Utilities/CountedReference/ReferenceHolder.h b/src/framework/Utilities/CountedReference/ReferenceHolder.h deleted file mode 100644 index 597e9854be0..00000000000 --- a/src/framework/Utilities/CountedReference/ReferenceHolder.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_REFERENCEHOLDER_H -#define TRINITY_REFERENCEHOLDER_H - -/** ReferenceHolder holds the actualy referenced obejct as well the refence - count. The ReferenecHolder implements as a policy base object and - will decided by the Reference class to be consnsitent. - */ - -template -< -typename T, -class THREADING_MODEL -> -struct ReferenceHolder : public THREADING_MODEL -{ - explicit ReferenceHolder(T *ref) : i_referencee(ref), i_referenceCount(0) {} - T *i_referencee; - unsigned int i_referenceCount; - typedef typename THREADING_MODEL::Lock Lock; -}; -#endif - diff --git a/src/framework/Utilities/CountedReference/ReferenceImpl.h b/src/framework/Utilities/CountedReference/ReferenceImpl.h deleted file mode 100644 index cde330179e3..00000000000 --- a/src/framework/Utilities/CountedReference/ReferenceImpl.h +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_REFERENCEIMPL_H -#define TRINITY_REFERENCEIMPL_H - -#include "Reference.h" - -template -< -typename T, -class THREADING_MODEL -> -Referencer<T, THREADING_MODEL>::Referencer(T *ref) -: i_holder(NULL) -{ - if( ref != NULL ) - { - i_holder = new ReferenceeHolder(ref); - ++i_holder->i_referenceCount; - } -} - -template -< -typename T, -class THREADING_MODEL -> -Referencer<T, THREADING_MODEL>::~Referencer() -{ - if( i_holder != NULL ) - deReference(i_holder); - i_holder = NULL; -} - -template -< -typename T, -class THREADING_MODEL -> -Referencer<T, THREADING_MODEL>& -Referencer<T, THREADING_MODEL>::operator=(const Referencer<T, THREADING_MODEL> &obj) -{ - if( i_holder != NULL ) - deReference(i_holder); - if( obj.i_holder != NULL ) - addReference(obj.i_holder); - i_holder = obj.i_holder; - return *this; -} - -template -< -typename T, -class THREADING_MODEL -> -Referencer<T, THREADING_MODEL>& -Referencer<T, THREADING_MODEL>::operator=(T *ref) -{ - if( i_holder != NULL ) - deReference(i_holder); - i_holder = NULL; - if( ref != NULL ) - { - i_holder = new ReferenceeHolder(ref); - ++i_holder->i_referenceCount; - } - - return *this; -} - -template -< -typename T, -class THREADING_MODEL -> -void -Referencer<T, THREADING_MODEL>::deReference(ReferenceHolder<T, THREADING_MODEL> *holder) -{ - assert( holder != NULL && holder->i_referenceCount > 0); - bool delete_object = false; - - { - // The guard is within the scope due to the guard - // must release earlier than expected. - Lock guard(*holder); - Guard(&guard); - - --holder->i_referenceCount; - if( holder->i_referenceCount == 0 ) - delete_object = true; - } - - if( delete_object ) - { - delete holder->i_referencee; - delete holder; - } -} - -template -< -typename T, -class THREADING_MODEL -> -void -Referencer<T, THREADING_MODEL>::addReference(ReferenceHolder<T, THREADING_MODEL> *holder) -{ - assert( i_holder != NULL ); - Lock guard(*holder); - Guard(&guard); - - ++holder->i_referenceCount; -} -#endif - diff --git a/src/framework/Utilities/EventProcessor.cpp b/src/framework/Utilities/EventProcessor.cpp deleted file mode 100644 index c695b43313a..00000000000 --- a/src/framework/Utilities/EventProcessor.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "EventProcessor.h" - -EventProcessor::EventProcessor() -{ - m_time = 0; - m_aborting = false; -} - -EventProcessor::~EventProcessor() -{ - KillAllEvents(true); -} - -void EventProcessor::Update(uint32 p_time) -{ - // update time - m_time += p_time; - - // main event loop - EventList::iterator i; - while (((i = m_events.begin()) != m_events.end()) && i->first <= m_time) - { - // get and remove event from queue - BasicEvent* Event = i->second; - m_events.erase(i); - - if (!Event->to_Abort) - { - if (Event->Execute(m_time, p_time)) - { - // completely destroy event if it is not re-added - delete Event; - } - } - else - { - Event->Abort(m_time); - delete Event; - } - } -} - -void EventProcessor::KillAllEvents(bool force) -{ - // prevent event insertions - m_aborting = true; - - // first, abort all existing events - for (EventList::iterator i = m_events.begin(); i != m_events.end();) - { - EventList::iterator i_old = i; - ++i; - - i_old->second->to_Abort = true; - i_old->second->Abort(m_time); - if(force || i_old->second->IsDeletable()) - { - delete i_old->second; - - if(!force) // need per-element cleanup - m_events.erase (i_old); - } - } - - // fast clear event list (in force case) - if(force) - m_events.clear(); -} - -void EventProcessor::AddEvent(BasicEvent* Event, uint64 e_time, bool set_addtime) -{ - if (set_addtime) Event->m_addTime = m_time; - Event->m_execTime = e_time; - m_events.insert(std::pair<uint64, BasicEvent*>(e_time, Event)); -} - -uint64 EventProcessor::CalculateTime(uint64 t_offset) -{ - return(m_time + t_offset); -} - diff --git a/src/framework/Utilities/EventProcessor.h b/src/framework/Utilities/EventProcessor.h deleted file mode 100644 index 2712967e1b7..00000000000 --- a/src/framework/Utilities/EventProcessor.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef __EVENTPROCESSOR_H -#define __EVENTPROCESSOR_H - -#include "Platform/Define.h" - -#include<map> - -// Note. All times are in milliseconds here. - -class BasicEvent -{ - public: - BasicEvent() { to_Abort = false; } - virtual ~BasicEvent() // override destructor to perform some actions on event removal - { - }; - - // this method executes when the event is triggered - // return false if event does not want to be deleted - // e_time is execution time, p_time is update interval - virtual bool Execute(uint64 /*e_time*/, uint32 /*p_time*/) { return true; } - - virtual bool IsDeletable() const { return true; } // this event can be safely deleted - - virtual void Abort(uint64 /*e_time*/) {} // this method executes when the event is aborted - - bool to_Abort; // set by externals when the event is aborted, aborted events don't execute - // and get Abort call when deleted - - // these can be used for time offset control - uint64 m_addTime; // time when the event was added to queue, filled by event handler - uint64 m_execTime; // planned time of next execution, filled by event handler -}; - -typedef std::multimap<uint64, BasicEvent*> EventList; - -class EventProcessor -{ - public: - EventProcessor(); - ~EventProcessor(); - - void Update(uint32 p_time); - void KillAllEvents(bool force); - void AddEvent(BasicEvent* Event, uint64 e_time, bool set_addtime = true); - uint64 CalculateTime(uint64 t_offset); - protected: - uint64 m_time; - EventList m_events; - bool m_aborting; -}; -#endif - diff --git a/src/framework/Utilities/LinkedList.h b/src/framework/Utilities/LinkedList.h deleted file mode 100644 index b26687767b3..00000000000 --- a/src/framework/Utilities/LinkedList.h +++ /dev/null @@ -1,247 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _LINKEDLIST -#define _LINKEDLIST - -#include "Common.h" - -//============================================ -class LinkedListHead; - -class LinkedListElement -{ - private: - friend class LinkedListHead; - - LinkedListElement* iNext; - LinkedListElement* iPrev; - public: - LinkedListElement() { iNext = NULL; iPrev = NULL; } - ~LinkedListElement() { delink(); } - - bool hasNext() const { return(iNext && iNext->iNext != NULL); } - bool hasPrev() const { return(iPrev && iPrev->iPrev != NULL); } - bool isInList() const { return(iNext != NULL && iPrev != NULL); } - - LinkedListElement * next() { return hasNext() ? iNext : NULL; } - LinkedListElement const* next() const { return hasNext() ? iNext : NULL; } - LinkedListElement * prev() { return hasPrev() ? iPrev : NULL; } - LinkedListElement const* prev() const { return hasPrev() ? iPrev : NULL; } - - LinkedListElement * nocheck_next() { return iNext; } - LinkedListElement const* nocheck_next() const { return iNext; } - LinkedListElement * nocheck_prev() { return iPrev; } - LinkedListElement const* nocheck_prev() const { return iPrev; } - - void delink() - { - if(isInList()) - { - iNext->iPrev = iPrev; iPrev->iNext = iNext; iNext = NULL; iPrev = NULL; - } - } - - void insertBefore(LinkedListElement* pElem) - { - pElem->iNext = this; - pElem->iPrev = iPrev; - iPrev->iNext = pElem; - iPrev = pElem; - } - - void insertAfter(LinkedListElement* pElem) - { - pElem->iPrev = this; - pElem->iNext = iNext; - iNext->iPrev = pElem; - iNext = pElem; - } -}; - -//============================================ - -class LinkedListHead -{ - private: - LinkedListElement iFirst; - LinkedListElement iLast; - uint32 iSize; - public: - LinkedListHead() - { - // create empty list - - iFirst.iNext = &iLast; - iLast.iPrev = &iFirst; - iSize = 0; - } - - bool isEmpty() const { return(!iFirst.iNext->isInList()); } - - LinkedListElement * getFirst() { return(isEmpty() ? NULL : iFirst.iNext); } - LinkedListElement const* getFirst() const { return(isEmpty() ? NULL : iFirst.iNext); } - - LinkedListElement * getLast() { return(isEmpty() ? NULL : iLast.iPrev); } - LinkedListElement const* getLast() const { return(isEmpty() ? NULL : iLast.iPrev); } - - void insertFirst(LinkedListElement* pElem) - { - iFirst.insertAfter(pElem); - } - - void insertLast(LinkedListElement* pElem) - { - iLast.insertBefore(pElem); - } - - uint32 getSize() const - { - if(!iSize) - { - uint32 result = 0; - LinkedListElement const* e = getFirst(); - while(e) - { - ++result; - e = e->next(); - } - return result; - } - else - return iSize; - } - - void incSize() { ++iSize; } - void decSize() { --iSize; } - - template<class _Ty> - class Iterator - { - public: - typedef std::bidirectional_iterator_tag iterator_category; - typedef _Ty value_type; - typedef ptrdiff_t difference_type; - typedef ptrdiff_t distance_type; - typedef _Ty* pointer; - typedef _Ty const* const_pointer; - typedef _Ty& reference; - typedef _Ty const & const_reference; - - Iterator() : _Ptr(0) - { // construct with null node pointer - } - - Iterator(pointer _Pnode) : _Ptr(_Pnode) - { // construct with node pointer _Pnode - } - - Iterator& operator=(Iterator const &_Right) - { - return (*this) = _Right._Ptr; - } - - Iterator& operator=(const_pointer const &_Right) - { - _Ptr = (pointer)_Right; - return (*this); - } - - reference operator*() - { // return designated value - return *_Ptr; - } - - pointer operator->() - { // return pointer to class object - return _Ptr; - } - - Iterator& operator++() - { // preincrement - _Ptr = _Ptr->next(); - return (*this); - } - - Iterator operator++(int) - { // postincrement - iterator _Tmp = *this; - ++*this; - return (_Tmp); - } - - Iterator& operator--() - { // predecrement - _Ptr = _Ptr->prev(); - return (*this); - } - - Iterator operator--(int) - { // postdecrement - iterator _Tmp = *this; - --*this; - return (_Tmp); - } - - bool operator==(Iterator const &_Right) const - { // test for iterator equality - return (_Ptr == _Right._Ptr); - } - - bool operator!=(Iterator const &_Right) const - { // test for iterator inequality - return (!(*this == _Right)); - } - - bool operator==(pointer const &_Right) const - { // test for pointer equality - return (_Ptr != _Right); - } - - bool operator!=(pointer const &_Right) const - { // test for pointer equality - return (!(*this == _Right)); - } - - bool operator==(const_reference _Right) const - { // test for reference equality - return (_Ptr == &_Right); - } - - bool operator!=(const_reference _Right) const - { // test for reference equality - return (_Ptr != &_Right); - } - - pointer _Mynode() - { // return node pointer - return (_Ptr); - } - - protected: - pointer _Ptr; // pointer to node - }; - - typedef Iterator<LinkedListElement> iterator; -}; - -//============================================ -#endif - diff --git a/src/framework/Utilities/LinkedReference/RefManager.h b/src/framework/Utilities/LinkedReference/RefManager.h deleted file mode 100644 index 7e294b4f5f0..00000000000 --- a/src/framework/Utilities/LinkedReference/RefManager.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _REFMANAGER_H -#define _REFMANAGER_H -//===================================================== - -#include "Utilities/LinkedList.h" -#include "Utilities/LinkedReference/Reference.h" - -template <class TO, class FROM> class RefManager : public LinkedListHead -{ - public: - typedef LinkedListHead::Iterator< Reference<TO, FROM> > iterator; - RefManager() { } - virtual ~RefManager() { clearReferences(); } - - Reference<TO, FROM>* getFirst() { return ((Reference<TO, FROM>*) LinkedListHead::getFirst()); } - Reference<TO, FROM> const* getFirst() const { return ((Reference<TO, FROM> const*) LinkedListHead::getFirst()); } - Reference<TO, FROM>* getLast() { return ((Reference<TO, FROM>*) LinkedListHead::getLast()); } - Reference<TO, FROM> const* getLast() const { return ((Reference<TO, FROM> const*) LinkedListHead::getLast()); } - - iterator begin() { return iterator(getFirst()); } - iterator end() { return iterator(NULL); } - iterator rbegin() { return iterator(getLast()); } - iterator rend() { return iterator(NULL); } - - void clearReferences() - { - LinkedListElement* ref; - while((ref = getFirst()) != NULL) - { - ((Reference<TO, FROM>*) ref)->invalidate(); - ref->delink(); // the delink might be already done by invalidate(), but doing it here again does not hurt and insures an empty list - } - } -}; - -//===================================================== -#endif - diff --git a/src/framework/Utilities/LinkedReference/Reference.h b/src/framework/Utilities/LinkedReference/Reference.h deleted file mode 100644 index 4a1545f8f12..00000000000 --- a/src/framework/Utilities/LinkedReference/Reference.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _REFERENCE_H -#define _REFERENCE_H - -#include "Utilities/LinkedList.h" - -//===================================================== - -template <class TO, class FROM> class Reference : public LinkedListElement -{ - private: - TO* iRefTo; - FROM* iRefFrom; - protected: - // Tell our refTo (target) object that we have a link - virtual void targetObjectBuildLink() = 0; - - // Tell our refTo (taget) object, that the link is cut - virtual void targetObjectDestroyLink() = 0; - - // Tell our refFrom (source) object, that the link is cut (Target destroyed) - virtual void sourceObjectDestroyLink() = 0; - public: - Reference() { iRefTo = NULL; iRefFrom = NULL; } - virtual ~Reference() {} - - // Create new link - void link(TO* toObj, FROM* fromObj) - { - assert(fromObj); // fromObj MUST not be NULL - if(isValid()) - unlink(); - if(toObj != NULL) - { - iRefTo = toObj; - iRefFrom = fromObj; - targetObjectBuildLink(); - } - } - - // We don't need the reference anymore. Call comes from the refFrom object - // Tell our refTo object, that the link is cut - void unlink() { targetObjectDestroyLink(); delink(); iRefTo = NULL; iRefFrom = NULL; } - - // Link is invalid due to destruction of referenced target object. Call comes from the refTo object - // Tell our refFrom object, that the link is cut - void invalidate() // the iRefFrom MUST remain!! - { - sourceObjectDestroyLink(); delink(); iRefTo = NULL; - } - - bool isValid() const // Only check the iRefTo - { - return iRefTo != NULL; - } - - Reference<TO,FROM> * next() { return((Reference<TO,FROM> *) LinkedListElement::next()); } - Reference<TO,FROM> const * next() const { return((Reference<TO,FROM> const *) LinkedListElement::next()); } - Reference<TO,FROM> * prev() { return((Reference<TO,FROM> *) LinkedListElement::prev()); } - Reference<TO,FROM> const * prev() const { return((Reference<TO,FROM> const *) LinkedListElement::prev()); } - - Reference<TO,FROM> * nocheck_next() { return((Reference<TO,FROM> *) LinkedListElement::nocheck_next()); } - Reference<TO,FROM> const * nocheck_next() const { return((Reference<TO,FROM> const *) LinkedListElement::nocheck_next()); } - Reference<TO,FROM> * nocheck_prev() { return((Reference<TO,FROM> *) LinkedListElement::nocheck_prev()); } - Reference<TO,FROM> const * nocheck_prev() const { return((Reference<TO,FROM> const *) LinkedListElement::nocheck_prev()); } - - TO* operator ->() const { return iRefTo; } - TO* getTarget() const { return iRefTo; } - - FROM* getSource() const { return iRefFrom; } -}; - -//===================================================== -#endif - diff --git a/src/framework/Utilities/TypeList.h b/src/framework/Utilities/TypeList.h deleted file mode 100644 index 02bc08083c2..00000000000 --- a/src/framework/Utilities/TypeList.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_TYPELIST_H -#define TRINITY_TYPELIST_H - -/* - @struct TypeList - TypeList is the most simple but yet the most powerfull class of all. It holds - at compile time the different type of objects in a linked list. - */ - -class TypeNull; - -template<typename HEAD, typename TAIL> -struct TypeList -{ - typedef HEAD Head; - typedef TAIL Tail; -}; - -// enough for now.. can be expand at any point in time as needed -#define TYPELIST_1(T1) TypeList<T1,TypeNull> -#define TYPELIST_2(T1, T2) TypeList<T1, TYPELIST_1(T2) > -#define TYPELIST_3(T1, T2, T3) TypeList<T1, TYPELIST_2(T2, T3) > -#define TYPELIST_4(T1, T2, T3, T4) TypeList<T1, TYPELIST_3(T2, T3, T4) > -#define TYPELIST_5(T1, T2, T3, T4, T5) TypeList<T1, TYPELIST_4(T2, T3, T4, T5) > -#endif - diff --git a/src/framework/Utilities/UnorderedMap.h b/src/framework/Utilities/UnorderedMap.h deleted file mode 100644 index fce5ec82bfc..00000000000 --- a/src/framework/Utilities/UnorderedMap.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_UNORDERED_MAP_H -#define TRINITY_UNORDERED_MAP_H - -#include "Platform/CompilerDefs.h" -#include "Platform/Define.h" - -#if COMPILER == COMPILER_INTEL -#include <ext/hash_map> -#elif COMPILER == COMPILER_GNU && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 3) -#include <tr1/unordered_map> -#elif COMPILER == COMPILER_GNU && __GNUC__ >= 3 -#include <ext/hash_map> -#elif COMPILER == COMPILER_MICROSOFT && _MSC_VER >= 1500 && _HAS_TR1 // VC9.0 and later -#include <unordered_map> -#else -#include <hash_map> -#endif - -#ifdef _STLPORT_VERSION -#define UNORDERED_MAP std::hash_map -using std::hash_map; -#elif COMPILER == COMPILER_MICROSOFT && _MSC_VER >= 1500 && _HAS_TR1 -#define UNORDERED_MAP std::tr1::unordered_map -#elif COMPILER == COMPILER_MICROSOFT && _MSC_VER >= 1300 -#define UNORDERED_MAP stdext::hash_map -using stdext::hash_map; -#elif COMPILER == COMPILER_INTEL -#define UNORDERED_MAP std::hash_map -using std::hash_map; -#elif COMPILER == COMPILER_GNU && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 3) -#define UNORDERED_MAP std::tr1::unordered_map -#elif COMPILER == COMPILER_GNU && __GNUC__ >= 3 -#define UNORDERED_MAP __gnu_cxx::hash_map - -namespace __gnu_cxx -{ - template<> struct hash<unsigned long long> - { - size_t operator()(const unsigned long long &__x) const { return (size_t)__x; } - }; - template<typename T> struct hash<T *> - { - size_t operator()(T * const &__x) const { return (size_t)__x; } - }; - -}; - -#else -#define UNORDERED_MAP std::hash_map -using std::hash_map; -#endif -#endif - |
