-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_gr_type.h
275 lines (238 loc) · 8.12 KB
/
_gr_type.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#ifndef __GR_TYPE_H
#define __GR_TYPE_H
// Copyright David Lawrence Bien 1997 - 2021.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt).
// _gr_type.h
// dgraph: typed links and nodes.
// Templatize each by both the node type and the element type ( design decision ).
// This allows typed access to connect graph objects - at the cost of more specified
// types - which could potentially cause more code, except:
// i) Most of the methods are inline - if not all.
// ii) The likelihood of coupling some node type with two different link types is slim.
__DGRAPH_BEGIN_NAMESPACE
template < class t_TyNodeEl, class t_TyLinkEl, class t_TyGraphNodeBase >
class _graph_node;
template < class t_TyLinkEl, class t_TyNodeEl, class t_TyGraphLinkBase >
class _graph_link : public t_TyGraphLinkBase
{
typedef t_TyGraphLinkBase _TyBase;
typedef _graph_link< t_TyLinkEl, t_TyNodeEl, t_TyGraphLinkBase > _TyThis;
public:
typedef t_TyLinkEl _TyLinkEl;
typedef t_TyNodeEl _TyNodeEl;
typedef _TyLinkEl _TyElement;
typedef t_TyGraphLinkBase _TyGraphLinkBase;
typedef typename t_TyGraphLinkBase::_TyGraphLinkBase _TyGraphLinkBaseBase;
typedef typename _TyGraphLinkBase::_TyGraphNodeBase _TyGraphNodeBase;
typedef typename _TyGraphNodeBase::_TyGraphNodeBase _TyGraphNodeBaseBase;
typedef _graph_node< _TyNodeEl, _TyLinkEl, _TyGraphNodeBase > _TyGraphNode;
explicit _graph_link( _TyLinkEl const & _rtEl )
: m_tEl( _rtEl )
{
}
_graph_link()
{
}
// This accesses the constructable/destructable object within
// the _graph_link. This allows implementations to override this
// implementation class to support different types for the
// constructable object and the link element - see "_gr_shwr.h":
_TyLinkEl & RElObject() _BIEN_NOTHROW
{
return m_tEl;
}
// Element access:
_TyLinkEl & REl() _BIEN_NOTHROW
{
return m_tEl;
}
const _TyLinkEl & REl() const _BIEN_NOTHROW
{
return m_tEl;
}
_TyLinkEl & RElNonConst() _BIEN_NOTHROW
{
return m_tEl;
}
const _TyLinkEl & RElConst() const _BIEN_NOTHROW
{
return m_tEl;
}
operator _TyLinkEl & () _BIEN_NOTHROW
{
return m_tEl;
}
operator const _TyLinkEl & () const _BIEN_NOTHROW
{
return m_tEl;
}
// typed child/parent node access:
_TyGraphNode * PGNChild() _BIEN_NOTHROW
{
return static_cast< _TyGraphNode* >( _TyBase::PGNBChild() );
}
_TyGraphNode * PGNParent() _BIEN_NOTHROW
{
return static_cast< _TyGraphNode* >( _TyBase::PGNBParent() );
}
const _TyGraphNode * PGNChild() const _BIEN_NOTHROW
{
return const_cast< const _TyGraphNode* >( static_cast< _TyGraphNode* >( _TyBase::PGNBChild() ) );
}
const _TyGraphNode * PGNParent() const _BIEN_NOTHROW
{
return const_cast< const _TyGraphNode* >( static_cast< _TyGraphNode* >( _TyBase::PGNBParent() ) );
}
_TyThis ** PPGLGetNextChild() _BIEN_NOTHROW
{
return (_TyThis**)_TyBase::PPGLBGetNextChild();
}
const _TyThis * const * PPGLGetNextChild() const _BIEN_NOTHROW
{
return (const _TyThis* const *)_TyBase::PPGLBGetNextChild();
}
_TyThis ** PPGLGetNextParent() _BIEN_NOTHROW
{
return (_TyThis**)_TyBase::PPGLBGetNextParent();
}
const _TyThis * const * PPGLGetNextParent() const _BIEN_NOTHROW
{
return (const _TyThis* const *)_TyBase::PPGLBGetNextParent();
}
_TyThis ** PPGLGetThisChild() _BIEN_NOTHROW
{
return (_TyThis**)_TyBase::PPGLBGetThisChild();
}
const _TyThis * const * PPGLGetThisChild() const _BIEN_NOTHROW
{
return (const _TyThis* const *)_TyBase::PPGLBGetThisChild();
}
_TyThis ** PPGLGetThisParent() _BIEN_NOTHROW
{
return (_TyThis**)_TyBase::PPGLBGetThisParent();
}
const _TyThis * const * PPGLGetThisParent() const _BIEN_NOTHROW
{
return (const _TyThis* const *)_TyBase::PPGLBGetThisParent();
}
_TyThis * PGLGetPrevChild() _BIEN_NOTHROW
{
return (_TyThis*)_TyBase::PGLBGetPrevChild();
}
const _TyThis * PGLGetPrevChild() const _BIEN_NOTHROW
{
return (const _TyThis*)_TyBase::PGLBGetPrevChild();
}
_TyThis * PGLGetPrevParent() _BIEN_NOTHROW
{
return (_TyThis*)_TyBase::PGLBGetPrevParent();
}
const _TyThis * PGLGetPrevParent() const _BIEN_NOTHROW
{
return (const _TyThis*)_TyBase::PGLBGetPrevParent();
}
void InsertParent( _TyThis ** _ppgl ) _BIEN_NOTHROW
{
_TyGraphLinkBase::InsertParent( (_TyGraphLinkBase**)_ppgl );
}
void InsertChild( _TyThis ** _ppgl ) _BIEN_NOTHROW
{
_TyGraphLinkBase::InsertChild( (_TyGraphLinkBase**)_ppgl );
}
void InsertParentAssume( _TyThis ** _ppgl ) _BIEN_NOTHROW
{
_TyGraphLinkBase::InsertParentAssume( (_TyGraphLinkBase**)_ppgl );
}
void InsertChildAssume( _TyThis ** _ppgl ) _BIEN_NOTHROW
{
_TyGraphLinkBase::InsertChildAssume( (_TyGraphLinkBase**)_ppgl );
}
protected:
t_TyLinkEl m_tEl;
};
template < class t_TyNodeEl, class t_TyLinkEl, class t_TyGraphNodeBase >
class _graph_node : public t_TyGraphNodeBase
{
typedef t_TyGraphNodeBase _TyBase;
typedef _graph_node< t_TyNodeEl, t_TyLinkEl, t_TyGraphNodeBase > _TyThis;
public:
typedef t_TyNodeEl _TyNodeEl;
typedef t_TyLinkEl _TyLinkEl;
typedef _TyNodeEl _TyElement;
typedef t_TyGraphNodeBase _TyGraphNodeBase;
typedef typename t_TyGraphNodeBase::_TyGraphNodeBase _TyGraphNodeBaseBase;
typedef typename _TyGraphNodeBase::_TyGraphLinkBase _TyGraphLinkBase;
typedef typename _TyGraphLinkBase::_TyGraphLinkBase _TyGraphLinkBaseBase;
typedef _graph_link< _TyLinkEl, _TyNodeEl, _TyGraphLinkBase > _TyGraphLink;
explicit _graph_node( _TyNodeEl const & _rtEl )
: m_tEl( _rtEl )
{
}
_graph_node()
{
}
// This accesses the constructable/destructable object within
// the _graph_node. This allows implementations to override this
// implementation class to support different types for the
// constructable object and the node element - see "_gr_shwr.h":
_TyNodeEl & RElObject() _BIEN_NOTHROW
{
return m_tEl;
}
// Element access:
_TyNodeEl & REl() _BIEN_NOTHROW
{
return m_tEl;
}
const _TyNodeEl & REl() const _BIEN_NOTHROW
{
return m_tEl;
}
_TyNodeEl & RElNonConst() _BIEN_NOTHROW
{
return m_tEl;
}
const _TyNodeEl & RElConst() const _BIEN_NOTHROW
{
return m_tEl;
}
operator _TyNodeEl & () _BIEN_NOTHROW
{
return m_tEl;
}
operator const _TyNodeEl & () const _BIEN_NOTHROW
{
return m_tEl;
}
// child/parent typed link list access:
_TyGraphLink ** PPGLChildHead() _BIEN_NOTHROW
{
return (_TyGraphLink**)_TyBase::PPGLBChildHead();
}
const _TyGraphLink * const * PPGLChildHead() const _BIEN_NOTHROW
{
return (const _TyGraphLink* const *)_TyBase::PPGLBChildHead();
}
_TyGraphLink ** PPGLParentHead() _BIEN_NOTHROW
{
return (_TyGraphLink**)_TyBase::PPGLBParentHead();
}
const _TyGraphLink * const * PPGLParentHead() const _BIEN_NOTHROW
{
return (const _TyGraphLink* const *)_TyBase::PPGLBParentHead();
}
_TyGraphLink ** PPGLRelationHead( bool _fChild ) _BIEN_NOTHROW
{
return (_TyGraphLink**)_TyBase::PPGLBRelationHead( _fChild );
}
const _TyGraphLink * const * PPGLRelationHead( bool _fChild ) const _BIEN_NOTHROW
{
return (const _TyGraphLink* const *)_TyBase::PPGLBRelationHead( _fChild );
}
protected:
_TyNodeEl m_tEl; // the element in the node.
};
__DGRAPH_END_NAMESPACE
#endif //__GR_TYPE_H