aboutsummaryrefslogtreecommitdiff
path: root/src/framework/Utilities
diff options
context:
space:
mode:
Diffstat (limited to 'src/framework/Utilities')
-rw-r--r--src/framework/Utilities/ByteConverter.h10
-rw-r--r--src/framework/Utilities/Callback.h35
-rw-r--r--src/framework/Utilities/CountedReference/Reference.h17
-rw-r--r--src/framework/Utilities/CountedReference/ReferenceHolder.h3
-rw-r--r--src/framework/Utilities/CountedReference/ReferenceImpl.h13
-rw-r--r--src/framework/Utilities/EventProcessor.cpp13
-rw-r--r--src/framework/Utilities/EventProcessor.h13
-rw-r--r--src/framework/Utilities/LinkedList.h42
-rw-r--r--src/framework/Utilities/LinkedReference/RefManager.h7
-rw-r--r--src/framework/Utilities/LinkedReference/Reference.h15
-rw-r--r--src/framework/Utilities/TypeList.h5
-rw-r--r--src/framework/Utilities/UnorderedMap.h7
12 files changed, 180 insertions, 0 deletions
diff --git a/src/framework/Utilities/ByteConverter.h b/src/framework/Utilities/ByteConverter.h
index 38910abfe4d..d9282c1787d 100644
--- a/src/framework/Utilities/ByteConverter.h
+++ b/src/framework/Utilities/ByteConverter.h
@@ -17,13 +17,17 @@
* 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>
@@ -32,13 +36,16 @@ namespace ByteConverter
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&) { }
@@ -46,11 +53,14 @@ template<typename T> inline void EndianConvertReverse(T&) { }
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
index 959a493944f..28c0931e6e7 100644
--- a/src/framework/Utilities/Callback.h
+++ b/src/framework/Utilities/Callback.h
@@ -17,9 +17,12 @@
* 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 >
@@ -40,6 +43,7 @@ namespace Trinity
_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 >
{
@@ -57,6 +61,7 @@ namespace Trinity
_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 >
{
@@ -73,6 +78,7 @@ namespace Trinity
_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 >
{
@@ -88,6 +94,7 @@ namespace Trinity
_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 >
{
@@ -102,7 +109,9 @@ namespace Trinity
_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
{
@@ -120,6 +129,7 @@ namespace Trinity
_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 >
{
@@ -136,6 +146,7 @@ namespace Trinity
_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 >
{
@@ -151,6 +162,7 @@ namespace Trinity
_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 >
{
@@ -165,6 +177,7 @@ namespace Trinity
_SCallback(_SCallback < ParamType1 > const& cb)
: m_method(cb.m_method), m_param1(cb.m_param1) {}
};
+
template < >
class _SCallback < >
{
@@ -179,7 +192,9 @@ namespace Trinity
: m_method(cb.m_method) {}
};
}
+
/// --------- GENERIC CALLBACKS ----------
+
namespace Trinity
{
class ICallback
@@ -188,6 +203,7 @@ namespace Trinity
virtual void Execute() = 0;
virtual ~ICallback() {}
};
+
template < class CB >
class _ICallback : public CB, public ICallback
{
@@ -195,6 +211,7 @@ namespace Trinity
_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 > >
@@ -205,6 +222,7 @@ namespace Trinity
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 > >
@@ -215,6 +233,7 @@ namespace Trinity
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 > >
@@ -225,6 +244,7 @@ namespace Trinity
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 > >
@@ -235,6 +255,7 @@ namespace Trinity
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 > >
{
@@ -245,8 +266,11 @@ namespace Trinity
: _ICallback< C0 >(C0(object, method)) {}
};
}
+
/// ---------- QUERY CALLBACKS -----------
+
class QueryResult;
+
namespace Trinity
{
class IQueryCallback
@@ -257,6 +281,7 @@ namespace Trinity
virtual void SetResult(QueryResult* result) = 0;
virtual QueryResult* GetResult() = 0;
};
+
template < class CB >
class _IQueryCallback : public CB, public IQueryCallback
{
@@ -266,6 +291,7 @@ namespace Trinity
void SetResult(QueryResult* result) { CB::m_param1 = result; }
QueryResult* GetResult() { return CB::m_param1; }
};
+
template < class Class, typename ParamType1 = void, typename ParamType2 = void, typename ParamType3 = void >
class QueryCallback :
public _IQueryCallback< _Callback < Class, QueryResult*, ParamType1, ParamType2, ParamType3 > >
@@ -276,6 +302,7 @@ namespace Trinity
QueryCallback(Class *object, typename QC3::Method method, QueryResult* 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*, ParamType1, ParamType2 > >
@@ -286,6 +313,7 @@ namespace Trinity
QueryCallback(Class *object, typename QC2::Method method, QueryResult* 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*, ParamType1 > >
@@ -296,6 +324,7 @@ namespace Trinity
QueryCallback(Class *object, typename QC1::Method method, QueryResult* result, ParamType1 param1)
: _IQueryCallback< QC1 >(QC1(object, method, result, param1)) {}
};
+
template < class Class >
class QueryCallback < Class > : public _IQueryCallback< _Callback < Class, QueryResult* > >
{
@@ -305,7 +334,9 @@ namespace Trinity
QueryCallback(Class *object, typename QC0::Method method, QueryResult* result)
: _IQueryCallback< QC0 >(QC0(object, method, result)) {}
};
+
/// ---- Statics ----
+
template < typename ParamType1 = void, typename ParamType2 = void, typename ParamType3 = void >
class SQueryCallback :
public _IQueryCallback< _SCallback < QueryResult*, ParamType1, ParamType2, ParamType3 > >
@@ -316,6 +347,7 @@ namespace Trinity
SQueryCallback(typename QC3::Method method, QueryResult* 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*, ParamType1, ParamType2 > >
@@ -326,6 +358,7 @@ namespace Trinity
SQueryCallback(typename QC2::Method method, QueryResult* result, ParamType1 param1, ParamType2 param2)
: _IQueryCallback< QC2 >(QC2(method, result, param1, param2)) {}
};
+
template < typename ParamType1 >
class SQueryCallback < ParamType1 > :
public _IQueryCallback< _SCallback < QueryResult*, ParamType1 > >
@@ -336,6 +369,7 @@ namespace Trinity
SQueryCallback(typename QC1::Method method, QueryResult* result, ParamType1 param1)
: _IQueryCallback< QC1 >(QC1(method, result, param1)) {}
};
+
template < >
class SQueryCallback < > : public _IQueryCallback< _SCallback < QueryResult* > >
{
@@ -346,5 +380,6 @@ namespace Trinity
: _IQueryCallback< QC0 >(QC0(method, result)) {}
};
}
+
#endif
diff --git a/src/framework/Utilities/CountedReference/Reference.h b/src/framework/Utilities/CountedReference/Reference.h
index 49156178258..1e1083e1a66 100644
--- a/src/framework/Utilities/CountedReference/Reference.h
+++ b/src/framework/Utilities/CountedReference/Reference.h
@@ -17,8 +17,10 @@
* 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
@@ -29,10 +31,12 @@
* 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,
@@ -43,39 +47,52 @@ class TRINITY_DLL_DECL 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;
};
diff --git a/src/framework/Utilities/CountedReference/ReferenceHolder.h b/src/framework/Utilities/CountedReference/ReferenceHolder.h
index 80576a8700d..4cfb7d16ded 100644
--- a/src/framework/Utilities/CountedReference/ReferenceHolder.h
+++ b/src/framework/Utilities/CountedReference/ReferenceHolder.h
@@ -17,12 +17,15 @@
* 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,
diff --git a/src/framework/Utilities/CountedReference/ReferenceImpl.h b/src/framework/Utilities/CountedReference/ReferenceImpl.h
index 22c31021bd8..c3116a21cf4 100644
--- a/src/framework/Utilities/CountedReference/ReferenceImpl.h
+++ b/src/framework/Utilities/CountedReference/ReferenceImpl.h
@@ -17,9 +17,12 @@
* 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,
@@ -34,6 +37,7 @@ Referencer<T, THREADING_MODEL>::Referencer(T *ref)
++i_holder->i_referenceCount;
}
}
+
template
<
typename T,
@@ -45,6 +49,7 @@ Referencer<T, THREADING_MODEL>::~Referencer()
deReference(i_holder);
i_holder = NULL;
}
+
template
<
typename T,
@@ -60,6 +65,7 @@ Referencer<T, THREADING_MODEL>::operator=(const Referencer<T, THREADING_MODEL> &
i_holder = obj.i_holder;
return *this;
}
+
template
<
typename T,
@@ -76,8 +82,10 @@ Referencer<T, THREADING_MODEL>::operator=(T *ref)
i_holder = new ReferenceeHolder(ref);
++i_holder->i_referenceCount;
}
+
return *this;
}
+
template
<
typename T,
@@ -88,21 +96,25 @@ Referencer<T, THREADING_MODEL>::deReference(ReferenceHolder<T, THREADING_MODEL>
{
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,
@@ -114,6 +126,7 @@ Referencer<T, THREADING_MODEL>::addReference(ReferenceHolder<T, THREADING_MODEL>
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
index 75cc5776602..852f84bc4e2 100644
--- a/src/framework/Utilities/EventProcessor.cpp
+++ b/src/framework/Utilities/EventProcessor.cpp
@@ -17,20 +17,25 @@
* 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)
@@ -38,6 +43,7 @@ void EventProcessor::Update(uint32 p_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))
@@ -53,34 +59,41 @@ void EventProcessor::Update(uint32 p_time)
}
}
}
+
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
index ef33fb1ce9a..d0a98c80e30 100644
--- a/src/framework/Utilities/EventProcessor.h
+++ b/src/framework/Utilities/EventProcessor.h
@@ -17,11 +17,16 @@
* 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:
@@ -29,24 +34,32 @@ class BasicEvent
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);
diff --git a/src/framework/Utilities/LinkedList.h b/src/framework/Utilities/LinkedList.h
index 0d10d6a0121..171ff3601e3 100644
--- a/src/framework/Utilities/LinkedList.h
+++ b/src/framework/Utilities/LinkedList.h
@@ -17,31 +17,40 @@
* 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 != NULL); }
bool hasPrev() const { return(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())
@@ -49,6 +58,7 @@ class LinkedListElement
iNext->iPrev = iPrev; iPrev->iNext = iNext; iNext = NULL; iPrev = NULL;
}
}
+
void insertBefore(LinkedListElement* pElem)
{
pElem->iNext = this;
@@ -56,6 +66,7 @@ class LinkedListElement
iPrev->iNext = pElem;
iPrev = pElem;
}
+
void insertAfter(LinkedListElement* pElem)
{
pElem->iPrev = this;
@@ -64,7 +75,9 @@ class LinkedListElement
iNext = pElem;
}
};
+
//============================================
+
class LinkedListHead
{
private:
@@ -75,23 +88,30 @@ class LinkedListHead
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)
@@ -108,8 +128,10 @@ class LinkedListHead
else
return iSize;
}
+
void incSize() { ++iSize; }
void decSize() { --iSize; }
+
template<class _Ty>
class Iterator
{
@@ -123,85 +145,105 @@ class LinkedListHead
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
index 819e7775bf6..ed580f49ec2 100644
--- a/src/framework/Utilities/LinkedReference/RefManager.h
+++ b/src/framework/Utilities/LinkedReference/RefManager.h
@@ -17,25 +17,31 @@
* 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;
@@ -46,6 +52,7 @@ template <class TO, class FROM> class RefManager : public LinkedListHead
}
}
};
+
//=====================================================
#endif
diff --git a/src/framework/Utilities/LinkedReference/Reference.h b/src/framework/Utilities/LinkedReference/Reference.h
index 7ac5bd4ef3d..c77d3a2cbdb 100644
--- a/src/framework/Utilities/LinkedReference/Reference.h
+++ b/src/framework/Utilities/LinkedReference/Reference.h
@@ -17,10 +17,14 @@
* 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:
@@ -29,13 +33,16 @@ template <class TO, class FROM> class Reference : public LinkedListElement
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)
{
@@ -49,31 +56,39 @@ template <class TO, class FROM> class Reference : public LinkedListElement
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
index e1f888e1afe..07b1ebad3e6 100644
--- a/src/framework/Utilities/TypeList.h
+++ b/src/framework/Utilities/TypeList.h
@@ -17,20 +17,25 @@
* 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) >
diff --git a/src/framework/Utilities/UnorderedMap.h b/src/framework/Utilities/UnorderedMap.h
index a93300b197e..dd539cc0bda 100644
--- a/src/framework/Utilities/UnorderedMap.h
+++ b/src/framework/Utilities/UnorderedMap.h
@@ -17,10 +17,13 @@
* 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)
@@ -32,6 +35,7 @@
#else
#include <hash_map>
#endif
+
#ifdef _STLPORT_VERSION
#define UNORDERED_MAP std::hash_map
using std::hash_map;
@@ -47,6 +51,7 @@ using std::hash_map;
#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>
@@ -57,7 +62,9 @@ namespace __gnu_cxx
{
size_t operator()(T * const &__x) const { return (size_t)__x; }
};
+
};
+
#else
#define UNORDERED_MAP std::hash_map
using std::hash_map;