Skip to content

Commit

Permalink
Eradicate recursive CRTPs.
Browse files Browse the repository at this point in the history
  • Loading branch information
nitrocaster committed Dec 10, 2015
1 parent 1bd9621 commit 822594a
Show file tree
Hide file tree
Showing 22 changed files with 217 additions and 245 deletions.
52 changes: 23 additions & 29 deletions src/xrAICore/Navigation/a_star.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,43 @@
#include "xrAICore/Navigation/data_storage_constructor.h"
#include "xrAICore/Navigation/dijkstra.h"

namespace AStar {
template <
typename _dist_type,
template <typename _T> class T1
>
struct _Vertex {
template <typename T2>
struct _vertex : public T1<T2> {
typedef _dist_type _dist_type;

_dist_type _g;
_dist_type _h;
namespace AStar
{
template<typename _dist_type>
struct ByDistType
{
template<typename TCompoundVertex>
struct VertexData :
Dijkstra::template ByDistType<_dist_type>::template VertexData<TCompoundVertex>
{
typedef _dist_type _dist_type;

IC _dist_type &g()
{
return (_g);
}
_dist_type _g;
_dist_type _h;

IC _dist_type &h()
{
return (_h);
}
};
_dist_type &g() { return _g; }
_dist_type &h() { return _h; }
};
};
}

template <
typename _dist_type,
typename _priority_queue,
typename _vertex_manager,
typename _vertex_allocator,
typename TCompoundVertex = EmptyVertexData,
bool euclidian_heuristics = true,
typename _data_storage_base = CVertexPath<euclidian_heuristics>,
template <typename _T> class _vertex = CEmptyClassTemplate,
typename _iteration_type = u32
> class CAStar : public CDijkstra <
> class CAStar : public CDijkstra<
_dist_type,
_priority_queue,
_vertex_manager,
_vertex_allocator,
TCompoundVertex,
euclidian_heuristics,
_data_storage_base,
AStar::_Vertex<_dist_type,_vertex>::_vertex,
_iteration_type
>
{
Expand All @@ -64,14 +58,14 @@ template <
_priority_queue,
_vertex_manager,
_vertex_allocator,
TCompoundVertex,
euclidian_heuristics,
_data_storage_base,
AStar::_Vertex<_dist_type,_vertex>::_vertex,
_iteration_type
> inherited;
typedef typename CDataStorage::CGraphVertex CGraphVertex;
typedef typename CGraphVertex::_dist_type _dist_type;
typedef typename CGraphVertex::_index_type _index_type;
> inherited;
typedef TCompoundVertex CGraphVertex;
typedef typename CGraphVertex::_dist_type _dist_type;
typedef typename CGraphVertex::_index_type _index_type;

protected:
template <typename _PathManager>
Expand Down
4 changes: 2 additions & 2 deletions src/xrAICore/Navigation/a_star_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
typename _priority_queue,\
typename _vertex_manager,\
typename _vertex_allocator,\
typename TCompoundVertex,\
bool euclidian_heuristics,\
typename _data_storage_base,\
template <typename _T> class _vertex,\
typename _iteration_type\
>

Expand All @@ -25,9 +25,9 @@
_priority_queue,\
_vertex_manager,\
_vertex_allocator,\
TCompoundVertex,\
euclidian_heuristics,\
_data_storage_base,\
_vertex,\
_iteration_type\
>

Expand Down
31 changes: 16 additions & 15 deletions src/xrAICore/Navigation/data_storage_binary_heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,25 @@

#pragma once

struct CDataStorageBinaryHeap {
struct CDataStorageBinaryHeap
{
template<typename TCompoundVertex>
struct VertexData
{};

template <
typename _data_storage,
template <typename _T> class _vertex = CEmptyClassTemplate
>
class CDataStorage : public _data_storage::template CDataStorage<_vertex> {
template<typename _data_storage, typename TCompoundVertex>
class CDataStorage : public _data_storage::template CDataStorage<TCompoundVertex>
{
public:
typedef typename _data_storage::template CDataStorage<_vertex> inherited;
typedef typename inherited::CGraphVertex CGraphVertex;
typedef typename CGraphVertex::_dist_type _dist_type;
typedef typename CGraphVertex::_index_type _index_type;
typedef typename _data_storage::template CDataStorage<TCompoundVertex> inherited;
typedef TCompoundVertex CGraphVertex;
typedef typename CGraphVertex::_dist_type _dist_type;
typedef typename CGraphVertex::_index_type _index_type;

struct CGraphNodePredicate {
IC bool operator()(CGraphVertex *node1, CGraphVertex *node2)
{
return (node1->f() > node2->f());
};
struct CGraphNodePredicate
{
bool operator()(CGraphVertex *node1, CGraphVertex *node2)
{ return node1->f() > node2->f(); }
};

protected:
Expand Down
7 changes: 2 additions & 5 deletions src/xrAICore/Navigation/data_storage_binary_heap_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
#pragma once

#define TEMPLATE_SPECIALIZATION \
template<\
typename _data_storage,\
template <typename _T> class _vertex\
>
template<typename _data_storage, typename TCompoundVertex>

#define CBinaryHeap CDataStorageBinaryHeap::CDataStorage<_data_storage,_vertex>
#define CBinaryHeap CDataStorageBinaryHeap::CDataStorage<_data_storage,TCompoundVertex>

TEMPLATE_SPECIALIZATION
IC CBinaryHeap::CDataStorage (const u32 vertex_count) :
Expand Down
39 changes: 16 additions & 23 deletions src/xrAICore/Navigation/data_storage_bucket_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,27 @@ template <
u32 bucket_count,
bool clear_buckets
>
struct CDataStorageBucketList {

template <template <typename _T> class T1>
struct BucketList
struct CDataStorageBucketList
{
template<typename TCompoundVertex>
struct VertexData
{
template<typename T2>
struct _vertex : public T1<T2>
{
T2 *_next;
T2 *_prev;
_path_id_type m_path_id;
_bucket_id_type m_bucket_id;
T2 *&next() { return _next; }
T2 *&prev() { return _prev; }
};
TCompoundVertex *_next;
TCompoundVertex *_prev;
_path_id_type m_path_id;
_bucket_id_type m_bucket_id;
TCompoundVertex *&next() { return _next; }
TCompoundVertex *&prev() { return _prev; }
};

template <
typename _data_storage,
template <typename _T> class _vertex = CEmptyClassTemplate
>
class CDataStorage : public _data_storage::template CDataStorage<BucketList<_vertex>::_vertex>
template<typename _data_storage, typename TCompoundVertex>
class CDataStorage : public _data_storage::template CDataStorage<TCompoundVertex>
{
public:
typedef typename _data_storage::template CDataStorage<BucketList<_vertex>::_vertex> inherited;
typedef typename inherited::CGraphVertex CGraphVertex;
typedef typename CGraphVertex::_dist_type _dist_type;
typedef typename CGraphVertex::_index_type _index_type;
typedef typename _data_storage::template CDataStorage<TCompoundVertex> inherited;
typedef TCompoundVertex CGraphVertex;
typedef typename CGraphVertex::_dist_type _dist_type;
typedef typename CGraphVertex::_index_type _index_type;

protected:
_dist_type m_max_distance;
Expand Down
4 changes: 2 additions & 2 deletions src/xrAICore/Navigation/data_storage_bucket_list_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
>\
template <\
typename _data_storage,\
template <typename _T> class _vertex\
typename TCompoundVertex\
>

#define CBucketList CDataStorageBucketList<_path_id_type,_bucket_id_type,bucket_count,clear_buckets>::CDataStorage<_data_storage,_vertex>
#define CBucketList CDataStorageBucketList<_path_id_type,_bucket_id_type,bucket_count,clear_buckets>::CDataStorage<_data_storage,TCompoundVertex>

TEMPLATE_SPECIALIZATION
IC CBucketList::CDataStorage (const u32 vertex_count) :
Expand Down
27 changes: 13 additions & 14 deletions src/xrAICore/Navigation/data_storage_constructor.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
////////////////////////////////////////////////////////////////////////////

#pragma once

struct EmptyVertexData {};
template <typename T> class CEmptyClassTemplate {};
template <typename T1, typename T2> class CEmptyClassTemplate2 {};

Expand All @@ -16,18 +16,17 @@ template <
typename _builder, // CVertexPath
typename _allocator
>
struct CManagerBuilderAllocatorConstructor {
template <
template <typename T> class _vertex = CEmptyClassTemplate
>
class CDataStorage :
public _manager::template CDataStorage<_builder, _allocator, _vertex>
struct CManagerBuilderAllocatorConstructor
{
template<typename TCompoundVertex>
class CDataStorage :
public _manager::template CDataStorage<_builder, _allocator, TCompoundVertex>
{
public:
typedef typename _manager::template CDataStorage<_builder, _allocator, _vertex> inherited;
typedef typename _manager::template CDataStorage<_builder, _allocator, TCompoundVertex> inherited;
typedef typename inherited::CDataStorageAllocator inherited_allocator;
typedef typename inherited::CGraphVertex CGraphVertex;
typedef typename CGraphVertex::_index_type _index_type;
typedef TCompoundVertex CGraphVertex;
typedef typename CGraphVertex::_index_type _index_type;

public:
CDataStorage(const u32 vertex_count) :
Expand All @@ -46,16 +45,16 @@ template <
typename _manager, // CVertexManagerFixed|CVertexManagerHashFixed
typename _builder, // CEdgePath|CVertexPath
typename _allocator, // CVertexAllocatorFixed
template <typename _T> class _vertex = CEmptyClassTemplate // _Vertex -- dijkstra vertex
typename TCompoundVertex // _Vertex -- dijkstra vertex
>
struct CDataStorageConstructor : // CDataStorageBucketList::CDataStorage<CManagerBuilderAllocatorConstructor<manager, path, allocator> >
public _algorithm::template CDataStorage<
CManagerBuilderAllocatorConstructor<_manager, _builder, _allocator>, _vertex>
CManagerBuilderAllocatorConstructor<_manager, _builder, _allocator>, TCompoundVertex>
{
typedef typename _algorithm::template CDataStorage<
CManagerBuilderAllocatorConstructor<_manager, _builder, _allocator>, _vertex> inherited;
CManagerBuilderAllocatorConstructor<_manager, _builder, _allocator>, TCompoundVertex> inherited;

typedef typename inherited::CGraphVertex CGraphVertex;
typedef TCompoundVertex CGraphVertex;
typedef typename CGraphVertex::_index_type _index_type;

CDataStorageConstructor (const u32 vertex_count) :
Expand Down
50 changes: 23 additions & 27 deletions src/xrAICore/Navigation/dijkstra.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,52 +11,48 @@
#include "xrAICore/Navigation/vertex_path.h"
#include "xrAICore/Navigation/data_storage_constructor.h"

namespace Dijkstra
{
template<typename _dist_type>
struct ByDistType
{
template<typename TCompoundVertex>
struct VertexData
{
typedef _dist_type _dist_type;

_dist_type _f;
TCompoundVertex *_back;

_dist_type &f() { return _f; }
const _dist_type &f() const { return _f; }
TCompoundVertex *&back() { return _back; }
};
};
}

template <
typename _dist_type,
typename _priority_queue,
typename _vertex_manager,
typename _vertex_allocator,
typename TCompoundVertex = EmptyVertexData,
bool euclidian_heuristics = true,
typename _data_storage_base = CVertexPath<euclidian_heuristics>,
template <typename _T> class _vertex = CEmptyClassTemplate,
typename _iteration_type = u32
> class CDijkstra
{
public:
template <typename T1>
struct _Vertex : public _vertex<T1> {
typedef _dist_type _dist_type;

_dist_type _f;
T1 *_back;

IC _dist_type &f()
{
return (_f);
}

IC const _dist_type &f() const
{
return (_f);
}

IC T1 *&back()
{
return (_back);
}
};


typedef CDataStorageConstructor<
_priority_queue, // algorithm
_vertex_manager, // manager
_data_storage_base, // builder
_vertex_allocator, // allocator
_Vertex
TCompoundVertex
> CDataStorage;

protected:
typedef typename CDataStorage::CGraphVertex CGraphVertex;
typedef TCompoundVertex CGraphVertex;
typedef typename CGraphVertex::_dist_type _dist_type;
typedef typename CGraphVertex::_index_type _index_type;

Expand Down
4 changes: 2 additions & 2 deletions src/xrAICore/Navigation/dijkstra_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
typename _priority_queue,\
typename _vertex_manager,\
typename _vertex_allocator,\
typename TCompoundVertex,\
bool euclidian_heuristics,\
typename _data_storage_base,\
template<typename _T> class _vertex,\
typename _iteration_type\
>

Expand All @@ -25,9 +25,9 @@
_priority_queue,\
_vertex_manager,\
_vertex_allocator,\
TCompoundVertex,\
euclidian_heuristics,\
_data_storage_base,\
_vertex,\
_iteration_type\
>

Expand Down
Loading

0 comments on commit 822594a

Please sign in to comment.