Skip to content

Commit 822594a

Browse files
author
nitrocaster
committed
Eradicate recursive CRTPs.
1 parent 1bd9621 commit 822594a

22 files changed

+217
-245
lines changed

src/xrAICore/Navigation/a_star.h

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,49 +12,43 @@
1212
#include "xrAICore/Navigation/data_storage_constructor.h"
1313
#include "xrAICore/Navigation/dijkstra.h"
1414

15-
namespace AStar {
16-
template <
17-
typename _dist_type,
18-
template <typename _T> class T1
19-
>
20-
struct _Vertex {
21-
template <typename T2>
22-
struct _vertex : public T1<T2> {
23-
typedef _dist_type _dist_type;
24-
25-
_dist_type _g;
26-
_dist_type _h;
15+
namespace AStar
16+
{
17+
template<typename _dist_type>
18+
struct ByDistType
19+
{
20+
template<typename TCompoundVertex>
21+
struct VertexData :
22+
Dijkstra::template ByDistType<_dist_type>::template VertexData<TCompoundVertex>
23+
{
24+
typedef _dist_type _dist_type;
2725

28-
IC _dist_type &g()
29-
{
30-
return (_g);
31-
}
26+
_dist_type _g;
27+
_dist_type _h;
3228

33-
IC _dist_type &h()
34-
{
35-
return (_h);
36-
}
37-
};
29+
_dist_type &g() { return _g; }
30+
_dist_type &h() { return _h; }
3831
};
32+
};
3933
}
4034

4135
template <
4236
typename _dist_type,
4337
typename _priority_queue,
4438
typename _vertex_manager,
4539
typename _vertex_allocator,
40+
typename TCompoundVertex = EmptyVertexData,
4641
bool euclidian_heuristics = true,
4742
typename _data_storage_base = CVertexPath<euclidian_heuristics>,
48-
template <typename _T> class _vertex = CEmptyClassTemplate,
4943
typename _iteration_type = u32
50-
> class CAStar : public CDijkstra <
44+
> class CAStar : public CDijkstra<
5145
_dist_type,
5246
_priority_queue,
5347
_vertex_manager,
5448
_vertex_allocator,
49+
TCompoundVertex,
5550
euclidian_heuristics,
5651
_data_storage_base,
57-
AStar::_Vertex<_dist_type,_vertex>::_vertex,
5852
_iteration_type
5953
>
6054
{
@@ -64,14 +58,14 @@ template <
6458
_priority_queue,
6559
_vertex_manager,
6660
_vertex_allocator,
61+
TCompoundVertex,
6762
euclidian_heuristics,
6863
_data_storage_base,
69-
AStar::_Vertex<_dist_type,_vertex>::_vertex,
7064
_iteration_type
71-
> inherited;
72-
typedef typename CDataStorage::CGraphVertex CGraphVertex;
73-
typedef typename CGraphVertex::_dist_type _dist_type;
74-
typedef typename CGraphVertex::_index_type _index_type;
65+
> inherited;
66+
typedef TCompoundVertex CGraphVertex;
67+
typedef typename CGraphVertex::_dist_type _dist_type;
68+
typedef typename CGraphVertex::_index_type _index_type;
7569

7670
protected:
7771
template <typename _PathManager>

src/xrAICore/Navigation/a_star_inline.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
typename _priority_queue,\
1515
typename _vertex_manager,\
1616
typename _vertex_allocator,\
17+
typename TCompoundVertex,\
1718
bool euclidian_heuristics,\
1819
typename _data_storage_base,\
19-
template <typename _T> class _vertex,\
2020
typename _iteration_type\
2121
>
2222

@@ -25,9 +25,9 @@
2525
_priority_queue,\
2626
_vertex_manager,\
2727
_vertex_allocator,\
28+
TCompoundVertex,\
2829
euclidian_heuristics,\
2930
_data_storage_base,\
30-
_vertex,\
3131
_iteration_type\
3232
>
3333

src/xrAICore/Navigation/data_storage_binary_heap.h

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,25 @@
88

99
#pragma once
1010

11-
struct CDataStorageBinaryHeap {
11+
struct CDataStorageBinaryHeap
12+
{
13+
template<typename TCompoundVertex>
14+
struct VertexData
15+
{};
1216

13-
template <
14-
typename _data_storage,
15-
template <typename _T> class _vertex = CEmptyClassTemplate
16-
>
17-
class CDataStorage : public _data_storage::template CDataStorage<_vertex> {
17+
template<typename _data_storage, typename TCompoundVertex>
18+
class CDataStorage : public _data_storage::template CDataStorage<TCompoundVertex>
19+
{
1820
public:
19-
typedef typename _data_storage::template CDataStorage<_vertex> inherited;
20-
typedef typename inherited::CGraphVertex CGraphVertex;
21-
typedef typename CGraphVertex::_dist_type _dist_type;
22-
typedef typename CGraphVertex::_index_type _index_type;
21+
typedef typename _data_storage::template CDataStorage<TCompoundVertex> inherited;
22+
typedef TCompoundVertex CGraphVertex;
23+
typedef typename CGraphVertex::_dist_type _dist_type;
24+
typedef typename CGraphVertex::_index_type _index_type;
2325

24-
struct CGraphNodePredicate {
25-
IC bool operator()(CGraphVertex *node1, CGraphVertex *node2)
26-
{
27-
return (node1->f() > node2->f());
28-
};
26+
struct CGraphNodePredicate
27+
{
28+
bool operator()(CGraphVertex *node1, CGraphVertex *node2)
29+
{ return node1->f() > node2->f(); }
2930
};
3031

3132
protected:

src/xrAICore/Navigation/data_storage_binary_heap_inline.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@
99
#pragma once
1010

1111
#define TEMPLATE_SPECIALIZATION \
12-
template<\
13-
typename _data_storage,\
14-
template <typename _T> class _vertex\
15-
>
12+
template<typename _data_storage, typename TCompoundVertex>
1613

17-
#define CBinaryHeap CDataStorageBinaryHeap::CDataStorage<_data_storage,_vertex>
14+
#define CBinaryHeap CDataStorageBinaryHeap::CDataStorage<_data_storage,TCompoundVertex>
1815

1916
TEMPLATE_SPECIALIZATION
2017
IC CBinaryHeap::CDataStorage (const u32 vertex_count) :

src/xrAICore/Navigation/data_storage_bucket_list.h

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,27 @@ template <
1414
u32 bucket_count,
1515
bool clear_buckets
1616
>
17-
struct CDataStorageBucketList {
18-
19-
template <template <typename _T> class T1>
20-
struct BucketList
17+
struct CDataStorageBucketList
18+
{
19+
template<typename TCompoundVertex>
20+
struct VertexData
2121
{
22-
template<typename T2>
23-
struct _vertex : public T1<T2>
24-
{
25-
T2 *_next;
26-
T2 *_prev;
27-
_path_id_type m_path_id;
28-
_bucket_id_type m_bucket_id;
29-
T2 *&next() { return _next; }
30-
T2 *&prev() { return _prev; }
31-
};
22+
TCompoundVertex *_next;
23+
TCompoundVertex *_prev;
24+
_path_id_type m_path_id;
25+
_bucket_id_type m_bucket_id;
26+
TCompoundVertex *&next() { return _next; }
27+
TCompoundVertex *&prev() { return _prev; }
3228
};
3329

34-
template <
35-
typename _data_storage,
36-
template <typename _T> class _vertex = CEmptyClassTemplate
37-
>
38-
class CDataStorage : public _data_storage::template CDataStorage<BucketList<_vertex>::_vertex>
30+
template<typename _data_storage, typename TCompoundVertex>
31+
class CDataStorage : public _data_storage::template CDataStorage<TCompoundVertex>
3932
{
4033
public:
41-
typedef typename _data_storage::template CDataStorage<BucketList<_vertex>::_vertex> inherited;
42-
typedef typename inherited::CGraphVertex CGraphVertex;
43-
typedef typename CGraphVertex::_dist_type _dist_type;
44-
typedef typename CGraphVertex::_index_type _index_type;
34+
typedef typename _data_storage::template CDataStorage<TCompoundVertex> inherited;
35+
typedef TCompoundVertex CGraphVertex;
36+
typedef typename CGraphVertex::_dist_type _dist_type;
37+
typedef typename CGraphVertex::_index_type _index_type;
4538

4639
protected:
4740
_dist_type m_max_distance;

src/xrAICore/Navigation/data_storage_bucket_list_inline.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
>\
1818
template <\
1919
typename _data_storage,\
20-
template <typename _T> class _vertex\
20+
typename TCompoundVertex\
2121
>
2222

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

2525
TEMPLATE_SPECIALIZATION
2626
IC CBucketList::CDataStorage (const u32 vertex_count) :

src/xrAICore/Navigation/data_storage_constructor.h

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
////////////////////////////////////////////////////////////////////////////
88

99
#pragma once
10-
10+
struct EmptyVertexData {};
1111
template <typename T> class CEmptyClassTemplate {};
1212
template <typename T1, typename T2> class CEmptyClassTemplate2 {};
1313

@@ -16,18 +16,17 @@ template <
1616
typename _builder, // CVertexPath
1717
typename _allocator
1818
>
19-
struct CManagerBuilderAllocatorConstructor {
20-
template <
21-
template <typename T> class _vertex = CEmptyClassTemplate
22-
>
23-
class CDataStorage :
24-
public _manager::template CDataStorage<_builder, _allocator, _vertex>
19+
struct CManagerBuilderAllocatorConstructor
20+
{
21+
template<typename TCompoundVertex>
22+
class CDataStorage :
23+
public _manager::template CDataStorage<_builder, _allocator, TCompoundVertex>
2524
{
2625
public:
27-
typedef typename _manager::template CDataStorage<_builder, _allocator, _vertex> inherited;
26+
typedef typename _manager::template CDataStorage<_builder, _allocator, TCompoundVertex> inherited;
2827
typedef typename inherited::CDataStorageAllocator inherited_allocator;
29-
typedef typename inherited::CGraphVertex CGraphVertex;
30-
typedef typename CGraphVertex::_index_type _index_type;
28+
typedef TCompoundVertex CGraphVertex;
29+
typedef typename CGraphVertex::_index_type _index_type;
3130

3231
public:
3332
CDataStorage(const u32 vertex_count) :
@@ -46,16 +45,16 @@ template <
4645
typename _manager, // CVertexManagerFixed|CVertexManagerHashFixed
4746
typename _builder, // CEdgePath|CVertexPath
4847
typename _allocator, // CVertexAllocatorFixed
49-
template <typename _T> class _vertex = CEmptyClassTemplate // _Vertex -- dijkstra vertex
48+
typename TCompoundVertex // _Vertex -- dijkstra vertex
5049
>
5150
struct CDataStorageConstructor : // CDataStorageBucketList::CDataStorage<CManagerBuilderAllocatorConstructor<manager, path, allocator> >
5251
public _algorithm::template CDataStorage<
53-
CManagerBuilderAllocatorConstructor<_manager, _builder, _allocator>, _vertex>
52+
CManagerBuilderAllocatorConstructor<_manager, _builder, _allocator>, TCompoundVertex>
5453
{
5554
typedef typename _algorithm::template CDataStorage<
56-
CManagerBuilderAllocatorConstructor<_manager, _builder, _allocator>, _vertex> inherited;
55+
CManagerBuilderAllocatorConstructor<_manager, _builder, _allocator>, TCompoundVertex> inherited;
5756

58-
typedef typename inherited::CGraphVertex CGraphVertex;
57+
typedef TCompoundVertex CGraphVertex;
5958
typedef typename CGraphVertex::_index_type _index_type;
6059

6160
CDataStorageConstructor (const u32 vertex_count) :

src/xrAICore/Navigation/dijkstra.h

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,52 +11,48 @@
1111
#include "xrAICore/Navigation/vertex_path.h"
1212
#include "xrAICore/Navigation/data_storage_constructor.h"
1313

14+
namespace Dijkstra
15+
{
16+
template<typename _dist_type>
17+
struct ByDistType
18+
{
19+
template<typename TCompoundVertex>
20+
struct VertexData
21+
{
22+
typedef _dist_type _dist_type;
23+
24+
_dist_type _f;
25+
TCompoundVertex *_back;
26+
27+
_dist_type &f() { return _f; }
28+
const _dist_type &f() const { return _f; }
29+
TCompoundVertex *&back() { return _back; }
30+
};
31+
};
32+
}
33+
1434
template <
1535
typename _dist_type,
1636
typename _priority_queue,
1737
typename _vertex_manager,
1838
typename _vertex_allocator,
39+
typename TCompoundVertex = EmptyVertexData,
1940
bool euclidian_heuristics = true,
2041
typename _data_storage_base = CVertexPath<euclidian_heuristics>,
21-
template <typename _T> class _vertex = CEmptyClassTemplate,
2242
typename _iteration_type = u32
2343
> class CDijkstra
2444
{
2545
public:
26-
template <typename T1>
27-
struct _Vertex : public _vertex<T1> {
28-
typedef _dist_type _dist_type;
29-
30-
_dist_type _f;
31-
T1 *_back;
32-
33-
IC _dist_type &f()
34-
{
35-
return (_f);
36-
}
37-
38-
IC const _dist_type &f() const
39-
{
40-
return (_f);
41-
}
42-
43-
IC T1 *&back()
44-
{
45-
return (_back);
46-
}
47-
};
48-
49-
5046
typedef CDataStorageConstructor<
5147
_priority_queue, // algorithm
5248
_vertex_manager, // manager
5349
_data_storage_base, // builder
5450
_vertex_allocator, // allocator
55-
_Vertex
51+
TCompoundVertex
5652
> CDataStorage;
5753

5854
protected:
59-
typedef typename CDataStorage::CGraphVertex CGraphVertex;
55+
typedef TCompoundVertex CGraphVertex;
6056
typedef typename CGraphVertex::_dist_type _dist_type;
6157
typedef typename CGraphVertex::_index_type _index_type;
6258

src/xrAICore/Navigation/dijkstra_inline.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
typename _priority_queue,\
1515
typename _vertex_manager,\
1616
typename _vertex_allocator,\
17+
typename TCompoundVertex,\
1718
bool euclidian_heuristics,\
1819
typename _data_storage_base,\
19-
template<typename _T> class _vertex,\
2020
typename _iteration_type\
2121
>
2222

@@ -25,9 +25,9 @@
2525
_priority_queue,\
2626
_vertex_manager,\
2727
_vertex_allocator,\
28+
TCompoundVertex,\
2829
euclidian_heuristics,\
2930
_data_storage_base,\
30-
_vertex,\
3131
_iteration_type\
3232
>
3333

0 commit comments

Comments
 (0)