Tulip  4.1.0
Better Visualization Through Research
 All Classes Files Functions Variables Enumerations Enumerator Properties Groups Pages
Edge.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 
20 #ifndef Tulip_EDGE_H
21 #define Tulip_EDGE_H
22 #include <climits>
23 #include <tulip/tuliphash.h>
24 
25 namespace tlp {
26 
27 /**
28  * @ingroup Graph
29  * @brief The edge struct represents an edge in a Graph object.
30  *
31  * This structure only contains an identifier, and a function to check if the node is valid.
32  * A node is considered invalid when its id has the UINT_MAX value.
33  *
34  * Most operations performed on an edge (getting the source, target, etc) are available into the tlp::Graph object.
35  *
36  * @see tlp::node
37  * @see tlp::Graph
38  */
39 struct edge {
40  /**
41  * @brief id The identifier of the edge.
42  */
43  unsigned int id;
44 
45  /**
46  * @brief edge creates an invalid edge.
47  */
48  edge():id(UINT_MAX) {}
49 
50  /**
51  * @brief edge Create an edge of given identifier.
52  * It is your responsibility to make sure an edge of this ID exists when you create the edge.
53  * If you want to make sure this edge exists, use Graph::isElement(), as isValid() will only tell is the edge was correctly initialized.
54  *
55  * @param j the identifier this edge will use.
56  */
57  explicit edge(unsigned int j):id(j) {}
58 
59  /**
60  * @brief operator unsigned int A convenience function to get the id of an edge.
61  */
62  operator unsigned int() const {
63  return id;
64  }
65 
66  /**
67  * @brief operator != Compares two edges, checking that they are different..
68  * @param n The other edge to compare this one to.
69  * @return Whether or not the two edges are different.
70  */
71  bool operator==(const edge e) const {
72  return id==e.id;
73  }
74 
75  /**
76  * @brief operator != Compares two edges, checking that they are identical.
77  * @param n The other edge to compare this one to.
78  * @return Whether or not the two edges are the same.
79  */
80  bool operator!=(const edge e) const {
81  return id!=e.id;
82  }
83 
84  /**
85  * @brief isValid checks if the edge is valid.
86  * An invalid edge is an edge whose id is UINT_MAX.
87  *
88  * @return whether the edge is valid or not.
89  */
90  bool isValid() const {
91  return id!=UINT_MAX;
92  }
93 };
94 
95 }
96 
97 #ifndef DOXYGEN_NOTFOR_DEVEL
98 //these three functions allow to use tlp::edge as a key in a hash-based data structure (e.g. hashmap).
99 TLP_BEGIN_HASH_NAMESPACE {
100  template<>
101  struct hash<tlp::edge>{
102  size_t operator()(const tlp::edge e) const {return e.id;}
103  };
104 } TLP_END_HASH_NAMESPACE
105 
106 namespace std {
107 template<>
108 struct equal_to<tlp::edge> {
109  size_t operator()(const tlp::edge e,const tlp::edge e2) const {
110  return e.id==e2.id;
111  }
112 };
113 template<>
114 struct less<tlp::edge> {
115  size_t operator()(const tlp::edge e,const tlp::edge e2) const {
116  return e.id<e2.id;
117  }
118 };
119 }
120 #endif
121 #endif