mirror of
https://github.com/mangosfour/server.git
synced 2025-12-30 10:37:12 +00:00
[Sync] Some project sync
This commit is contained in:
parent
b25fa433fe
commit
bbf0020c1a
98 changed files with 5866 additions and 2121 deletions
|
|
@ -25,26 +25,47 @@
|
|||
#ifndef MANGOS_BYTECONVERTER_H
|
||||
#define MANGOS_BYTECONVERTER_H
|
||||
|
||||
/** ByteConverter reverse your byte order. This is use
|
||||
for cross platform where they have different endians.
|
||||
/**
|
||||
* ByteConverter reverse your byte order. This is used for cross platform
|
||||
* where they have different endians.
|
||||
*/
|
||||
|
||||
#include <Platform/Define.h>
|
||||
#include "Platform/Define.h"
|
||||
#include <algorithm>
|
||||
|
||||
namespace ByteConverter
|
||||
{
|
||||
template<size_t T>
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param val
|
||||
*/
|
||||
inline void convert(char* val)
|
||||
{
|
||||
std::swap(*val, *(val + T - 1));
|
||||
convert < T - 2 > (val + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param
|
||||
*/
|
||||
template<> inline void convert<0>(char*) {}
|
||||
template<> inline void convert<1>(char*) {} // ignore central byte
|
||||
/**
|
||||
* @brief ignore central byte
|
||||
*
|
||||
* @param
|
||||
*/
|
||||
template<> inline void convert<1>(char*) {}
|
||||
|
||||
template<typename T>
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param val
|
||||
*/
|
||||
inline void apply(T* val)
|
||||
{
|
||||
convert<sizeof(T)>((char*)(val));
|
||||
|
|
@ -52,19 +73,59 @@ namespace ByteConverter
|
|||
}
|
||||
|
||||
#if MANGOS_ENDIAN == MANGOS_BIGENDIAN
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param val
|
||||
*/
|
||||
template<typename T> inline void EndianConvert(T& val) { ByteConverter::apply<T>(&val); }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param
|
||||
*/
|
||||
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
|
||||
/**
|
||||
* @brief will generate link error
|
||||
*
|
||||
* @param
|
||||
*/
|
||||
template<typename T> void EndianConvert(T*);
|
||||
/**
|
||||
* @brief will generate link error
|
||||
*
|
||||
* @param
|
||||
*/
|
||||
template<typename T> void EndianConvertReverse(T*);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param
|
||||
*/
|
||||
inline void EndianConvert(uint8&) { }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param
|
||||
*/
|
||||
inline void EndianConvert(int8&) { }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param
|
||||
*/
|
||||
inline void EndianConvertReverse(uint8&) { }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param
|
||||
*/
|
||||
inline void EndianConvertReverse(int8&) { }
|
||||
|
||||
#endif
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -82,19 +82,19 @@ void EventProcessor::KillAllEvents(bool force)
|
|||
delete i_old->second;
|
||||
|
||||
if (!force) // need per-element cleanup
|
||||
m_events.erase(i_old);
|
||||
{ m_events.erase(i_old); }
|
||||
}
|
||||
}
|
||||
|
||||
// fast clear event list (in force case)
|
||||
if (force)
|
||||
m_events.clear();
|
||||
{ m_events.clear(); }
|
||||
}
|
||||
|
||||
void EventProcessor::AddEvent(BasicEvent* Event, uint64 e_time, bool set_addtime)
|
||||
{
|
||||
if (set_addtime)
|
||||
Event->m_addTime = m_time;
|
||||
{ Event->m_addTime = m_time; }
|
||||
|
||||
Event->m_execTime = e_time;
|
||||
m_events.insert(std::pair<uint64, BasicEvent*>(e_time, Event));
|
||||
|
|
|
|||
|
|
@ -22,64 +22,127 @@
|
|||
* and lore are copyrighted by Blizzard Entertainment, Inc.
|
||||
*/
|
||||
|
||||
#ifndef __EVENTPROCESSOR_H
|
||||
#define __EVENTPROCESSOR_H
|
||||
#ifndef MANGOS_H_EVENTPROCESSOR
|
||||
#define MANGOS_H_EVENTPROCESSOR
|
||||
|
||||
#include "Platform/Define.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
// Note. All times are in milliseconds here.
|
||||
|
||||
/**
|
||||
* @brief Note. All times are in milliseconds here.
|
||||
*
|
||||
*/
|
||||
class BasicEvent
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
BasicEvent()
|
||||
: to_Abort(false)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~BasicEvent() // override destructor to perform some actions on event removal
|
||||
/**
|
||||
* @brief override destructor to perform some actions on event removal
|
||||
*
|
||||
*/
|
||||
virtual ~BasicEvent()
|
||||
{
|
||||
};
|
||||
|
||||
// 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
|
||||
|
||||
/**
|
||||
* @brief this method executes when the event is triggered
|
||||
*
|
||||
* @param uint64 e_time is execution time
|
||||
* @param uint32 p_time is update interval
|
||||
* @return bool return false if event does not want to be deleted
|
||||
*/
|
||||
virtual bool Execute(uint64 /*e_time*/, uint32 /*p_time*/) { return true; }
|
||||
|
||||
virtual bool IsDeletable() const { return true; } // this event can be safely deleted
|
||||
/**
|
||||
* @brief this event can be safely deleted
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
virtual bool IsDeletable() const { return true; }
|
||||
|
||||
virtual void Abort(uint64 /*e_time*/) {} // this method executes when the event is aborted
|
||||
/**
|
||||
* @brief this method executes when the event is aborted
|
||||
*
|
||||
* @param uint64
|
||||
*/
|
||||
virtual void Abort(uint64 /*e_time*/) {}
|
||||
|
||||
bool to_Abort; // set by externals when the event is aborted, aborted events don't execute
|
||||
// and get Abort call when deleted
|
||||
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
|
||||
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 */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
typedef std::multimap<uint64, BasicEvent*> EventList;
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
class EventProcessor
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
EventProcessor();
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
~EventProcessor();
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param p_time
|
||||
*/
|
||||
void Update(uint32 p_time);
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param force
|
||||
*/
|
||||
void KillAllEvents(bool force);
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param Event
|
||||
* @param e_time
|
||||
* @param set_addtime
|
||||
*/
|
||||
void AddEvent(BasicEvent* Event, uint64 e_time, bool set_addtime = true);
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param t_offset
|
||||
* @return uint64
|
||||
*/
|
||||
uint64 CalculateTime(uint64 t_offset);
|
||||
|
||||
protected:
|
||||
|
||||
uint64 m_time;
|
||||
EventList m_events;
|
||||
bool m_aborting;
|
||||
uint64 m_time; /**< TODO */
|
||||
EventList m_events; /**< TODO */
|
||||
bool m_aborting; /**< TODO */
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -30,34 +30,105 @@
|
|||
//============================================
|
||||
class LinkedListHead;
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
class LinkedListElement
|
||||
{
|
||||
private:
|
||||
|
||||
friend class LinkedListHead;
|
||||
|
||||
LinkedListElement* iNext;
|
||||
LinkedListElement* iPrev;
|
||||
LinkedListElement* iNext; /**< TODO */
|
||||
LinkedListElement* iPrev; /**< TODO */
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
LinkedListElement() { iNext = NULL; iPrev = NULL; }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
~LinkedListElement() { delink(); }
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
bool hasNext() const { return (iNext->iNext != NULL); }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
bool hasPrev() const { return (iPrev->iPrev != NULL); }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
bool isInList() const { return (iNext != NULL && iPrev != NULL); }
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return LinkedListElement
|
||||
*/
|
||||
LinkedListElement* next() { return hasNext() ? iNext : NULL; }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return const LinkedListElement
|
||||
*/
|
||||
LinkedListElement const* next() const { return hasNext() ? iNext : NULL; }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return LinkedListElement
|
||||
*/
|
||||
LinkedListElement* prev() { return hasPrev() ? iPrev : NULL; }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return const LinkedListElement
|
||||
*/
|
||||
LinkedListElement const* prev() const { return hasPrev() ? iPrev : NULL; }
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return LinkedListElement
|
||||
*/
|
||||
LinkedListElement* nocheck_next() { return iNext; }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return const LinkedListElement
|
||||
*/
|
||||
LinkedListElement const* nocheck_next() const { return iNext; }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return LinkedListElement
|
||||
*/
|
||||
LinkedListElement* nocheck_prev() { return iPrev; }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return const LinkedListElement
|
||||
*/
|
||||
LinkedListElement const* nocheck_prev() const { return iPrev; }
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
void delink()
|
||||
{
|
||||
if (isInList())
|
||||
|
|
@ -69,6 +140,11 @@ class LinkedListElement
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param pElem
|
||||
*/
|
||||
void insertBefore(LinkedListElement* pElem)
|
||||
{
|
||||
pElem->iNext = this;
|
||||
|
|
@ -77,6 +153,11 @@ class LinkedListElement
|
|||
iPrev = pElem;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param pElem
|
||||
*/
|
||||
void insertAfter(LinkedListElement* pElem)
|
||||
{
|
||||
pElem->iPrev = this;
|
||||
|
|
@ -88,16 +169,24 @@ class LinkedListElement
|
|||
|
||||
//============================================
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
class LinkedListHead
|
||||
{
|
||||
private:
|
||||
|
||||
LinkedListElement iFirst;
|
||||
LinkedListElement iLast;
|
||||
uint32 iSize;
|
||||
LinkedListElement iFirst; /**< TODO */
|
||||
LinkedListElement iLast; /**< TODO */
|
||||
uint32 iSize; /**< TODO */
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
LinkedListHead()
|
||||
{
|
||||
// create empty list
|
||||
|
|
@ -107,24 +196,64 @@ class LinkedListHead
|
|||
iSize = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
bool isEmpty() const { return (!iFirst.iNext->isInList()); }
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return LinkedListElement
|
||||
*/
|
||||
LinkedListElement* getFirst() { return (isEmpty() ? NULL : iFirst.iNext); }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return const LinkedListElement
|
||||
*/
|
||||
LinkedListElement const* getFirst() const { return (isEmpty() ? NULL : iFirst.iNext); }
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return LinkedListElement
|
||||
*/
|
||||
LinkedListElement* getLast() { return (isEmpty() ? NULL : iLast.iPrev); }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return const LinkedListElement
|
||||
*/
|
||||
LinkedListElement const* getLast() const { return (isEmpty() ? NULL : iLast.iPrev); }
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param pElem
|
||||
*/
|
||||
void insertFirst(LinkedListElement* pElem)
|
||||
{
|
||||
iFirst.insertAfter(pElem);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param pElem
|
||||
*/
|
||||
void insertLast(LinkedListElement* pElem)
|
||||
{
|
||||
iLast.insertBefore(pElem);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return uint32
|
||||
*/
|
||||
uint32 getSize() const
|
||||
{
|
||||
if (!iSize)
|
||||
|
|
@ -141,62 +270,141 @@ class LinkedListHead
|
|||
return result;
|
||||
}
|
||||
else
|
||||
return iSize;
|
||||
{ return iSize; }
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
void incSize() { ++iSize; }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
void decSize() { --iSize; }
|
||||
|
||||
template<class _Ty>
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
class Iterator
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
typedef std::bidirectional_iterator_tag iterator_category;
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
typedef _Ty value_type;
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
typedef ptrdiff_t difference_type;
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
typedef ptrdiff_t distance_type;
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
typedef _Ty* pointer;
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
typedef _Ty const* const_pointer;
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
typedef _Ty& reference;
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
typedef _Ty const& const_reference;
|
||||
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
Iterator()
|
||||
: _Ptr(0)
|
||||
{
|
||||
// construct with null node pointer
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param _Pnode
|
||||
*/
|
||||
Iterator(pointer _Pnode)
|
||||
: _Ptr(_Pnode)
|
||||
{
|
||||
// construct with node pointer _Pnode
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param _Right
|
||||
* @return Iterator &operator
|
||||
*/
|
||||
Iterator& operator=(Iterator const& _Right)
|
||||
{
|
||||
return (*this) = _Right._Ptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param _Right
|
||||
* @return Iterator &operator
|
||||
*/
|
||||
Iterator& operator=(const_pointer const& _Right)
|
||||
{
|
||||
_Ptr = (pointer)_Right;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return reference operator
|
||||
*/
|
||||
reference operator*()
|
||||
{
|
||||
// return designated value
|
||||
return *_Ptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return pointer operator ->
|
||||
*/
|
||||
pointer operator->()
|
||||
{
|
||||
// return pointer to class object
|
||||
return _Ptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return Iterator &operator
|
||||
*/
|
||||
Iterator& operator++()
|
||||
{
|
||||
// preincrement
|
||||
|
|
@ -204,6 +412,12 @@ class LinkedListHead
|
|||
return (*this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param int
|
||||
* @return Iterator operator
|
||||
*/
|
||||
Iterator operator++(int)
|
||||
{
|
||||
// postincrement
|
||||
|
|
@ -212,6 +426,11 @@ class LinkedListHead
|
|||
return (_Tmp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return Iterator &operator
|
||||
*/
|
||||
Iterator& operator--()
|
||||
{
|
||||
// predecrement
|
||||
|
|
@ -219,6 +438,12 @@ class LinkedListHead
|
|||
return (*this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param int
|
||||
* @return Iterator operator
|
||||
*/
|
||||
Iterator operator--(int)
|
||||
{
|
||||
// postdecrement
|
||||
|
|
@ -227,42 +452,83 @@ class LinkedListHead
|
|||
return (_Tmp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param _Right
|
||||
* @return bool operator
|
||||
*/
|
||||
bool operator==(Iterator const& _Right) const
|
||||
{
|
||||
// test for iterator equality
|
||||
return (_Ptr == _Right._Ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param _Right
|
||||
* @return bool operator
|
||||
*/
|
||||
bool operator!=(Iterator const& _Right) const
|
||||
{
|
||||
// test for iterator inequality
|
||||
return (!(*this == _Right));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param _Right
|
||||
* @return bool operator
|
||||
*/
|
||||
bool operator==(pointer const& _Right) const
|
||||
{
|
||||
// test for pointer equality
|
||||
return (_Ptr != _Right);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param _Right
|
||||
* @return bool operator
|
||||
*/
|
||||
bool operator!=(pointer const& _Right) const
|
||||
{
|
||||
// test for pointer equality
|
||||
return (!(*this == _Right));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param _Right
|
||||
* @return bool operator
|
||||
*/
|
||||
bool operator==(const_reference _Right) const
|
||||
{
|
||||
// test for reference equality
|
||||
return (_Ptr == &_Right);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param _Right
|
||||
* @return bool operator
|
||||
*/
|
||||
bool operator!=(const_reference _Right) const
|
||||
{
|
||||
// test for reference equality
|
||||
return (_Ptr != &_Right);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return pointer
|
||||
*/
|
||||
pointer _Mynode()
|
||||
{
|
||||
// return node pointer
|
||||
|
|
@ -271,9 +537,13 @@ class LinkedListHead
|
|||
|
||||
protected:
|
||||
|
||||
pointer _Ptr; // pointer to node
|
||||
pointer _Ptr; /**< pointer to node */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
typedef Iterator<LinkedListElement> iterator;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@
|
|||
* and lore are copyrighted by Blizzard Entertainment, Inc.
|
||||
*/
|
||||
|
||||
#ifndef _REFMANAGER_H
|
||||
#define _REFMANAGER_H
|
||||
#ifndef MANGOS_H_REFMANAGER
|
||||
#define MANGOS_H_REFMANAGER
|
||||
|
||||
//=====================================================
|
||||
|
||||
|
|
@ -31,24 +31,84 @@
|
|||
#include "Utilities/LinkedReference/Reference.h"
|
||||
|
||||
template <class TO, class FROM>
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
class RefManager : public LinkedListHead
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
typedef LinkedListHead::Iterator<Reference<TO, FROM> > iterator;
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
RefManager() {}
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
virtual ~RefManager() { clearReferences(); }
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return Reference<TO, FROM>
|
||||
*/
|
||||
Reference<TO, FROM>* getFirst() { return ((Reference<TO, FROM>*) LinkedListHead::getFirst()); }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return const Reference<TO, FROM>
|
||||
*/
|
||||
Reference<TO, FROM> const* getFirst() const { return ((Reference<TO, FROM> const*) LinkedListHead::getFirst()); }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return Reference<TO, FROM>
|
||||
*/
|
||||
Reference<TO, FROM>* getLast() { return ((Reference<TO, FROM>*) LinkedListHead::getLast()); }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return const Reference<TO, FROM>
|
||||
*/
|
||||
Reference<TO, FROM> const* getLast() const { return ((Reference<TO, FROM> const*) LinkedListHead::getLast()); }
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return iterator
|
||||
*/
|
||||
iterator begin() { return iterator(getFirst()); }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return iterator
|
||||
*/
|
||||
iterator end() { return iterator(NULL); }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return iterator
|
||||
*/
|
||||
iterator rbegin() { return iterator(getLast()); }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return iterator
|
||||
*/
|
||||
iterator rend() { return iterator(NULL); }
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
void clearReferences()
|
||||
{
|
||||
LinkedListElement* ref;
|
||||
|
|
|
|||
|
|
@ -22,47 +22,73 @@
|
|||
* and lore are copyrighted by Blizzard Entertainment, Inc.
|
||||
*/
|
||||
|
||||
#ifndef _REFERENCE_H
|
||||
#define _REFERENCE_H
|
||||
#ifndef MANGOS_H_REFERENCE
|
||||
#define MANGOS_H_REFERENCE
|
||||
|
||||
#include "Utilities/LinkedList.h"
|
||||
|
||||
//=====================================================
|
||||
|
||||
template<class TO, class FROM>
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
class Reference : public LinkedListElement
|
||||
{
|
||||
private:
|
||||
|
||||
TO* iRefTo;
|
||||
FROM* iRefFrom;
|
||||
TO* iRefTo; /**< TODO */
|
||||
FROM* iRefFrom; /**< TODO */
|
||||
|
||||
protected:
|
||||
|
||||
// Tell our refTo (target) object that we have a link
|
||||
/**
|
||||
* @brief Tell our refTo (target) object that we have a link
|
||||
*
|
||||
*/
|
||||
virtual void targetObjectBuildLink() = 0;
|
||||
|
||||
// Tell our refTo (taget) object, that the link is cut
|
||||
/**
|
||||
* @brief 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)
|
||||
/**
|
||||
* @brief Tell our refFrom (source) object, that the link is cut (Target destroyed)
|
||||
*
|
||||
*/
|
||||
virtual void sourceObjectDestroyLink() = 0;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
Reference()
|
||||
: iRefTo(NULL), iRefFrom(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
virtual ~Reference() {}
|
||||
|
||||
// Create new link
|
||||
/**
|
||||
* @brief Create new link
|
||||
*
|
||||
* @param toObj
|
||||
* @param fromObj
|
||||
*/
|
||||
void link(TO* toObj, FROM* fromObj)
|
||||
{
|
||||
assert(fromObj); // fromObj MUST not be NULL
|
||||
if (isValid())
|
||||
unlink();
|
||||
{ unlink(); }
|
||||
|
||||
if (toObj != NULL)
|
||||
{
|
||||
|
|
@ -72,8 +98,13 @@ class Reference : public LinkedListElement
|
|||
}
|
||||
}
|
||||
|
||||
// We don't need the reference anymore. Call comes from the refFrom object
|
||||
// Tell our refTo object, that the link is cut
|
||||
/**
|
||||
* @brief 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();
|
||||
|
|
@ -82,8 +113,13 @@ class Reference : public LinkedListElement
|
|||
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
|
||||
/**
|
||||
* @brief 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();
|
||||
|
|
@ -91,24 +127,84 @@ class Reference : public LinkedListElement
|
|||
iRefTo = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
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()); }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return Reference<TO, FROM>
|
||||
*/
|
||||
Reference<TO, FROM>* next() { return((Reference<TO, FROM>*) LinkedListElement::next()); }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return const Reference<TO, FROM>
|
||||
*/
|
||||
Reference<TO, FROM> const* next() const { return((Reference<TO, FROM> const*) LinkedListElement::next()); }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return Reference<TO, FROM>
|
||||
*/
|
||||
Reference<TO, FROM>* prev() { return((Reference<TO, FROM>*) LinkedListElement::prev()); }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return const Reference<TO, FROM>
|
||||
*/
|
||||
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()); }
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return Reference<TO, FROM>
|
||||
*/
|
||||
Reference<TO, FROM>* nocheck_next() { return((Reference<TO, FROM>*) LinkedListElement::nocheck_next()); }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return const Reference<TO, FROM>
|
||||
*/
|
||||
Reference<TO, FROM> const* nocheck_next() const { return((Reference<TO, FROM> const*) LinkedListElement::nocheck_next()); }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return Reference<TO, FROM>
|
||||
*/
|
||||
Reference<TO, FROM>* nocheck_prev() { return((Reference<TO, FROM>*) LinkedListElement::nocheck_prev()); }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return const Reference<TO, FROM>
|
||||
*/
|
||||
Reference<TO, FROM> const* nocheck_prev() const { return((Reference<TO, FROM> const*) LinkedListElement::nocheck_prev()); }
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return TO *operator ->
|
||||
*/
|
||||
TO* operator->() const { return iRefTo; }
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return TO
|
||||
*/
|
||||
TO* getTarget() const { return iRefTo; }
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return FROM
|
||||
*/
|
||||
FROM* getSource() const { return iRefFrom; }
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -25,18 +25,26 @@
|
|||
#ifndef MANGOS_TYPELIST_H
|
||||
#define MANGOS_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>
|
||||
/**
|
||||
* @brief 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.
|
||||
*
|
||||
*/
|
||||
struct TypeList
|
||||
{
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
typedef HEAD Head;
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
typedef TAIL Tail;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -96,9 +96,14 @@ HASH_NAMESPACE_END
|
|||
# define HASH_NAMESPACE_END }
|
||||
using std::hash_map;
|
||||
using std::hash_set;
|
||||
#elif COMPILER == COMPILER_CLANG
|
||||
#elif COMPILER == COMPILER_CLANG && defined(__FreeBSD__)
|
||||
# define UNORDERED_MAP std::unordered_map
|
||||
# define UNORDERED_SET std::unordered_set
|
||||
# define HASH_NAMESPACE_START namespace std { namespace __1 {
|
||||
# define HASH_NAMESPACE_END } }
|
||||
#elif COMPILER == COMPILER_CLANG
|
||||
# define UNORDERED_MAP std::tr1::unordered_map
|
||||
# define UNORDERED_SET std::tr1::unordered_set
|
||||
# define HASH_NAMESPACE_START namespace std { namespace tr1 {
|
||||
# define HASH_NAMESPACE_END } }
|
||||
#elif COMPILER == COMPILER_GNU && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 3)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue