Tulip 5.7.1
Large graphs analysis and drawing
Loading...
Searching...
No Matches
Edge.h
1/*
2 *
3 * This file is part of Tulip (https://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 <functional>
24
25namespace 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 */
40struct 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 different.
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} // namespace tlp
97
98#ifdef _MSC_VER
99#include <vector>
100#include <tulip/tulipconf.h>
101// needed by MSVC to avoid multiple definitions
102struct TLP_SCOPE __tlp_vector_edge : public std::vector<tlp::edge> {};
103#endif
104
105///@cond DOXYGEN_HIDDEN
106// these three functions allow to use tlp::edge as a key in a hash-based data structure (e.g.
107// hashmap).
108namespace std {
109template <>
110struct hash<tlp::edge> {
111 size_t operator()(const tlp::edge e) const {
112 return e.id;
113 }
114};
115template <>
116struct equal_to<tlp::edge> {
117 size_t operator()(const tlp::edge e, const tlp::edge e2) const {
118 return e.id == e2.id;
119 }
120};
121template <>
122struct less<tlp::edge> {
123 size_t operator()(const tlp::edge e, const tlp::edge e2) const {
124 return e.id < e2.id;
125 }
126};
127} // namespace std
128///@endcond
129
130#endif
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 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
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
bool operator!=(const edge e) const
operator != checks if two edges are different.
Definition: Edge.h:82
bool operator==(const edge e) const
operator == checks if two edges are equals.
Definition: Edge.h:73