Tulip
4.6.0
Better Visualization Through Research
|
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_EDGE_H 00021 #define Tulip_EDGE_H 00022 #include <climits> 00023 #include <tulip/tuliphash.h> 00024 00025 namespace tlp { 00026 00027 /** 00028 * @ingroup Graph 00029 * @brief The edge struct represents an edge in a Graph object. 00030 * 00031 * This structure only contains an identifier, and a function to check if the edge is valid. 00032 * A edge is considered invalid when its id has the UINT_MAX value. 00033 * 00034 * Most operations performed on an edge (getting the source, target, etc) are available into the tlp::Graph object. 00035 * 00036 * @see tlp::node 00037 * @see tlp::Graph 00038 */ 00039 struct edge { 00040 /** 00041 * @brief id The identifier of the edge. 00042 */ 00043 unsigned int id; 00044 00045 /** 00046 * @brief edge creates an invalid edge. 00047 */ 00048 edge():id(UINT_MAX) {} 00049 00050 /** 00051 * @brief edge Create an edge of given identifier. 00052 * It is your responsibility to make sure an edge of this ID exists when you create the edge. 00053 * If you want to make sure this edge exists, use Graph::isElement(), as isValid() will only tell is the edge was correctly initialized. 00054 * 00055 * @param j the identifier this edge will use. 00056 */ 00057 explicit edge(unsigned int j):id(j) {} 00058 00059 /** 00060 * @brief operator unsigned int A convenience function to get the id of an edge. 00061 */ 00062 operator unsigned int() const { 00063 return id; 00064 } 00065 00066 /** 00067 * @brief operator != Compares two edges, checking that they are different.. 00068 * @param n The other edge to compare this one to. 00069 * @return Whether or not the two edges are different. 00070 */ 00071 bool operator==(const edge e) const { 00072 return id==e.id; 00073 } 00074 00075 /** 00076 * @brief operator != Compares two edges, checking that they are identical. 00077 * @param n The other edge to compare this one to. 00078 * @return Whether or not the two edges are the same. 00079 */ 00080 bool operator!=(const edge e) const { 00081 return id!=e.id; 00082 } 00083 00084 /** 00085 * @brief isValid checks if the edge is valid. 00086 * An invalid edge is an edge whose id is UINT_MAX. 00087 * 00088 * @return whether the edge 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::edge as a key in a hash-based data structure (e.g. hashmap). 00099 TLP_BEGIN_HASH_NAMESPACE { 00100 template<> 00101 struct hash<tlp::edge>{ 00102 size_t operator()(const tlp::edge e) const {return e.id;} 00103 }; 00104 } TLP_END_HASH_NAMESPACE 00105 00106 namespace std { 00107 template<> 00108 struct equal_to<tlp::edge> { 00109 size_t operator()(const tlp::edge e,const tlp::edge e2) const { 00110 return e.id==e2.id; 00111 } 00112 }; 00113 template<> 00114 struct less<tlp::edge> { 00115 size_t operator()(const tlp::edge e,const tlp::edge e2) const { 00116 return e.id<e2.id; 00117 } 00118 }; 00119 } 00120 #endif 00121 #endif