Tulip  5.6.0
Large graphs analysis and drawing
Node.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_NODE_H
21 #define Tulip_NODE_H
22 #include <climits>
23 #include <functional>
24 
25 namespace tlp {
26 
27 /**
28  * @ingroup Graph
29  * @brief The node struct represents a node 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 a node (getting out edges etc) are available into the tlp::Graph
35  * object.
36  *
37  * @see tlp::edge
38  * @see tlp::Graph
39  */
40 struct node {
41  /**
42  * @brief id The identifier of the node.
43  */
44  unsigned int id;
45 
46  /**
47  * @brief node creates an invalid node.
48  */
49  node() : id(UINT_MAX) {}
50 
51  /**
52  * @brief node Create a node of given identifier.
53  * It is your responsibility to make sure a node of this ID exists when you create the node.
54  * If you want to make sure this node exists, use Graph::isElement(), as isValid() will only tell
55  * is the node was correctly initialized.
56  *
57  * @param j the identifier this node will use.
58  */
59  explicit node(unsigned int j) : id(j) {}
60 
61  /**
62  * @brief operator unsigned int A convenience function to get the id of a node.
63  */
64  operator unsigned int() const {
65  return id;
66  }
67 
68  /**
69  * @brief operator != Compares two nodes, checking that they are different..
70  * @param n The other node to compare this one to.
71  * @return Whether or not the two nodes are different.
72  */
73  bool operator!=(const node n) const {
74  return id != n.id;
75  }
76 
77  /**
78  * @brief operator != Compares two nodes, checking that they are identical.
79  * @param n The other node to compare this one to.
80  * @return Whether or not the two nodes are the same.
81  */
82  bool operator==(const node n) const {
83  return id == n.id;
84  }
85 
86  /**
87  * @brief isValid checks if the node is valid.
88  * An invalid node is a node whose id is UINT_MAX.
89  *
90  * @return whether the node 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
102 struct TLP_SCOPE __tlp_vector_node : public std::vector<tlp::node> {};
103 #endif
104 
105 ///@cond DOXYGEN_HIDDEN
106 // these three functions allow to use tlp::node as a key in a hash-based data structure (e.g.
107 // hashmap).
108 namespace std {
109 template <>
110 struct hash<tlp::node> {
111  size_t operator()(const tlp::node n) const {
112  return n.id;
113  }
114 };
115 template <>
116 struct equal_to<tlp::node> {
117  size_t operator()(const tlp::node n, const tlp::node n2) const {
118  return n.id == n2.id;
119  }
120 };
121 template <>
122 struct less<tlp::node> {
123  size_t operator()(const tlp::node n, const tlp::node n2) const {
124  return n.id < n2.id;
125  }
126 };
127 } // namespace std
128 ///@endcond
129 
130 #endif
tlp::node::node
node(unsigned int j)
node Create a node of given identifier. It is your responsibility to make sure a node of this ID exis...
Definition: Node.h:59
tlp::node::node
node()
node creates an invalid node.
Definition: Node.h:49
tlp::node::operator==
bool operator==(const node n) const
operator != Compares two nodes, checking that they are identical.
Definition: Node.h:82
tlp::node::id
unsigned int id
id The identifier of the node.
Definition: Node.h:44
tlp::node::isValid
bool isValid() const
isValid checks if the node is valid. An invalid node is a node whose id is UINT_MAX.
Definition: Node.h:92
tlp::node::operator!=
bool operator!=(const node n) const
operator != Compares two nodes, checking that they are different..
Definition: Node.h:73
tlp
Definition: AbstractProperty.h:34
tlp::node
The node struct represents a node in a Graph object.
Definition: Node.h:40