remove \r
[extl.git] / extl / container / detail / net_traits.h
blobb508aaf34d3e31a4ae7b28b5fb5c23b76486ebdd
1 /* ///////////////////////////////////////////////////////////////////////
2 * File: net_traits.h
4 * Created: 08.11.26
5 * Updated: 08.11.29
7 * Brief: The net_traits class
9 * [<Home>]
10 * Copyright (c) 2008-2020, Waruqi All rights reserved.
11 * //////////////////////////////////////////////////////////////////// */
13 #ifndef EXTL_CONTAINER_DETAIL_NET_TRAITS_H
14 #define EXTL_CONTAINER_DETAIL_NET_TRAITS_H
16 /* ///////////////////////////////////////////////////////////////////////
17 * Includes
19 #include "../prefix.h"
20 #include "../basic_pair.h"
21 /* ///////////////////////////////////////////////////////////////////////
22 * ::extl::detail namespace
24 EXTL_BEGIN_NAMESPACE
25 EXTL_DETAIL_BEGIN_NAMESPACE
27 /// net_traits_impl
28 template<e_bool_t is_dir>
29 struct net_traits_impl
31 /// node_type_impl
32 template< typename_param_k Dev
33 , typename_param_k Val
34 , typename_param_k Wgt
36 struct node_type_impl;
38 /// arc_type_impl
39 template< typename_param_k Dev
40 , typename_param_k Val
41 , typename_param_k Wgt
43 struct arc_type_impl;
46 /// net_traits_impl<e_true_v>
47 EXTL_TEMPLATE_SPECIALISATION
48 struct net_traits_impl<e_true_v> // directed
50 /// node_type_impl
51 template< typename_param_k Dev
52 , typename_param_k Val
53 , typename_param_k Wgt
55 struct node_type_impl
57 /// \name Types
58 /// @{
59 public:
60 typedef Dev derived_type;
61 typedef Val value_type;
62 typedef value_type* pointer;
63 typedef value_type const* const_pointer;
64 typedef value_type& reference;
65 typedef value_type const& const_reference;
66 typedef e_size_t size_type;
67 typedef size_type index_type;
68 typedef e_bool_t bool_type;
69 /// @}
71 /// \name Members
72 /// @{
73 private:
74 size_type m_in_degree;
75 size_type m_out_degree;
76 /// @}
78 /// \name Constructors
79 /// @{
80 public:
81 node_type_impl()
82 : m_in_degree(0)
83 , m_out_degree(0)
85 /// @}
87 /// \name Attributes
88 /// @{
89 public:
90 size_type in_degree() const { return m_in_degree; }
91 void in_degree(size_type d) { m_in_degree = d; }
93 size_type out_degree() const { return m_out_degree; }
94 void out_degree(size_type d) { m_out_degree = d; }
96 size_type degree() const { return in_degree() + out_degree(); }
97 /// @}
99 /// \name Mutators
100 /// @{
101 public:
102 void clear()
104 in_degree(0);
105 out_degree(0);
107 /// @}
109 /// \name Helpers
110 /// @{
111 private:
112 derived_type& derive() { return static_cast<derived_type&>(*this); }
113 derived_type const& derive() const { return static_cast<derived_type const&>(*this); }
114 /// @}
117 /// arc_type_impl
118 template< typename_param_k Dev
119 , typename_param_k Val
120 , typename_param_k Wgt
122 struct arc_type_impl
124 /// \name Types
125 /// @{
126 public:
127 typedef Dev derived_type;
128 typedef Wgt weight_type;
129 typedef e_size_t size_type;
130 typedef size_type index_type;
131 typedef e_bool_t bool_type;
132 /// @}
134 /// \name Helpers
135 /// @{
136 private:
137 derived_type& derive() { return static_cast<derived_type&>(*this); }
138 derived_type const& derive() const { return static_cast<derived_type const&>(*this); }
139 /// @}
142 /// net_traits_impl<e_true_v>
143 EXTL_TEMPLATE_SPECIALISATION
144 struct net_traits_impl<e_false_v> // indirected
146 /// node_type_impl
147 template< typename_param_k Dev
148 , typename_param_k Val
149 , typename_param_k Wgt
151 struct node_type_impl
153 /// \name Types
154 /// @{
155 public:
156 typedef Dev derived_type;
157 typedef Val value_type;
158 typedef value_type* pointer;
159 typedef value_type const* const_pointer;
160 typedef value_type& reference;
161 typedef value_type const& const_reference;
162 typedef e_size_t size_type;
163 typedef size_type index_type;
164 typedef e_bool_t bool_type;
165 /// @}
167 /// \name Members
168 /// @{
169 private:
170 size_type m_degree;
171 /// @}
173 /// \name Constructors
174 /// @{
175 public:
176 node_type_impl()
177 : m_degree(0)
179 /// @}
181 /// \name Attributes
182 /// @{
183 public:
184 size_type degree() const { return m_degree; }
185 void degree(size_type d) { m_degree = d; }
186 /// @}
188 /// \name Mutators
189 /// @{
190 public:
191 void clear()
193 degree(0);
195 /// @}
197 /// \name Helpers
198 /// @{
199 private:
200 derived_type& derive() { return static_cast<derived_type&>(*this); }
201 derived_type const& derive() const { return static_cast<derived_type const&>(*this); }
202 /// @}
205 /// arc_type_impl
206 template< typename_param_k Dev
207 , typename_param_k Val
208 , typename_param_k Wgt
210 struct arc_type_impl
212 /// \name Types
213 /// @{
214 public:
215 typedef Dev derived_type;
216 typedef Wgt weight_type;
217 typedef e_size_t size_type;
218 typedef size_type index_type;
219 typedef e_bool_t bool_type;
220 /// @}
222 /// \name Helpers
223 /// @{
224 private:
225 derived_type& derive() { return static_cast<derived_type&>(*this); }
226 derived_type const& derive() const { return static_cast<derived_type const&>(*this); }
227 /// @}
231 /*!brief net_traits
233 * \param is_dir returns \true if it's a directed net
234 * \param Val the value type
235 * \param Wgt the weight type
237 * \ingroup extl_group_container
239 template< e_bool_t is_dir
240 , typename_param_k Val
241 , typename_param_k Wgt
243 struct net_traits
245 struct arc_type;
246 /// node_type
247 struct node_type
248 : public net_traits_impl<is_dir>::template_qual_k node_type_impl<node_type, Val, Wgt>
250 /// \name Types
251 /// @{
252 public:
253 typedef typename_type_k net_traits_impl<is_dir>::
254 template_qual_k node_type_impl<node_type, Val, Wgt> base_type;
255 typedef Val value_type;
256 typedef value_type* pointer;
257 typedef value_type const* const_pointer;
258 typedef value_type& reference;
259 typedef value_type const& const_reference;
260 typedef e_size_t size_type;
261 typedef size_type index_type;
262 typedef e_bool_t bool_type;
263 friend struct arc_type;
264 /// @}
266 /// \name Members
267 /// @{
268 private:
269 index_type m_id;
270 value_type m_value;
271 /// @}
273 private:
274 enum { en_id_empty = -1 };
276 /// \name Constructors
277 /// @{
278 public:
279 explicit_k node_type( index_type id = index_type(en_id_empty)
280 , const_reference value = value_type())
281 : base_type()
282 , m_id(id)
283 , m_value(value)
285 /// @}
287 /// \name Attributes
288 /// @{
289 public:
290 const_reference value() const { return m_value; }
291 reference value() { return m_value; }
292 void value(const_reference val) { m_value = val; }
294 index_type const& id() const { return m_id; }
295 void id(index_type i) { m_id = i; }
296 bool_type is_empty() const { return id() == index_type(en_id_empty); }
297 /// @}
299 /// \name Mutators
300 /// @{
301 public:
302 void clear()
304 id(index_type(en_id_empty));
305 value(value_type());
306 base_type::clear();
308 /// @}
311 /// arc_type
312 struct arc_type
313 : public net_traits_impl<is_dir>::template_qual_k arc_type_impl<arc_type, Val, Wgt>
315 /// \name Types
316 /// @{
317 public:
318 typedef Wgt weight_type;
319 typedef e_size_t size_type;
320 typedef size_type index_type;
321 typedef e_bool_t bool_type;
322 typedef basic_pair<index_type, index_type> index_pair_type;
323 /// @}
325 /// \name Members
326 /// @{
327 public:
328 index_pair_type m_ids;
329 weight_type m_weight;
330 /// @}
332 /// \name Constructors
333 /// @{
334 public:
335 arc_type()
336 : m_ids(index_pair_type())
337 , m_weight(weight_type())
339 arc_type( index_type bid
340 , index_type eid
341 , weight_type const& w = weight_type())
342 : m_ids(bid, eid)
343 , m_weight(w)
346 /// @}
348 /// \name Attributes
349 /// @{
350 public:
351 weight_type const& weight() const { return m_weight; }
352 weight_type& weight() { return m_weight; }
353 void weight(weight_type const& w) { m_weight = w; }
355 index_pair_type const& ids() const { return m_ids; }
356 index_pair_type& ids() { return m_ids; }
357 void ids(index_pair_type const& ids) { m_ids = ids; }
359 index_type const& begin_id() const { return ids().first(); }
360 void begin_id(index_type const& id) { ids().first(id); }
362 index_type const& end_id() const { return ids().second(); }
363 void end_id(index_type const& id) { ids().second(id); }
365 bool_type is_empty() const
367 EXTL_ASSERT(is_valid());
368 return index_type(node_type::en_id_empty) == begin_id()
369 && index_type(node_type::en_id_empty) == end_id();
371 bool_type is_valid() const
373 if ((index_type(node_type::en_id_empty) == begin_id())
374 != (index_type(node_type::en_id_empty) == end_id()))
375 return e_false_v;
376 return e_true_v;
378 /// @}
380 /// \name Mutators
381 /// @{
382 public:
383 void clear()
385 weight(weight_type());
386 begin_id(index_type(node_type::en_id_empty));
387 end_id(index_type(node_type::en_id_empty));
388 EXTL_ASSERT(is_valid());
390 /// @}
393 /* ///////////////////////////////////////////////////////////////////////
394 * ::extl::detail namespace
396 EXTL_DETAIL_END_NAMESPACE
397 EXTL_END_NAMESPACE
399 /* //////////////////////////////////////////////////////////////////// */
400 #endif /* EXTL_CONTAINER_DETAIL_NET_TRAITS_H */
401 /* //////////////////////////////////////////////////////////////////// */