Tulip  5.2.0
Large graphs analysis and drawing
Edge.h
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
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 edge is valid.
32  * A edge 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
35  * tlp::Graph object.
36  *
37  * @see tlp::node
38  * @see tlp::Graph
39  */
40 struct edge {
41  /**
42  * @brief id The identifier of the edge.
43  */
44  unsigned int id;
45 
46  /**
47  * @brief edge creates an invalid edge.
48  */
49  edge() : id(UINT_MAX) {}
50 
51  /**
52  * @brief edge Create an edge of given identifier.
53  * It is your responsibility to make sure an edge of this ID exists when you create the edge.
54  * If you want to make sure this edge exists, use Graph::isElement(), as isValid() will only tell
55  * is the edge was correctly initialized.
56  *
57  * @param j the identifier this edge will use.
58  */
59  explicit edge(unsigned int j) : id(j) {}
60 
61  /**
62  * @brief operator unsigned int A convenience function to get the id of an edge.
63  */
64  operator unsigned int() const {
65  return id;
66  }
67 
68  /**
69  * @brief operator == checks if two edges are equals.
70  * @param n The other edge to compare this one to.
71  * @return Whether or not the two edges are equal.
72  */
73  bool operator==(const edge e) const {
74  return id == e.id;
75  }
76 
77  /**
78  * @brief operator != checks if two edges are differents.
79  * @param n The other edge to compare this one to.
80  * @return Whether or not the two edges are different.
81  */
82  bool operator!=(const edge e) const {
83  return id != e.id;
84  }
85 
86  /**
87  * @brief isValid checks if the edge is valid.
88  * An invalid edge is an edge whose id is UINT_MAX.
89  *
90  * @return whether the edge is valid or not.
91  */
92  bool isValid() const {
93  return id != UINT_MAX;
94  }
95 };
96 }
97 
98 ///@cond DOXYGEN_HIDDEN
99 // these three functions allow to use tlp::edge as a key in a hash-based data structure (e.g.
100 // hashmap).
101 TLP_BEGIN_HASH_NAMESPACE {
102  template <>
103  struct hash<tlp::edge> {
104  size_t operator()(const tlp::edge e) const {
105  return e.id;
106  }
107  };
108 }
109 TLP_END_HASH_NAMESPACE
110 
111 namespace std {
112 template <>
113 struct equal_to<tlp::edge> {
114  size_t operator()(const tlp::edge e, const tlp::edge e2) const {
115  return e.id == e2.id;
116  }
117 };
118 template <>
119 struct less<tlp::edge> {
120  size_t operator()(const tlp::edge e, const tlp::edge e2) const {
121  return e.id < e2.id;
122  }
123 };
124 }
125 ///@endcond
126 
127 #endif
bool operator==(const edge e) const
operator == checks if two edges are equals.
Definition: Edge.h:73
edge(unsigned int j)
edge Create an edge of given identifier. It is your responsibility to make sure an edge of this ID ex...
Definition: Edge.h:59
The edge struct represents an edge in a Graph object.
Definition: Edge.h:40
edge()
edge creates an invalid edge.
Definition: Edge.h:49
bool operator!=(const edge e) const
operator != checks if two edges are differents.
Definition: Edge.h:82
bool isValid() const
isValid checks if the edge is valid. An invalid edge is an edge whose id is UINT_MAX.
Definition: Edge.h:92
unsigned int id
id The identifier of the edge.
Definition: Edge.h:44