Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
node.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file node.h
1 /* This software is distributed under the GNU Lesser General Public License */
2 //==========================================================================
3 //
4 // node.h
5 //
6 //==========================================================================
7 // $Id: node.h,v 1.20 2003/11/27 13:36:56 raitner Exp $
8 
9 #ifndef GTL_NODE_H
10 #define GTL_NODE_H
11 
12 #include <GTL/GTL.h>
13 #include <GTL/edge.h>
14 
15 #include <list>
16 
18 
19 //--------------------------------------------------------------------------
20 // For MSVC 5.0 node.h has to be included before {node,edge}_data.h.
21 // So we only declare node_data here
22 //--------------------------------------------------------------------------
23 
24 class node_data;
25 
26 //--------------------------------------------------------------------------
27 // The first alternative is correct. The second one is a workaround
28 // for compilers that don't support namespaces and use the SGI STL
29 // (i.e. gcc/egcs)
30 //--------------------------------------------------------------------------
31 
32 #ifdef __GTL_USE_NAMESPACES
33 
34 class node;
35 typedef std::iterator<std::bidirectional_iterator_tag, edge> bi_iter_edge;
36 typedef std::iterator<std::bidirectional_iterator_tag, node> bi_iter_node;
37 
38 #else
39 
40 class node;
41 typedef bidirectional_iterator<edge,ptrdiff_t> bi_iter_edge;
42 typedef bidirectional_iterator<node,ptrdiff_t> bi_iter_node;
43 
44 #endif // __GTL_USE_NAMESPACES
45 
46 //--------------------------------------------------------------------------
47 // nodes
48 //--------------------------------------------------------------------------
49 
54 {
55 public:
69  node();
70 
75  int degree() const;
76 
80  int outdeg() const;
81 
85  int indeg() const;
86 
90  int id() const;
91 
97  const node& opposite(edge e) const;
98 
102  list<node> opposites(edge) const;
103 
111  bool is_hidden () const;
112 
119  int excentricity() const;
120 
121  //================================================== Iterator types
122 
126  typedef list<edge>::const_iterator in_edges_iterator;
130  typedef list<edge>::const_iterator out_edges_iterator;
131 
135  class inout_edges_iterator;
136 
140  class adj_nodes_iterator;
141 
145  class adj_edges_iterator;
146 
147  //================================================== Iterators
148 
154  adj_nodes_iterator adj_nodes_begin() const;
155 
161  adj_nodes_iterator adj_nodes_end() const;
162 
168  adj_edges_iterator adj_edges_begin() const;
169 
175  adj_edges_iterator adj_edges_end() const;
176 
182  in_edges_iterator in_edges_begin() const;
183 
189  in_edges_iterator in_edges_end() const;
190 
196  out_edges_iterator out_edges_begin() const;
197 
203  out_edges_iterator out_edges_end() const;
204 
210  inout_edges_iterator inout_edges_begin() const;
211 
217  inout_edges_iterator inout_edges_end() const;
218 
219  //================================================== Implementation
220 
221 private:
223 
224  bool is_directed() const;
225  bool is_undirected() const;
226 
227  friend class graph;
228  friend class edge;
229  friend class adj_edges_iterator;
230 
231  GTL_EXTERN friend bool operator==(node, node);
232  GTL_EXTERN friend bool operator!=(node, node);
233  GTL_EXTERN friend bool operator<(node, node);
234  GTL_EXTERN friend ostream& operator<< (ostream& os, const node& n);
235 };
236 
237 
241 class GTL_EXTERN node::adj_edges_iterator : public bi_iter_edge
242 {
243 public:
244 
245  // constructor
246  adj_edges_iterator();
247  adj_edges_iterator(node, bool);
248 
249  // comparibility
250  bool operator==(const adj_edges_iterator&) const;
251  bool operator!=(const adj_edges_iterator&) const;
252 
253  // operators
254  adj_edges_iterator &operator++();
255  adj_edges_iterator operator++(int);
256  adj_edges_iterator &operator--();
257  adj_edges_iterator operator--(int);
258 
259  // dereferencing
260  const edge& operator*() const;
261  const edge* operator->() const;
262 
263 private:
264  in_edges_iterator akt_edge[2], last_edge[2], begin_edge[2];
265  int inout; // in=0, out=1
266  bool directed; // graph directed ??
267 };
268 
272 class GTL_EXTERN node::inout_edges_iterator : public bi_iter_edge
273 {
274 public:
275 
276  // constructor
277  inout_edges_iterator();
278  inout_edges_iterator(node n, bool start);
279 
280  // comparibility
281  bool operator==(const inout_edges_iterator&) const;
282  bool operator!=(const inout_edges_iterator&) const;
283 
284  // operators
285  inout_edges_iterator &operator++();
286  inout_edges_iterator operator++(int);
287  inout_edges_iterator &operator--();
288  inout_edges_iterator operator--(int);
289 
290  // dereferencing
291  const edge& operator*() const;
292  const edge* operator->() const;
293 
294 private:
295  in_edges_iterator akt_edge[2], last_edge, begin_edge;
296  int inout; // in=0, out=1
297 };
298 
302 class GTL_EXTERN node::adj_nodes_iterator : public bi_iter_node
303 {
304 public:
305 
306  // constructor
307  adj_nodes_iterator();
308  adj_nodes_iterator(const node&, bool);
309 
310  // comparibility
311  bool operator==(const adj_nodes_iterator&) const;
312  bool operator!=(const adj_nodes_iterator&) const;
313 
314  // operators
315  adj_nodes_iterator &operator++();
316  adj_nodes_iterator operator++(int);
317  adj_nodes_iterator &operator--();
318  adj_nodes_iterator operator--(int);
319 
320  // dereferencing
321  const node& operator*() const;
322  const node* operator->() const;
323 
324 private:
325  adj_edges_iterator akt_edge;
327 };
328 
329 
331 
332 //--------------------------------------------------------------------------
333 // Iteration
334 //--------------------------------------------------------------------------
335 
336 // #define forall_adj_nodes(v,w) GTL_FORALL(v,w,node::adj_nodes_iterator,adj_nodes_)
337 #define forall_out_edges(e,v) GTL_FORALL(e,v,node::out_edges_iterator,out_edges_)
338 #define forall_in_edges(e,v) GTL_FORALL(e,v,node::in_edges_iterator,in_edges_)
339 #define forall_inout_edges(e,v) GTL_FORALL(e,v,node::inout_edges_iterator,inout_edges_)
340 #define forall_adj_edges(e,v) GTL_FORALL(e,v,node::adj_edges_iterator,adj_edges_)
341 
342 #endif // GTL_NODE_H
343 
344 //--------------------------------------------------------------------------
345 // end of file
346 //--------------------------------------------------------------------------