1 /* ///////////////////////////////////////////////////////////////////////
7 * Brief: The net_traits class
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 /* ///////////////////////////////////////////////////////////////////////
19 #include "../prefix.h"
20 #include "../basic_pair.h"
21 /* ///////////////////////////////////////////////////////////////////////
22 * ::extl::detail namespace
25 EXTL_DETAIL_BEGIN_NAMESPACE
28 template<e_bool_t is_dir
>
29 struct net_traits_impl
32 template< typename_param_k Dev
33 , typename_param_k Val
34 , typename_param_k Wgt
36 struct node_type_impl
;
39 template< typename_param_k Dev
40 , typename_param_k Val
41 , typename_param_k Wgt
46 /// net_traits_impl<e_true_v>
47 EXTL_TEMPLATE_SPECIALISATION
48 struct net_traits_impl
<e_true_v
> // directed
51 template< typename_param_k Dev
52 , typename_param_k Val
53 , typename_param_k Wgt
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
;
74 size_type m_in_degree
;
75 size_type m_out_degree
;
78 /// \name Constructors
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(); }
112 derived_type
& derive() { return static_cast<derived_type
&>(*this); }
113 derived_type
const& derive() const { return static_cast<derived_type
const&>(*this); }
118 template< typename_param_k Dev
119 , typename_param_k Val
120 , typename_param_k Wgt
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
;
137 derived_type
& derive() { return static_cast<derived_type
&>(*this); }
138 derived_type
const& derive() const { return static_cast<derived_type
const&>(*this); }
142 /// net_traits_impl<e_true_v>
143 EXTL_TEMPLATE_SPECIALISATION
144 struct net_traits_impl
<e_false_v
> // indirected
147 template< typename_param_k Dev
148 , typename_param_k Val
149 , typename_param_k Wgt
151 struct node_type_impl
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
;
173 /// \name Constructors
184 size_type
degree() const { return m_degree
; }
185 void degree(size_type d
) { m_degree
= d
; }
200 derived_type
& derive() { return static_cast<derived_type
&>(*this); }
201 derived_type
const& derive() const { return static_cast<derived_type
const&>(*this); }
206 template< typename_param_k Dev
207 , typename_param_k Val
208 , typename_param_k Wgt
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
;
225 derived_type
& derive() { return static_cast<derived_type
&>(*this); }
226 derived_type
const& derive() const { return static_cast<derived_type
const&>(*this); }
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
248 : public net_traits_impl
<is_dir
>::template_qual_k node_type_impl
<node_type
, Val
, Wgt
>
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
;
274 enum { en_id_empty
= -1 };
276 /// \name Constructors
279 explicit_k
node_type( index_type id
= index_type(en_id_empty
)
280 , const_reference value
= value_type())
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
); }
304 id(index_type(en_id_empty
));
313 : public net_traits_impl
<is_dir
>::template_qual_k arc_type_impl
<arc_type
, Val
, Wgt
>
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
;
328 index_pair_type m_ids
;
329 weight_type m_weight
;
332 /// \name Constructors
336 : m_ids(index_pair_type())
337 , m_weight(weight_type())
339 arc_type( index_type bid
341 , weight_type
const& w
= weight_type())
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()))
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());
393 /* ///////////////////////////////////////////////////////////////////////
394 * ::extl::detail namespace
396 EXTL_DETAIL_END_NAMESPACE
399 /* //////////////////////////////////////////////////////////////////// */
400 #endif /* EXTL_CONTAINER_DETAIL_NET_TRAITS_H */
401 /* //////////////////////////////////////////////////////////////////// */