Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,461 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Part of CryEngine's extension framework.
#ifndef CRYINCLUDE_CRYEXTENSION_IMPL_CLASSWEAVER_H
#define CRYINCLUDE_CRYEXTENSION_IMPL_CLASSWEAVER_H
#pragma once
#include "TypeList.h"
#include "Conversion.h"
#include "RegFactoryNode.h"
#include "../ICryUnknown.h"
#include "../ICryFactory.h"
#include <AzCore/Memory/Memory.h>
namespace CW
{
namespace Internal
{
template <class Dst>
struct InterfaceCast;
template <class Dst>
struct InterfaceCast
{
template <class T>
static void* Op(T* p)
{
return (Dst*) p;
}
};
template <>
struct InterfaceCast<ICryUnknown>
{
template <class T>
static void* Op(T* p)
{
return const_cast<ICryUnknown*>(static_cast<const ICryUnknown*>(static_cast<const void*>(p)));
}
};
}
template <class TList>
struct InterfaceCast;
template <>
struct InterfaceCast<TL::NullType>
{
template <class T>
static void* Op(T*, const CryInterfaceID&)
{
return 0;
}
};
template <class Head, class Tail>
struct InterfaceCast<TL::Typelist<Head, Tail> >
{
template <class T>
static void* Op(T* p, const CryInterfaceID& iid)
{
if (cryiidof<Head>() == iid)
{
return Internal::InterfaceCast<Head>::Op(p);
}
return InterfaceCast<Tail>::Op(p, iid);
}
};
template <class TList>
struct FillIIDs;
template <>
struct FillIIDs<TL::NullType>
{
static void Op(CryInterfaceID*)
{
}
};
template <class Head, class Tail>
struct FillIIDs<TL::Typelist<Head, Tail> >
{
static void Op(CryInterfaceID* p)
{
*p++ = cryiidof<Head>();
FillIIDs<Tail>::Op(p);
}
};
namespace Internal
{
template <bool, typename S>
struct PickList;
template <bool, typename S>
struct PickList
{
typedef TL::BuildTypelist<>::Result Result;
};
template <typename S>
struct PickList<true, S>
{
typedef typename S::FullCompositeList Result;
};
}
template <typename T>
struct ProbeFullCompositeList
{
private:
typedef char y[1];
typedef char n[2];
template <typename S>
static y& test(typename S::FullCompositeList*);
template <typename>
static n& test(...);
public:
enum
{
listFound = sizeof(test<T>(0)) == sizeof(y)
};
typedef typename Internal::PickList<listFound, T>::Result ListType;
};
namespace Internal
{
template <class TList>
struct CompositeQuery;
template <>
struct CompositeQuery<TL::NullType>
{
template<typename T>
static void* Op(const T&, const char*)
{
return 0;
}
};
template <class Head, class Tail>
struct CompositeQuery<TL::Typelist<Head, Tail> >
{
template<typename T>
static void* Op(const T& ref, const char* name)
{
void* p = ref.Head::CompositeQueryImpl(name);
return p ? p : CompositeQuery<Tail>::Op(ref, name);
}
};
}
struct CompositeQuery
{
template <typename T>
static void* Op(const T& ref, const char* name)
{
return Internal::CompositeQuery<typename ProbeFullCompositeList<T>::ListType>::Op(ref, name);
}
};
inline bool NameMatch(const char* name, const char* compositeName)
{
if (!name || !compositeName)
{
return false;
}
size_t i = 0;
for (; name[i] && name[i] == compositeName[i]; ++i)
{
}
return name[i] == compositeName[i];
}
template <typename T>
void* CheckCompositeMatch(const char* name, const AZStd::shared_ptr<T>& composite, const char* compositeName)
{
typedef TC::SuperSubClass<ICryUnknown, T> Rel;
COMPILE_TIME_ASSERT(Rel::exists);
return NameMatch(name, compositeName) ? const_cast<void*>(static_cast<const void*>(&composite)) : 0;
}
} // namespace CW
#define CRYINTERFACE_BEGIN() \
private: \
typedef TL::BuildTypelist < ICryUnknown
#define CRYINTERFACE_ADD(iname) , iname
#define CRYINTERFACE_END() > ::Result _UserDefinedPartialInterfaceList; \
protected: \
typedef TL::NoDuplicates<_UserDefinedPartialInterfaceList>::Result FullInterfaceList;
#define _CRY_TPL_APPEND0(base) TL::Append<base::FullInterfaceList, _UserDefinedPartialInterfaceList>::Result
#define _CRY_TPL_APPEND(base, intermediate) TL::Append<base::FullInterfaceList, intermediate>::Result
#define CRYINTERFACE_ENDWITHBASE(base) > ::Result _UserDefinedPartialInterfaceList; \
protected: \
typedef TL::NoDuplicates<_CRY_TPL_APPEND0(base)>::Result FullInterfaceList;
#define CRYINTERFACE_ENDWITHBASE2(base0, base1) > ::Result _UserDefinedPartialInterfaceList; \
protected: \
typedef TL::NoDuplicates<_CRY_TPL_APPEND(base0, _CRY_TPL_APPEND0(base1))>::Result FullInterfaceList;
#define CRYINTERFACE_ENDWITHBASE3(base0, base1, base2) > ::Result _UserDefinedPartialInterfaceList; \
protected: \
typedef TL::NoDuplicates<_CRY_TPL_APPEND(base0, _CRY_TPL_APPEND(base1, _CRY_TPL_APPEND0(base2)))>::Result FullInterfaceList;
#define CRYINTERFACE_SIMPLE(iname) \
CRYINTERFACE_BEGIN() \
CRYINTERFACE_ADD(iname) \
CRYINTERFACE_END()
#define CRYCOMPOSITE_BEGIN() \
private: \
void* CompositeQueryImpl(const char* name) const \
{ \
(void)(name); \
void* res = 0; (void)(res); \
#define CRYCOMPOSITE_ADD(member, membername) \
COMPILE_TIME_ASSERT((sizeof(membername) / sizeof(membername[0])) > 1); \
if ((res = CW::CheckCompositeMatch(name, member, membername)) != 0) { \
return res; }
#define _CRYCOMPOSITE_END(implclassname) \
return 0; \
}; \
protected: \
typedef TL::BuildTypelist<implclassname>::Result _PartialCompositeList; \
\
template <bool, typename S> \
friend struct CW::Internal::PickList;
#define CRYCOMPOSITE_END(implclassname) \
_CRYCOMPOSITE_END(implclassname) \
protected: \
typedef _PartialCompositeList FullCompositeList;
#define _CRYCOMPOSITE_APPEND0(base) TL::Append<_PartialCompositeList, CW::ProbeFullCompositeList<base>::ListType>::Result
#define _CRYCOMPOSITE_APPEND(base, intermediate) TL::Append<intermediate, CW::ProbeFullCompositeList<base>::ListType>::Result
#define CRYCOMPOSITE_ENDWITHBASE(implclassname, base) \
_CRYCOMPOSITE_END(implclassname) \
protected: \
typedef _CRYCOMPOSITE_APPEND0 (base) FullCompositeList;
#define CRYCOMPOSITE_ENDWITHBASE2(implclassname, base0, base1) \
_CRYCOMPOSITE_END(implclassname) \
protected: \
typedef TL::NoDuplicates<_CRYCOMPOSITE_APPEND(base1, _CRYCOMPOSITE_APPEND0(base0))>::Result FullCompositeList;
#define CRYCOMPOSITE_ENDWITHBASE3(implclassname, base0, base1, base2) \
_CRYCOMPOSITE_END(implclassname) \
protected: \
typedef TL::NoDuplicates<_CRYCOMPOSITE_APPEND(base2, _CRYCOMPOSITE_APPEND(base1, _CRYCOMPOSITE_APPEND0(base0)))>::Result FullCompositeList;
template<typename T>
class CFactory
: public ICryFactory
{
public:
virtual const char* GetName() const
{
return T::GetCName();
}
virtual const CryClassID& GetClassID() const
{
return T::GetCID();
}
virtual bool ClassSupports(const CryInterfaceID& iid) const
{
for (size_t i = 0; i < m_numIIDs; ++i)
{
if (iid == m_pIIDs[i])
{
return true;
}
}
return false;
}
virtual void ClassSupports(const CryInterfaceID*& pIIDs, size_t& numIIDs) const
{
pIIDs = m_pIIDs;
numIIDs = m_numIIDs;
}
public:
virtual ICryUnknownPtr CreateClassInstance() const
{
AZStd::shared_ptr<T> p = AZStd::make_shared<T>();
return cryinterface_cast<ICryUnknown> (p);
}
CFactory<T>()
: m_numIIDs(0)
, m_pIIDs(0)
, m_regFactory()
{
static CryInterfaceID supportedIIDs[TL::Length < typename T::FullInterfaceList > ::value];
CW::FillIIDs<typename T::FullInterfaceList>::Op(supportedIIDs);
m_pIIDs = &supportedIIDs[0];
m_numIIDs = TL::Length<typename T::FullInterfaceList>::value;
new(&m_regFactory)SRegFactoryNode(this);
}
protected:
CFactory(const CFactory&);
CFactory& operator =(const CFactory&);
size_t m_numIIDs;
CryInterfaceID* m_pIIDs;
SRegFactoryNode m_regFactory;
};
template<typename T>
class CSingletonFactory
: public CFactory<T>
{
public:
CSingletonFactory()
: CFactory<T>()
, m_csCreateClassInstance()
{
}
virtual ICryUnknownPtr CreateClassInstance() const
{
CryAutoLock<CryCriticalSection> lock(m_csCreateClassInstance);
// override the allocator. These function static instances are being destroyed after the AZ alloctor has been deleted.
// On win, TerminateProcess() prevents these destructors from being called, but that is not the case on OSX.
static typename AZStd::aligned_storage<sizeof(AZStd::Internal::sp_counted_impl_pda<T*, AZStd::Internal::sp_ms_deleter<T>,SingletonAllocator>), AZStd::alignment_of<T>::value>::type m_storage;
static ICryUnknownPtr p = AZStd::allocate_shared<T>(SingletonAllocator(AZStd::addressof(m_storage)));
return p;
}
mutable CryCriticalSection m_csCreateClassInstance;
struct SingletonAllocator
{
SingletonAllocator(void* ptr) :
m_data(ptr)
{}
void* allocate(size_t /*byteSize*/, size_t /*alignment*/, int /*flags*/ = 0)
{
return m_data;
}
void deallocate(void* /*ptr*/, size_t /*byteSize*/, size_t /*alignment*/)
{
// nothing to see here
}
void* m_data;
};
};
#define _CRYFACTORY_DECLARE(implclassname) \
private: \
friend class CFactory<implclassname>; \
static CFactory<implclassname> s_factory;
#define _CRYFACTORY_DECLARE_SINGLETON(implclassname) \
private: \
friend class CFactory<implclassname>; \
friend void* Get##implclassname##Factory(); \
static CSingletonFactory<implclassname> s_factory;
#define _IMPLEMENT_ICRYUNKNOWN() \
public: \
virtual ICryFactory* GetFactory() const \
{ \
return &s_factory; \
} \
\
protected: \
virtual void* QueryInterface(const CryInterfaceID&iid) const \
{ \
return CW::InterfaceCast<FullInterfaceList>::Op(this, iid); \
} \
\
template <class TList> \
friend struct CW::Internal::CompositeQuery; \
\
virtual void* QueryComposite(const char* name) const \
{ \
return CW::CompositeQuery::Op(*this, name); \
}
#define _ENFORCE_CRYFACTORY_USAGE(implclassname, cname, cidHigh, cidLow) \
public: \
static const char* GetCName() \
{ \
return cname; \
} \
static const CryClassID& GetCID() \
{ \
static const CryClassID cid = {(uint64) cidHigh##LL, (uint64) cidLow##LL}; \
return cid; \
} \
static AZStd::shared_ptr<implclassname> CreateClassInstance() \
{ \
ICryUnknownPtr p = s_factory.CreateClassInstance(); \
return AZStd::shared_ptr<implclassname>(*static_cast<AZStd::shared_ptr<implclassname>*>(static_cast<void*>(&p))); \
} \
\
protected: \
implclassname(); \
virtual ~implclassname();
#define _BEFRIEND_OPS() \
_BEFRIEND_CRYINTERFACE_CAST() \
_BEFRIEND_CRYCOMPOSITE_QUERY() \
_BEFRIEND_MAKE_SHARED()
#define CRYGENERATE_CLASS(implclassname, cname, cidHigh, cidLow) \
_CRYFACTORY_DECLARE(implclassname) \
_BEFRIEND_OPS() \
_IMPLEMENT_ICRYUNKNOWN() \
_ENFORCE_CRYFACTORY_USAGE(implclassname, cname, cidHigh, cidLow)
#define CRYGENERATE_SINGLETONCLASS(implclassname, cname, cidHigh, cidLow) \
_CRYFACTORY_DECLARE_SINGLETON(implclassname) \
_BEFRIEND_OPS() \
_IMPLEMENT_ICRYUNKNOWN() \
_ENFORCE_CRYFACTORY_USAGE(implclassname, cname, cidHigh, cidLow)
#define CRYREGISTER_CLASS(implclassname) \
CFactory<implclassname> implclassname::s_factory;
#define DECLARE_CRYREGISTER_SINGLETON_CLASS(implclassname) \
void* Get##implclassname##Factory();
#define CRYREGISTER_SINGLETON_CLASS(implclassname) \
CSingletonFactory<implclassname> implclassname::s_factory; \
void* Get##implclassname##Factory() { \
return &implclassname::s_factory; \
}
#endif // CRYINCLUDE_CRYEXTENSION_IMPL_CLASSWEAVER_H
@@ -0,0 +1,109 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Part of CryEngine's extension framework.
#ifndef CRYINCLUDE_CRYEXTENSION_IMPL_CONVERSION_H
#define CRYINCLUDE_CRYEXTENSION_IMPL_CONVERSION_H
#pragma once
namespace TC
{
//template <class T, class U>
//struct Conversion
//{
//private:
// typedef char y[1];
// typedef char n[2];
// static y& Test(U);
// static n& Test(...);
// static T MakeT();
//public:
// enum
// {
// exists = sizeof(Test(MakeT())) == sizeof(y),
// sameType = false
// };
//};
//template <class T>
//struct Conversion<T, T>
//{
//public:
// enum
// {
// exists = true,
// sameType = true
// };
//};
//template<typename Base, typename Derived>
//struct CheckInheritance
//{
// enum
// {
// exists = Conversion<const Derived*, const Base*>::exists && !Conversion<const Base*, const void*>::sameType
// };
//};
//template<typename Base, typename Derived>
//struct CheckStrictInheritance
//{
// enum
// {
// exists = CheckInheritance<Base, Derived>::exists && !Conversion<const Base*, const Derived*>::sameType
// };
//};
template <typename Base, typename Derived>
struct SuperSubClass
{
private:
typedef char y[1];
typedef char n[2];
template<typename T>
static y& check(const volatile Derived&, T);
static n& check(const volatile Base&, int);
struct C
{
operator const volatile Base&() const;
operator const volatile Derived&();
};
static C getC();
public:
enum
{
exists = sizeof(check(getC(), 0)) == sizeof(y),
sameType = false
};
};
template <typename T>
struct SuperSubClass<T, T>
{
enum
{
exists = true
};
};
} // namespace TC
#endif // CRYINCLUDE_CRYEXTENSION_IMPL_CONVERSION_H
@@ -0,0 +1,67 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Part of CryEngine's extension framework.
#ifndef CRYINCLUDE_CRYEXTENSION_IMPL_CRYGUIDHELPER_H
#define CRYINCLUDE_CRYEXTENSION_IMPL_CRYGUIDHELPER_H
#pragma once
#include "../CryGUID.h"
#include "../../CryString.h"
namespace CryGUIDHelper
{
string Print(const CryGUID& val)
{
char buf[39]; // sizeof("{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}")
static const char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
char* p = buf;
*p++ = '{';
for (int i = 15; i >= 8; --i)
{
*p++ = hex[(unsigned char) ((val.hipart >> (i << 2)) & 0xF)];
}
*p++ = '-';
for (int i = 7; i >= 4; --i)
{
*p++ = hex[(unsigned char) ((val.hipart >> (i << 2)) & 0xF)];
}
*p++ = '-';
for (int i = 3; i >= 0; --i)
{
*p++ = hex[(unsigned char) ((val.hipart >> (i << 2)) & 0xF)];
}
*p++ = '-';
for (int i = 15; i >= 12; --i)
{
*p++ = hex[(unsigned char) ((val.lopart >> (i << 2)) & 0xF)];
}
*p++ = '-';
for (int i = 11; i >= 0; --i)
{
*p++ = hex[(unsigned char) ((val.lopart >> (i << 2)) & 0xF)];
}
*p++ = '}';
*p++ = '\0';
return string(buf);
}
}
#endif // CRYINCLUDE_CRYEXTENSION_IMPL_CRYGUIDHELPER_H
@@ -0,0 +1,58 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Part of CryEngine's extension framework.
#ifndef CRYINCLUDE_CRYEXTENSION_IMPL_ICRYFACTORYREGISTRYIMPL_H
#define CRYINCLUDE_CRYEXTENSION_IMPL_ICRYFACTORYREGISTRYIMPL_H
#pragma once
#include "../ICryFactoryRegistry.h"
struct SRegFactoryNode;
struct ICryFactoryRegistryCallback
{
virtual void OnNotifyFactoryRegistered(ICryFactory* pFactory) = 0;
virtual void OnNotifyFactoryUnregistered(ICryFactory* pFactory) = 0;
protected:
virtual ~ICryFactoryRegistryCallback() {}
};
struct ICryFactoryRegistryImpl
: public ICryFactoryRegistry
{
virtual ICryFactory* GetFactory(const char* cname) const = 0;
virtual ICryFactory* GetFactory(const CryClassID& cid) const = 0;
virtual void IterateFactories(const CryInterfaceID& iid, ICryFactory** pFactories, size_t& numFactories) const = 0;
virtual void RegisterCallback(ICryFactoryRegistryCallback* pCallback) = 0;
virtual void UnregisterCallback(ICryFactoryRegistryCallback* pCallback) = 0;
virtual void RegisterFactories(const SRegFactoryNode* pFactories) = 0;
virtual void UnregisterFactories(const SRegFactoryNode* pFactories) = 0;
virtual void UnregisterFactory(ICryFactory* const pFactory) = 0;
protected:
// prevent explicit destruction from client side (delete, shared_ptr, etc)
virtual ~ICryFactoryRegistryImpl() {}
};
#endif // CRYINCLUDE_CRYEXTENSION_IMPL_ICRYFACTORYREGISTRYIMPL_H
@@ -0,0 +1,52 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Part of CryEngine's extension framework.
#ifndef CRYINCLUDE_CRYEXTENSION_IMPL_REGFACTORYNODE_H
#define CRYINCLUDE_CRYEXTENSION_IMPL_REGFACTORYNODE_H
#pragma once
struct ICryFactory;
struct SRegFactoryNode;
extern SRegFactoryNode* g_pHeadToRegFactories;
struct SRegFactoryNode
{
SRegFactoryNode()
{
}
SRegFactoryNode(ICryFactory* pFactory)
: m_pFactory(pFactory)
, m_pNext(g_pHeadToRegFactories)
{
g_pHeadToRegFactories = this;
}
static void* operator new(size_t, void* p)
{
return p;
}
static void operator delete(void*, void*)
{
}
ICryFactory* m_pFactory;
SRegFactoryNode* m_pNext;
};
#endif // CRYINCLUDE_CRYEXTENSION_IMPL_REGFACTORYNODE_H
@@ -0,0 +1,236 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Part of CryEngine's extension framework.
#ifndef CRYINCLUDE_CRYEXTENSION_TYPELIST_H
#define CRYINCLUDE_CRYEXTENSION_TYPELIST_H
#pragma once
namespace TL
{
// typelist terminator
class NullType
{
};
// structure for typelist generation
template <class T, class U = NullType>
struct Typelist
{
typedef T Head;
typedef U Tail;
};
// helper structure to automatically build typelists containing n types
template
<
typename T0 = NullType, typename T1 = NullType, typename T2 = NullType, typename T3 = NullType, typename T4 = NullType,
typename T5 = NullType, typename T6 = NullType, typename T7 = NullType, typename T8 = NullType, typename T9 = NullType,
typename T10 = NullType, typename T11 = NullType, typename T12 = NullType, typename T13 = NullType, typename T14 = NullType,
typename T15 = NullType, typename T16 = NullType, typename T17 = NullType, typename T18 = NullType, typename T19 = NullType
>
struct BuildTypelist
{
private:
typedef typename BuildTypelist<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19>::Result TailResult;
public:
typedef Typelist<T0, TailResult> Result;
};
template <>
struct BuildTypelist<>
{
typedef NullType Result;
};
// typelist operation : Length
template <class TList>
struct Length;
template <>
struct Length<NullType>
{
enum
{
value = 0
};
};
template <class T, class U>
struct Length<Typelist<T, U> >
{
enum
{
value = 1 + Length<U>::value
};
};
// typelist operation : TypeAt
template <class TList, unsigned int index>
struct TypeAt;
template <class Head, class Tail>
struct TypeAt<Typelist<Head, Tail>, 0>
{
typedef Head Result;
};
template <class Head, class Tail, unsigned int index>
struct TypeAt<Typelist<Head, Tail>, index>
{
typedef typename TypeAt<Tail, index - 1>::Result Result;
};
// typelist operation : IndexOf
template <class TList, class T>
struct IndexOf;
template <class T>
struct IndexOf<NullType, T>
{
enum
{
value = -1
};
};
template <class T, class Tail>
struct IndexOf<Typelist<T, Tail>, T>
{
enum
{
value = 0
};
};
template <class Head, class Tail, class T>
struct IndexOf<Typelist<Head, Tail>, T>
{
private:
enum
{
temp = IndexOf<Tail, T>::value
};
public:
enum
{
value = temp == -1 ? -1 : 1 + temp
};
};
// typelist operation : Append
template <class TList, class T>
struct Append;
template <>
struct Append<NullType, NullType>
{
typedef NullType Result;
};
template <class T>
struct Append<NullType, T>
{
typedef Typelist<T, NullType> Result;
};
template <class Head, class Tail>
struct Append<NullType, Typelist<Head, Tail> >
{
typedef Typelist<Head, Tail> Result;
};
template <class Head, class Tail, class T>
struct Append<Typelist<Head, Tail>, T>
{
typedef Typelist<Head, typename Append<Tail, T>::Result> Result;
};
// typelist operation : Erase
template <class TList, class T>
struct Erase;
template <class T>
struct Erase<NullType, T>
{
typedef NullType Result;
};
template <class T, class Tail>
struct Erase<Typelist<T, Tail>, T>
{
typedef Tail Result;
};
template <class Head, class Tail, class T>
struct Erase<Typelist<Head, Tail>, T>
{
typedef Typelist<Head, typename Erase<Tail, T>::Result> Result;
};
// typelist operation : Erase All
template <class TList, class T>
struct EraseAll;
template <class T>
struct EraseAll<NullType, T>
{
typedef NullType Result;
};
template <class T, class Tail>
struct EraseAll<Typelist<T, Tail>, T>
{
typedef typename EraseAll<Tail, T>::Result Result;
};
template <class Head, class Tail, class T>
struct EraseAll<Typelist<Head, Tail>, T>
{
typedef Typelist<Head, typename EraseAll<Tail, T>::Result> Result;
};
// typelist operation : NoDuplicates
template <class TList>
struct NoDuplicates;
template <>
struct NoDuplicates<NullType>
{
typedef NullType Result;
};
template <class Head, class Tail>
struct NoDuplicates<Typelist<Head, Tail> >
{
private:
typedef typename NoDuplicates<Tail>::Result L1;
typedef typename Erase<L1, Head>::Result L2;
public:
typedef Typelist<Head, L2> Result;
};
} // namespace TL
#endif // CRYINCLUDE_CRYEXTENSION_TYPELIST_H