Home | Documentation | Download | Platforms | Projects | Mailing Lists | Version History

- Main Page
- Classes
- Files
- Related Pages

# node.h

    00001 //==========================================================================
    00002 //
    00003 //   node.h
    00004 //
    00005 //==========================================================================
    00006 // $Id: node.h,v 1.20 2003/11/27 13:36:56 raitner Exp $
    00007
    00008 #ifndef GTL_NODE_H
    00009 #define GTL_NODE_H
    00010
    00011 #include <GTL/GTL.h>
    00012 #include <GTL/edge.h>
    00013
    00014 #include <list>
    00015
    00016 __GTL_BEGIN_NAMESPACE
    00017
    00018 //--------------------------------------------------------------------------
    00019 //   For MSVC 5.0 node.h has to be included before {node,edge}_data.h.
    00020 //   So we only declare node_data here
    00021 //--------------------------------------------------------------------------
    00022
    00023 class node_data;
    00024
    00025 //--------------------------------------------------------------------------
    00026 // The first alternative is correct. The second one is a workaround
    00027 // for compilers that don't support namespaces and use the SGI STL
    00028 // (i.e. gcc/egcs)
    00029 //--------------------------------------------------------------------------
    00030
    00031 #ifdef __GTL_USE_NAMESPACES
    00032
    00033 class node;
    00034 typedef std::iterator<std::bidirectional_iterator_tag, edge> bi_iter_edge;
    00035 typedef std::iterator<std::bidirectional_iterator_tag, node> bi_iter_node;
    00036
    00037 #else
    00038
    00039 class node;
    00040 typedef bidirectional_iterator<edge,ptrdiff_t> bi_iter_edge;
    00041 typedef bidirectional_iterator<node,ptrdiff_t> bi_iter_node;
    00042
    00043 #endif // __GTL_USE_NAMESPACES
    00044
    00045 //--------------------------------------------------------------------------
    00046 //   nodes
    00047 //--------------------------------------------------------------------------
    00048
    00052 class GTL_EXTERN node
    00053 {
    00054 public:
    00068     node();
    00069
    00074     int degree() const;
    00075
    00079     int outdeg() const;
    00080
    00084     int indeg() const;
    00085
    00089     int id() const;
    00090
    00096     const node& opposite(edge e) const;
    00097
    00101     list<node> opposites(edge) const;
    00102
    00110     bool is_hidden () const;
    00111
    00118     int excentricity() const;
    00119
    00120     //================================================== Iterator types
    00121
    00125     typedef list<edge>::const_iterator in_edges_iterator;
    00129     typedef list<edge>::const_iterator out_edges_iterator;
    00130
    00134     class inout_edges_iterator;
    00135
    00139     class adj_nodes_iterator;
    00140
    00144     class adj_edges_iterator;
    00145
    00146     //================================================== Iterators
    00147
    00153     adj_nodes_iterator adj_nodes_begin() const;
    00154
    00160     adj_nodes_iterator adj_nodes_end() const;
    00161
    00167     adj_edges_iterator adj_edges_begin() const;
    00168
    00174     adj_edges_iterator adj_edges_end() const;
    00175
    00181     in_edges_iterator in_edges_begin() const;
    00182
    00188     in_edges_iterator in_edges_end() const;
    00189
    00195     out_edges_iterator out_edges_begin() const;
    00196
    00202     out_edges_iterator out_edges_end() const;
    00203
    00209     inout_edges_iterator inout_edges_begin() const;
    00210
    00216     inout_edges_iterator inout_edges_end() const;
    00217
    00218     //================================================== Implementation
    00219
    00220 private:
    00221     node_data *data;
    00222
    00223     bool is_directed() const;
    00224     bool is_undirected() const;
    00225
    00226     friend class graph;
    00227     friend class edge;
    00228     friend class adj_edges_iterator;
    00229
    00230     GTL_EXTERN friend bool operator==(node, node);
    00231     GTL_EXTERN friend bool operator!=(node, node);
    00232     GTL_EXTERN friend bool operator<(node, node);
    00233     GTL_EXTERN friend ostream& operator<< (ostream& os, const node& n);
    00234 };
    00235
    00236
    00240 class GTL_EXTERN node::adj_edges_iterator : public bi_iter_edge
    00241 {
    00242 public:
    00243
    00244     // constructor
    00245     adj_edges_iterator();
    00246     adj_edges_iterator(node, bool);
    00247
    00248     // comparibility
    00249     bool operator==(const adj_edges_iterator&) const;
    00250     bool operator!=(const adj_edges_iterator&) const;
    00251
    00252     // operators
    00253     adj_edges_iterator &operator++();
    00254     adj_edges_iterator operator++(int);
    00255     adj_edges_iterator &operator--();
    00256     adj_edges_iterator operator--(int);
    00257
    00258     // dereferencing
    00259     const edge& operator*() const;
    00260     const edge* operator->() const;
    00261
    00262 private:
    00263     in_edges_iterator akt_edge[2], last_edge[2], begin_edge[2];
    00264     int inout;     // in=0, out=1
    00265     bool directed; // graph directed ??
    00266 };
    00267
    00271 class GTL_EXTERN node::inout_edges_iterator : public bi_iter_edge
    00272 {
    00273 public:
    00274
    00275     // constructor
    00276     inout_edges_iterator();
    00277     inout_edges_iterator(node n, bool start);
    00278
    00279     // comparibility
    00280     bool operator==(const inout_edges_iterator&) const;
    00281     bool operator!=(const inout_edges_iterator&) const;
    00282
    00283     // operators
    00284     inout_edges_iterator &operator++();
    00285     inout_edges_iterator operator++(int);
    00286     inout_edges_iterator &operator--();
    00287     inout_edges_iterator operator--(int);
    00288
    00289     // dereferencing
    00290     const edge& operator*() const;
    00291     const edge* operator->() const;
    00292
    00293 private:
    00294     in_edges_iterator akt_edge[2], last_edge, begin_edge;
    00295     int inout;     // in=0, out=1
    00296 };
    00297
    00301 class GTL_EXTERN node::adj_nodes_iterator : public bi_iter_node
    00302 {
    00303 public:
    00304
    00305     // constructor
    00306     adj_nodes_iterator();
    00307     adj_nodes_iterator(const node&, bool);
    00308
    00309     // comparibility
    00310     bool operator==(const adj_nodes_iterator&) const;
    00311     bool operator!=(const adj_nodes_iterator&) const;
    00312
    00313     // operators
    00314     adj_nodes_iterator &operator++();
    00315     adj_nodes_iterator operator++(int);
    00316     adj_nodes_iterator &operator--();
    00317     adj_nodes_iterator operator--(int);
    00318
    00319     // dereferencing
    00320     const node& operator*() const;
    00321     const node* operator->() const;
    00322
    00323 private:
    00324     adj_edges_iterator akt_edge;
    00325     node int_node;
    00326 };
    00327
    00328
    00329 __GTL_END_NAMESPACE
    00330
    00331 //--------------------------------------------------------------------------
    00332 //   Iteration
    00333 //--------------------------------------------------------------------------
    00334
    00335 // #define forall_adj_nodes(v,w)        GTL_FORALL(v,w,node::adj_nodes_iterator,adj_nodes_)
    00336 #define forall_out_edges(e,v)   GTL_FORALL(e,v,node::out_edges_iterator,out_edges_)
    00337 #define forall_in_edges(e,v)    GTL_FORALL(e,v,node::in_edges_iterator,in_edges_)
    00338 #define forall_inout_edges(e,v) GTL_FORALL(e,v,node::inout_edges_iterator,inout_edges_)
    00339 #define forall_adj_edges(e,v)   GTL_FORALL(e,v,node::adj_edges_iterator,adj_edges_)
    00340
    00341 #endif // GTL_NODE_H
    00342
    00343 //--------------------------------------------------------------------------
    00344 //   end of file
    00345 //--------------------------------------------------------------------------

University of Passau - FMI - Theoretical Computer Science

Design © 2002, 2003 Marcus Raitner, University of Passau