Tulip  4.6.0
Better Visualization Through Research
library/tulip-core/include/tulip/Node.h
00001 /*
00002  *
00003  * This file is part of Tulip (www.tulip-software.org)
00004  *
00005  * Authors: David Auber and the Tulip development Team
00006  * from LaBRI, University of Bordeaux
00007  *
00008  * Tulip is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU Lesser General Public License
00010  * as published by the Free Software Foundation, either version 3
00011  * of the License, or (at your option) any later version.
00012  *
00013  * Tulip is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016  * See the GNU General Public License for more details.
00017  *
00018  */
00019 
00020 #ifndef Tulip_NODE_H
00021 #define Tulip_NODE_H
00022 #include <climits>
00023 #include <tulip/tuliphash.h>
00024 
00025 namespace tlp {
00026 
00027 /**
00028  * @ingroup Graph
00029  * @brief The node struct represents a node in a Graph object.
00030  *
00031  * This structure only contains an identifier, and a function to check if the node is valid.
00032  * A node is considered invalid when its id has the UINT_MAX value.
00033  *
00034  * Most operations performed on a node (getting out edges etc) are available into the tlp::Graph object.
00035  *
00036  * @see tlp::edge
00037  * @see tlp::Graph
00038  */
00039 struct node {
00040   /**
00041    * @brief id The identifier of the node.
00042    */
00043   unsigned int id;
00044 
00045   /**
00046    * @brief node creates an invalid node.
00047    */
00048   node():id(UINT_MAX) {}
00049 
00050   /**
00051    * @brief node Create a node of given identifier.
00052    * It is your responsibility to make sure a node of this ID exists when you create the node.
00053    * If you want to make sure this node exists, use Graph::isElement(), as isValid() will only tell is the node was correctly initialized.
00054    *
00055    * @param j the identifier this node will use.
00056    */
00057   explicit node(unsigned int j):id(j) {}
00058 
00059   /**
00060    * @brief operator unsigned int A convenience function to get the id of a node.
00061    */
00062   operator unsigned int() const {
00063     return id;
00064   }
00065 
00066   /**
00067    * @brief operator != Compares two nodes, checking that they are different..
00068    * @param n The other node to compare this one to.
00069    * @return Whether or not the two nodes are different.
00070    */
00071   bool operator!=(const node n) const {
00072     return id!=n.id;
00073   }
00074 
00075   /**
00076    * @brief operator != Compares two nodes, checking that they are identical.
00077    * @param n The other node to compare this one to.
00078    * @return Whether or not the two nodes are the same.
00079    */
00080   bool operator==(const node n) const {
00081     return id==n.id;
00082   }
00083 
00084   /**
00085    * @brief isValid checks if the node is valid.
00086    * An invalid node is a node whose id is UINT_MAX.
00087    *
00088    * @return whether the node is valid or not.
00089    */
00090   bool isValid() const {
00091     return id!=UINT_MAX;
00092   }
00093 };
00094 
00095 }
00096 
00097 #ifndef DOXYGEN_NOTFOR_DEVEL
00098 //these three functions allow to use tlp::node as a key in a hash-based data structure (e.g. hashmap).
00099 TLP_BEGIN_HASH_NAMESPACE {
00100   template<> struct hash<tlp::node> {
00101     size_t operator()(const tlp::node n) const {return n.id;}
00102   };
00103 } TLP_END_HASH_NAMESPACE
00104 
00105 
00106 namespace std {
00107 template<> struct equal_to<tlp::node> {
00108   size_t operator()(const tlp::node n,const tlp::node n2) const {
00109     return n.id==n2.id;
00110   }
00111 };
00112 template<> struct less<tlp::node> {
00113   size_t operator()(const tlp::node n,const tlp::node n2) const {
00114     return n.id<n2.id;
00115   }
00116 };
00117 }
00118 #endif // DOXYGEN_NOTFOR_DEVEL
00119 
00120 #endif
 All Classes Files Functions Variables Enumerations Enumerator Properties