Big re-organization of repository [W.I.P]

This commit is contained in:
Yehonal
2016-08-11 20:25:27 +02:00
parent c62a72c0a8
commit 0f85ce1c54
3016 changed files with 1271 additions and 1 deletions

View File

@@ -0,0 +1,61 @@
/*
* Copyright (C)
* Copyright (C)
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef TRINITY_FACTORY_HOLDER
#define TRINITY_FACTORY_HOLDER
#include "Define.h"
#include "Dynamic/TypeList.h"
#include "ObjectRegistry.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;
friend class ACE_Singleton<FactoryHolderRegistry, ACE_Null_Mutex>;
typedef ACE_Singleton<FactoryHolderRegistry, ACE_Null_Mutex> 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

View File

@@ -0,0 +1,119 @@
/*
* Copyright (C)
* Copyright (C)
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef TRINITY_HASH_NAMESPACE_H
#define TRINITY_HASH_NAMESPACE_H
#include "Define.h"
#if COMPILER_HAS_CPP11_SUPPORT
# define HASH_NAMESPACE_START namespace std {
# define HASH_NAMESPACE_END }
#elif defined(_STLPORT_VERSION)
# define HASH_NAMESPACE_START namespace std {
# define HASH_NAMESPACE_END }
#elif COMPILER == COMPILER_MICROSOFT && _MSC_VER >= 1600 // VS100
# define HASH_NAMESPACE_START namespace std {
# define HASH_NAMESPACE_END }
#elif COMPILER == COMPILER_MICROSOFT && _MSC_VER >= 1500 && _HAS_TR1
# define HASH_NAMESPACE_START namespace std { namespace tr1 {
# define HASH_NAMESPACE_END } }
#elif COMPILER == COMPILER_MICROSOFT && _MSC_VER >= 1300
# define HASH_NAMESPACE_START namespace stdext {
# define HASH_NAMESPACE_END }
#if !_HAS_TRADITIONAL_STL
#ifndef HASH_NAMESPACE
#define HASH_NAMESPACE
#else
// can be not used by some platforms, so provide fake forward
HASH_NAMESPACE_START
template<class K>
class hash
{
public:
size_t operator() (K const&);
};
HASH_NAMESPACE_END
#endif
#endif
#elif COMPILER == COMPILER_INTEL
# define HASH_NAMESPACE_START namespace std {
# define HASH_NAMESPACE_END }
#elif COMPILER == COMPILER_GNU && defined(__clang__) && defined(_LIBCPP_VERSION)
# define HASH_NAMESPACE_START namespace std {
# define HASH_NAMESPACE_END }
#elif COMPILER == COMPILER_GNU && GCC_VERSION > 40200
# define HASH_NAMESPACE_START namespace std { namespace tr1 {
# define HASH_NAMESPACE_END } }
#elif COMPILER == COMPILER_GNU && GCC_VERSION >= 30000
# define HASH_NAMESPACE_START namespace __gnu_cxx {
# define HASH_NAMESPACE_END }
#include <ext/hash_fun.h>
#include <string>
HASH_NAMESPACE_START
template<>
class hash<unsigned long long>
{
public:
size_t operator()(const unsigned long long &__x) const { return (size_t)__x; }
};
template<typename T>
class hash<T *>
{
public:
size_t operator()(T * const &__x) const { return (size_t)__x; }
};
template<> struct hash<std::string>
{
size_t operator()(const std::string &__x) const
{
return hash<char const*>()(__x.c_str());
}
};
HASH_NAMESPACE_END
#else
# define HASH_NAMESPACE_START namespace std {
# define HASH_NAMESPACE_END }
#endif
#if COMPILER != COMPILER_MICROSOFT
// Visual Studio use non standard hash calculation function, so provide fake forward for other
HASH_NAMESPACE_START
template<class K>
size_t hash_value(K const&);
HASH_NAMESPACE_END
#endif
#endif

View File

@@ -0,0 +1,245 @@
/*
* Copyright (C)
* Copyright (C)
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef _LINKEDLIST
#define _LINKEDLIST
#include "Define.h"
#include <iterator>
//============================================
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(): iSize(0)
{
// create empty list
iFirst.iNext = &iLast;
iLast.iPrev = &iFirst;
}
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)
{
_Ptr = _Right._Ptr;
return *this;
}
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

View File

@@ -0,0 +1,56 @@
/*
* Copyright (C)
* Copyright (C)
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef _REFMANAGER_H
#define _REFMANAGER_H
//=====================================================
#include "Dynamic/LinkedList.h"
#include "Dynamic/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

View File

@@ -0,0 +1,100 @@
/*
* Copyright (C)
* Copyright (C)
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef _REFERENCE_H
#define _REFERENCE_H
#include "Dynamic/LinkedList.h"
#include "Errors.h" // for ASSERT
//=====================================================
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

View File

@@ -0,0 +1,106 @@
/*
* Copyright (C)
* Copyright (C)
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef TRINITY_OBJECTREGISTRY_H
#define TRINITY_OBJECTREGISTRY_H
#include "Define.h"
#include "Dynamic/UnorderedMap.h"
#include <ace/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;
}
ObjectRegistry() { }
~ObjectRegistry()
{
for (typename RegistryMapType::iterator iter=i_registeredObjects.begin(); iter != i_registeredObjects.end(); ++iter)
delete iter->second;
i_registeredObjects.clear();
}
private:
RegistryMapType i_registeredObjects;
};
#endif

View File

@@ -0,0 +1,124 @@
/*
* Copyright (C)
* Copyright (C)
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#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 "Define.h"
#include "Dynamic/TypeList.h"
#include "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

View File

@@ -0,0 +1,113 @@
/*
* Copyright (C)
* Copyright (C)
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#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 "Define.h"
#include "Dynamic/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->AddToGrid(elements._element);
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

View File

@@ -0,0 +1,168 @@
/*
* Copyright (C)
* Copyright (C)
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#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

View File

@@ -0,0 +1,111 @@
/*
* Copyright (C)
* Copyright (C)
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#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 "Define.h"
#include "Dynamic/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

View File

@@ -0,0 +1,44 @@
/*
* Copyright (C)
* Copyright (C)
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#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

View File

@@ -0,0 +1,72 @@
/*
* Copyright (C)
* Copyright (C)
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef TRINITY_UNORDERED_MAP_H
#define TRINITY_UNORDERED_MAP_H
#include "HashNamespace.h"
#if COMPILER_HAS_CPP11_SUPPORT
# include <unordered_map>
#elif COMPILER == COMPILER_INTEL
# include <ext/hash_map>
#elif COMPILER == COMPILER_GNU && defined(__clang__) && defined(_LIBCPP_VERSION)
# include <unordered_map>
#elif COMPILER == COMPILER_GNU && GCC_VERSION > 40200
# include <tr1/unordered_map>
#elif COMPILER == COMPILER_GNU && GCC_VERSION >= 30000
# include <ext/hash_map>
#elif COMPILER == COMPILER_MICROSOFT && ((_MSC_VER >= 1500 && _HAS_TR1) || _MSC_VER >= 1700) // VC9.0 SP1 and later
# include <unordered_map>
#else
# include <hash_map>
#endif
#ifdef _STLPORT_VERSION
# define UNORDERED_MAP std::hash_map
# define UNORDERED_MULTIMAP std::hash_multimap
#elif COMPILER_HAS_CPP11_SUPPORT
# define UNORDERED_MAP std::unordered_map
# define UNORDERED_MULTIMAP std::unordered_multimap
#elif COMPILER == COMPILER_MICROSOFT && _MSC_VER >= 1600 // VS100
# define UNORDERED_MAP std::tr1::unordered_map
# define UNORDERED_MULTIMAP std::tr1::unordered_multimap
#elif COMPILER == COMPILER_MICROSOFT && _MSC_VER >= 1500 && _HAS_TR1
# define UNORDERED_MAP std::tr1::unordered_map
# define UNORDERED_MULTIMAP std::tr1::unordered_multimap
#elif COMPILER == COMPILER_MICROSOFT && _MSC_VER >= 1300
# define UNORDERED_MAP stdext::hash_map
# define UNORDERED_MULTIMAP stdext::hash_multimap
#elif COMPILER == COMPILER_INTEL
# define UNORDERED_MAP std::hash_map
# define UNORDERED_MULTIMAP std::hash_multimap
#elif COMPILER == COMPILER_GNU && defined(__clang__) && defined(_LIBCPP_VERSION)
# define UNORDERED_MAP std::unordered_map
# define UNORDERED_MULTIMAP std::unordered_multimap
#elif COMPILER == COMPILER_GNU && GCC_VERSION > 40200
# define UNORDERED_MAP std::tr1::unordered_map
# define UNORDERED_MULTIMAP std::tr1::unordered_multimap
#elif COMPILER == COMPILER_GNU && GCC_VERSION >= 30000
# define UNORDERED_MAP __gnu_cxx::hash_map
# define UNORDERED_MULTIMAP __gnu_cxx::hash_multimap
#else
# define UNORDERED_MAP std::hash_map
# define UNORDERED_MULTIMAP std::hash_multimap
#endif
#endif

View File

@@ -0,0 +1,66 @@
/*
* Copyright (C)
* Copyright (C)
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef TRINITY_UNORDERED_SET_H
#define TRINITY_UNORDERED_SET_H
#include "HashNamespace.h"
#if COMPILER_HAS_CPP11_SUPPORT
# include <unordered_set>
#elif COMPILER == COMPILER_INTEL
# include <ext/hash_set>
#elif COMPILER == COMPILER_GNU && defined(__clang__) && defined(_LIBCPP_VERSION)
# include <unordered_set>
#elif COMPILER == COMPILER_GNU && GCC_VERSION > 40200
# include <tr1/unordered_set>
#elif COMPILER == COMPILER_GNU && GCC_VERSION >= 30000
# include <ext/hash_set>
#elif COMPILER == COMPILER_MICROSOFT && ((_MSC_VER >= 1500 && _HAS_TR1) || _MSC_VER >= 1700) // VC9.0 SP1 and later
# include <unordered_set>
#else
# include <hash_set>
#endif
#ifdef _STLPORT_VERSION
# define UNORDERED_SET std::hash_set
using std::hash_set;
#elif COMPILER_HAS_CPP11_SUPPORT
# define UNORDERED_SET std::unordered_set
#elif COMPILER == COMPILER_MICROSOFT && _MSC_VER >= 1600 // VS100
# define UNORDERED_SET std::tr1::unordered_set
#elif COMPILER == COMPILER_MICROSOFT && _MSC_VER >= 1500 && _HAS_TR1
# define UNORDERED_SET std::tr1::unordered_set
#elif COMPILER == COMPILER_MICROSOFT && _MSC_VER >= 1300
# define UNORDERED_SET stdext::hash_set
using stdext::hash_set;
#elif COMPILER == COMPILER_INTEL
# define UNORDERED_SET std::hash_set
using std::hash_set;
#elif COMPILER == COMPILER_GNU && defined(__clang__) && defined(_LIBCPP_VERSION)
# define UNORDERED_SET std::unordered_set
#elif COMPILER == COMPILER_GNU && GCC_VERSION > 40200
# define UNORDERED_SET std::tr1::unordered_set
#elif COMPILER == COMPILER_GNU && GCC_VERSION >= 30000
# define UNORDERED_SET __gnu_cxx::hash_set
#else
# define UNORDERED_SET std::hash_set
using std::hash_set;
#endif
#endif