00001 /*---------------------------------------------------------------------+ 00002 | Library QgarLib, graphics analysis and recognition | 00003 | Copyright (C) 2002 Qgar Project, LORIA | 00004 | | 00005 | This library is free software; you can redistribute it and/or | 00006 | modify it under the terms of the GNU Lesser General Public | 00007 | License version 2.1, as published by the Free Software Foundation. | 00008 | | 00009 | This library is distributed in the hope that it will be useful, | 00010 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00011 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 00012 | See the GNU Lesser General Public License for more details. | 00013 | | 00014 | The GNU Lesser General Public License is included in the file | 00015 | LICENSE.LGPL, in the root directory of the Qgar packaging. See | 00016 | http://www.gnu.org/licenses/lgpl.html for the terms of the licence. | 00017 | To receive a paper copy, write to the Free Software Foundation, | 00018 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. | 00019 | | 00020 | Contact Project Qgar for any information: | 00021 | LORIA - équipe Qgar | 00022 | B.P. 239, 54506 Vandoeuvre-lès-Nancy Cedex, France | 00023 | email: qgar-contact@loria.fr | 00024 | http://www.qgar.org/ | 00025 *---------------------------------------------------------------------*/ 00026 00027 00028 #ifndef __GENUGRAPH_H_INCLUDED__ 00029 #define __GENUGRAPH_H_INCLUDED__ 00030 00031 00032 /** 00033 * @file GenUGraph.H 00034 * @brief Header file of class qgar::GenUGraph. 00035 * 00036 * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Gérald Masini">Gérald Masini</a> 00037 * @date July 29, 2004 17:18 00038 * @since Qgar 2.2 00039 */ 00040 00041 00042 00043 // For RCS/CVS use: Do not delete 00044 /* $Id: GenUGraph.H,v 1.6 2005/10/14 17:05:46 masini Exp $ */ 00045 00046 00047 00048 // STD 00049 #include <list> 00050 // QGAR 00051 #include <qgarlib/GenEdge.H> 00052 #include <qgarlib/GenNode.H> 00053 00054 00055 00056 namespace qgar 00057 { 00058 00059 00060 /** 00061 * @ingroup DS_GRAPH 00062 * 00063 * @class GenUGraph GenUGraph.H "qgarlib/GenUGraph.H" 00064 * 00065 * @brief Parameterized undirected graph. 00066 * 00067 * A node is described by class qgar::GenNode. It contains: 00068 * 00069 * - an object of type <b>TNODE</b>, called the <i>node type</i>, 00070 * - an <b>integer</b> flag, at client's disposal, 00071 * - a STL list of (pointers to) edges adjacent to the node. 00072 * 00073 * An edge is described by class qgar::GenEdge. It contains: 00074 * 00075 * - an object of type <b>TEDGE</b>, called the <i>edge type</i>, 00076 * - an <b>integer</b> flag, at client's disposal, 00077 * - two (pointers to its) adjacent nodes, arbitrarily called 00078 * <i>source</i> and <i>target</i> nodes. 00079 * 00080 * A graph is represented as: 00081 * 00082 * - A STL list of pointers to its nodes, called the <i>nodes list</i>. 00083 * The first node of the list is called the <i>entry</i> node. 00084 * - A STL list of pointers to its edges called the <i>edges list</i>. 00085 * The first edge of the list is called the <i>entry</i> edge. 00086 * 00087 * Partially inspired by the LEDA library (when it was a free software). 00088 * See <a href="http://www.mpi-sb.mpg.de/LEDA/" target="_blank">http://www.mpi-sb.mpg.de/LEDA/</a>. 00089 * 00090 * @warning 00091 * 00092 * <ul> 00093 * 00094 * <li><p> 00095 * The class is not supposed to be derived: No function 00096 * member (destructor or whatever else) is virtual. 00097 * </p></li> 00098 * 00099 * <li><p> 00100 * Neither copy constructor nor assignment operator are defined. 00101 * </p></li> 00102 * 00103 * <li><p> 00104 * <b>For efficiency reasons, the validity of pointers given as 00105 * arguments to function members is not checked.</b> 00106 * In particular: 00107 * - pointers may be equal to <b>0</b>, which will undoubtedly be 00108 * the cause of a further program abortion, 00109 * - pointed nodes or edges may not belong to the current graph, 00110 * with similar consequences. 00111 * </p></li> 00112 * 00113 * <li><p> 00114 * <b>The deletion of a graph causes the deletion of all its nodes and 00115 * edges.</b> Consequently, a program abortion may occur when: 00116 * - a (pointer to a) same node or a same edge belongs 00117 * to different graphs, 00118 * - the nodes (resp. edges) list of a graph contains multiple 00119 * occurrences of (pointers to) a same node (resp. edge), or 00120 * contains null pointers, 00121 * - nodes (resp. edges) of the nodes (resp. edges) list of a 00122 * graph are explicitely deleted, using operator <tt>delete</tt>, 00123 * before exiting the block of program containing the graph, 00124 * - local variables are used to insert nodes (resp. edges) 00125 * in a graph, for example: 00126 @code 00127 GenUGraph<int,int> g; 00128 GenNode<int,int> n(1); 00129 GenEdge<int,int> e(1); 00130 00131 g.addNode(&n); // prohibited! 00132 g.addEdge(&e); // prohibited! 00133 @endcode 00134 * </p></li> 00135 * 00136 * </ul> 00137 * 00138 * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Gérald Masini">Gérald Masini</a> 00139 * @date July 29, 2004 17:18 00140 * @since Qgar 2.2 00141 */ 00142 template <class TNODE, class TEDGE> 00143 class GenUGraph 00144 { 00145 // ------------------------------------------------------------------- 00146 // T Y P E D E F I N I T I O N S 00147 // ------------------------------------------------------------------- 00148 public: 00149 00150 /** @name Types */ 00151 // ===== 00152 //@{ 00153 00154 /** 00155 * @brief Type of the data stored in a node. 00156 */ 00157 typedef TNODE node_type; 00158 00159 /** 00160 * @brief Reference to qgar::GenUGraph::node_type. 00161 */ 00162 typedef node_type& node_type_reference; 00163 00164 /** 00165 * @brief Constant reference to qgar::GenUGraph::node_type. 00166 */ 00167 typedef const node_type& node_type_const_reference; 00168 00169 /** 00170 * @brief Pointer to qgar::GenUGraph::node_type. 00171 */ 00172 typedef node_type* node_type_pointer; 00173 00174 /** 00175 * @brief Constant pointer to qgar::GenUGraph::node_type. 00176 */ 00177 typedef const node_type* node_type_const_pointer; 00178 00179 /** 00180 * @brief Type of the data stored in an edge. 00181 */ 00182 typedef TEDGE edge_type; 00183 00184 /** 00185 * @brief Reference to qgar::GenUGraph::edge_type. 00186 */ 00187 typedef edge_type& edge_type_reference; 00188 00189 /** 00190 * @brief Constant reference to qgar::GenUGraph::edge_type. 00191 */ 00192 typedef const edge_type& edge_type_const_reference; 00193 00194 /** 00195 * @brief Pointer to qgar::GenUGraph::edge_type. 00196 */ 00197 typedef edge_type* edge_type_pointer; 00198 00199 /** 00200 * @brief Constant pointer to qgar::GenUGraph::edge_type. 00201 */ 00202 typedef const edge_type* edge_type_const_pointer; 00203 00204 /** 00205 * @brief Type of the nodes list. 00206 */ 00207 typedef std::list< GenNode<node_type,edge_type>* > nodes_list_type; 00208 00209 /** 00210 * @brief Type of the edges list. 00211 */ 00212 typedef std::list< GenEdge<node_type,edge_type>* > edges_list_type; 00213 00214 //@} 00215 00216 00217 // ------------------------------------------------------------------- 00218 // P U B L I C M E M B E R S 00219 // ------------------------------------------------------------------- 00220 public: 00221 00222 00223 /** @name Constructors */ 00224 // ============ 00225 //@{ 00226 00227 /** 00228 * @brief Default constructor. 00229 * 00230 * Edges and nodes lists are empty. 00231 */ 00232 GenUGraph(); 00233 00234 /** 00235 * @brief Initialize from (a pointer to) a node. 00236 * 00237 * @param aPNode a pointer to a node: <b>must not be 0!</b> 00238 */ 00239 GenUGraph(GenNode<node_type,edge_type>* const aPNode); 00240 00241 /** 00242 * @brief Initialize from (a pointer to) an edge. 00243 * 00244 * @param aPEdge a pointer to an edge: <b>must not be 0!</b> 00245 */ 00246 GenUGraph(GenEdge<node_type,edge_type>* const aPEdge); 00247 00248 ///** 00249 // * @brief Copy constructor. 00250 // * 00251 // * @warning No copy constructor is defined. 00252 // */ 00253 //GenUGraph(const GenUGraph<node_type,edge_type>& aGraph); 00254 00255 //@} 00256 00257 00258 /** @name Destructor */ 00259 // ========== 00260 //@{ 00261 00262 /** 00263 * @brief Virtual destructor. 00264 */ 00265 virtual ~GenUGraph(); 00266 00267 //@} 00268 00269 00270 /** @name Graph characteristics */ 00271 // ===================== 00272 //@{ 00273 00274 /** 00275 * @brief Return <b>true</b> if the graph is empty. 00276 */ 00277 inline bool empty() const; 00278 00279 /** 00280 * @brief Return the number of nodes. 00281 */ 00282 inline int sizeNodes() const; 00283 00284 /** 00285 * @brief Return the number of edges. 00286 */ 00287 inline int sizeEdges() const; 00288 00289 //@} 00290 00291 00292 /** @name Node access */ 00293 // =========== 00294 //@{ 00295 /** 00296 * @brief Return a pointer to the entry node, 00297 * or <b>0</b> if the nodes list is empty. 00298 */ 00299 inline GenNode<node_type,edge_type>* pEntryNode() const; 00300 00301 /** 00302 * @brief Get the nodes list. 00303 */ 00304 inline nodes_list_type& getNodes(); 00305 00306 /** 00307 * @brief Get (a constant reference to) the nodes list. 00308 */ 00309 inline const nodes_list_type& accessNodes() const; 00310 00311 /** 00312 * @brief Get a copy of the nodes list. 00313 */ 00314 inline nodes_list_type nodes() const; 00315 00316 //@} 00317 00318 00319 /** @name Edge access */ 00320 // =========== 00321 //@{ 00322 00323 /** 00324 * @brief Get a pointer to the entry edge, 00325 * or <b>0</b> if the edges list is empty. 00326 */ 00327 inline GenEdge<node_type,edge_type>* pEntryEdge() const; 00328 00329 /** 00330 * @brief Get the edges list. 00331 */ 00332 inline edges_list_type& getEdges(); 00333 00334 /** 00335 * @brief Get (a constant reference to) the edges list. 00336 */ 00337 inline const edges_list_type& accessEdges() const; 00338 00339 /** 00340 * @brief Get a copy of the edges list. 00341 */ 00342 inline edges_list_type edges() const; 00343 00344 //@} 00345 00346 00347 /** @name Insertion of created nodes */ 00348 // ========================== 00349 //@{ 00350 /** 00351 * @brief Just insert a new node created from given data and flag. 00352 * 00353 * The (pointer to the) node is just inserted in the nodes list 00354 * of the graph, and is not connected to any edge. 00355 * 00356 * @param aData data to be contained in the node 00357 * @param aFlag value of the node flag (default <b>0</b>) 00358 * 00359 * @return A pointer to the new node. 00360 */ 00361 inline GenNode<node_type,edge_type>* 00362 addNode(node_type_const_reference aData, short int aFlag = 0); 00363 00364 /** 00365 * @brief Insert a new node and link it to given edge of the graph. 00366 * 00367 * The (pointer to the) node is inserted in the nodes list of the graph. 00368 * The (pointer to the) edge is inserted in the edges list of the node. 00369 * The new node becomes the source of the given edge if the source 00370 * is free, otherwise it becomes the target of the edge. 00371 * 00372 * @param aPEdge pointer to an edge: <b>must not be 0!</b> 00373 * @param aData data to be contained in the node 00374 * @param aFlag value of the node flag (default <b>0</b>) 00375 * 00376 * @return A pointer to the new node. 00377 * 00378 * @warning 00379 * <b>The given (pointed) edge must belong to the graph.</b> 00380 */ 00381 inline GenNode<node_type,edge_type>* 00382 addNode(GenEdge<node_type,edge_type>* const aPEdge, 00383 node_type_const_reference aData, 00384 short int aFlag = 0); 00385 00386 /** 00387 * @brief Insert a new node between given edges of the graph. 00388 * 00389 * The (pointer to the) node is inserted in the nodes list of the graph. 00390 * The (pointers to the) edges are inserted in the edges list of the node. 00391 * The new node becomes the source of the first (resp. second) edge 00392 * if the source is free, otherwise it becomes the target of the first 00393 * (resp. second) edge. 00394 * 00395 * @param aPEdge1 pointer to an edge: <b>must not be 0!</b> 00396 * @param aPEdge2 pointer to an edge: <b>must not be 0!</b> 00397 * @param aData data to be contained in the node 00398 * @param aFlag value of the node flag (default <b>0</b>) 00399 * 00400 * @return A pointer to the new node. 00401 * 00402 * @warning 00403 * <b>The 2 given (pointed) edges must belong to the graph.</b> 00404 */ 00405 inline GenNode<node_type,edge_type>* 00406 addNode(GenEdge<node_type,edge_type>* const aPEdge1, 00407 GenEdge<node_type,edge_type>* const aPEdge2, 00408 node_type_const_reference aData, 00409 short int aFlag = 0); 00410 00411 /** 00412 * @brief Insert a new node as source of given edge of the graph. 00413 * 00414 * - The node is inserted in the nodes list of the graph. 00415 * - The edge is included in the edges list of the node. 00416 * - The node becomes the source of the edge. 00417 * 00418 * @param aPEdge pointer to an edge: <b>must not be 0!</b> 00419 * @param aData data to be contained in the node 00420 * @param aFlag value of the node flag (default <b>0</b>) 00421 * 00422 * @return A pointer to the node. 00423 * 00424 * @warning 00425 * <b>The given (pointed) edge must belong to the graph.</b> 00426 */ 00427 GenNode<node_type,edge_type>* 00428 addNodeAtSource(GenEdge<node_type,edge_type>* const aPEdge, 00429 node_type_const_reference aData, 00430 short int aFlag = 0); 00431 00432 /** 00433 * @brief Insert a new node as target of given edge of the graph. 00434 * 00435 * - The node is inserted in the nodes list of the graph. 00436 * - The edge is included in the edges list of the node. 00437 * - The node becomes the target of the edge. 00438 * 00439 * @param aPEdge pointer to an edge: <b>must not be 0!</b> 00440 * @param aData data to be contained in the node 00441 * @param aFlag value of the node flag (default <b>0</b>) 00442 * 00443 * @return A pointer to the node. 00444 * 00445 * @warning 00446 * <b>The given (pointed) edge must belong to the graph.</b> 00447 */ 00448 GenNode<node_type,edge_type>* 00449 addNodeAtTarget(GenEdge<node_type,edge_type>* const aPEdge, 00450 node_type_const_reference aData, 00451 short int aFlag = 0); 00452 00453 //@} 00454 00455 00456 /** @name Insertion of existing nodes */ 00457 // =========================== 00458 //@{ 00459 00460 /** 00461 * @brief Just insert (a pointer to) a node in the graph. 00462 * 00463 * The (pointer to the) node is just inserted in the nodes list 00464 * of the graph, and is not connected to any edge. 00465 * 00466 * @param aPNode a pointer to a node: <b>must not be 0!</b> 00467 * 00468 * @return A pointer to the node. 00469 * 00470 * @warning 00471 * <b>The given (pointed) node must not belong to the graph.</b> 00472 */ 00473 inline GenNode<node_type,edge_type>* 00474 addNode(GenNode<node_type,edge_type>* const aPNode); 00475 00476 /** 00477 * @brief Insert given (pointer to) node in the graph, 00478 * as source or target of given (pointed) edge. 00479 * 00480 * The given edge is supposed to belong to the current graph: 00481 * - The node is inserted in the nodes list of the graph. 00482 * - The edge is inserted in the edges list of the node. 00483 * - <b>The node becomes the source of the edge if the edge 00484 * source is free. Otherwise, the node becomes the target.</b> 00485 * 00486 * @param aPNode pointer to a node: <b>must not be 0!</b> 00487 * @param aPEdge pointer to an edge: <b>must not be 0!</b> 00488 * 00489 * @return A pointer to the node. 00490 * 00491 * @warning 00492 * - <b>The given (pointed) node must not belong to the graph.</b> 00493 * - <b>The given (pointed) edge must belong to the graph.</b> 00494 */ 00495 GenNode<node_type,edge_type>* 00496 addNode(GenNode<node_type,edge_type>* const aPNode, 00497 GenEdge<node_type,edge_type>* const aPEdge); 00498 00499 /** 00500 * @brief Insert a node between two given edges of the graph. 00501 * 00502 * The given edges are supposed to belong to the current graph: 00503 * - The node is inserted in the nodes list of the graph. 00504 * - The edges are included in the edges list of the node. 00505 * - The node becomes the source of the first (resp. second) 00506 * edge, if the edge source is free. Otherwise, the node 00507 * becomes the target of the first (resp. second) edge. 00508 * 00509 * @param aPNode pointer to a node: <b>must not be 0!</b> 00510 * @param aPEdge1 pointer to an edge: <b>must not be 0!</b> 00511 * @param aPEdge2 pointer to an edge: <b>must not be 0!</b> 00512 * 00513 * @return A pointer to the node. 00514 * 00515 * @warning 00516 * - <b>The given (pointed) node must not belong to the graph.</b> 00517 * - <b>The given (pointed) edges must belong to the graph.</b> 00518 */ 00519 GenNode<node_type,edge_type>* 00520 addNode(GenNode<node_type,edge_type>* const aPNode, 00521 GenEdge<node_type,edge_type>* const aPEdge1, 00522 GenEdge<node_type,edge_type>* const aPEdge2); 00523 00524 /** 00525 * @brief Insert given node as source of given edge of the graph. 00526 * 00527 * The given edge is supposed to belong to the current graph: 00528 * - The node is inserted in the nodes list of the graph. 00529 * - The edge is included in the edges list of the node. 00530 * - The node becomes the source of the edge. 00531 * 00532 * @param aPNode pointer to a node: <b>must not be 0!</b> 00533 * @param aPEdge pointer to an edge: <b>must not be 0!</b> 00534 * 00535 * @return A pointer to the node. 00536 * 00537 * @warning 00538 * - <b>The given (pointed) node must not belong to the graph.</b> 00539 * - <b>The given (pointed) edge must belong to the graph.</b> 00540 */ 00541 GenNode<node_type,edge_type>* 00542 addNodeAtSource(GenNode<node_type,edge_type>* const aPNode, 00543 GenEdge<node_type,edge_type>* const aPEdge); 00544 00545 /** 00546 * @brief Insert given node as target of given edge of the graph. 00547 * 00548 * The given edge is supposed to belong to the current graph: 00549 * - The node is inserted in the nodes list of the graph. 00550 * - The edge is included in the edges list of the node. 00551 * - The node becomes the target of the edge. 00552 * 00553 * @param aPNode pointer to a node: <b>must not be 0!</b> 00554 * @param aPEdge pointer to an edge: <b>must not be 0!</b> 00555 * 00556 * @return A pointer to the node. 00557 * 00558 * @warning 00559 * - <b>The given (pointed) node must not belong to the graph.</b> 00560 * - <b>The given (pointed) edge must belong to the graph.</b> 00561 */ 00562 GenNode<node_type,edge_type>* 00563 addNodeAtTarget(GenNode<node_type,edge_type>* const aPNode, 00564 GenEdge<node_type,edge_type>* const aPEdge); 00565 //@} 00566 00567 00568 /** @name Insertion of created edges */ 00569 // ========================== 00570 //@{ 00571 /** 00572 * @brief Just insert a new edge created from given data and flag. 00573 * 00574 * The (pointer to the) edge is just inserted in the edges list 00575 * of the graph, and is not connected to any node. 00576 * 00577 * @param aData data to be contained in the edge 00578 * @param aFlag value of the edge flag (default <b>0</b>) 00579 * 00580 * @return a pointer to the new edge. 00581 */ 00582 inline GenEdge<node_type,edge_type>* 00583 addEdge(edge_type_const_reference aData, 00584 short int aFlag = 0); 00585 00586 /** 00587 * @brief Insert a new edge in the graph, so that given (pointed) 00588 * node becomes its source. 00589 * 00590 * The (pointer to the) new edge is inserted in the edges list 00591 * of the node, and in the edges list of the graph. 00592 * The given node becomes the source of the new edge. 00593 * 00594 * @param aPNode pointer to a node: <b>must not be 0!</b> 00595 * @param aData data to be contained in the edge 00596 * @param aFlag value of the edge flag (default <b>0</b>) 00597 * 00598 * @return A pointer to the new edge. 00599 * 00600 * @warning 00601 * <b>The given (pointed) node must belong to the graph.</b> 00602 */ 00603 inline GenEdge<node_type,edge_type>* 00604 addEdge(GenNode<node_type,edge_type>* const aPNode, 00605 edge_type_const_reference aData, 00606 short int aFlag = 0); 00607 00608 /** 00609 * @brief Insert an new edge between two given nodes of the graph. 00610 * 00611 * An edge is created, with (pointers to) nodes <b>aPSource</b> 00612 * and <b>aPTarget</b> as source and target, respectively. 00613 * The new edge is inserted in the edges list of both nodes, 00614 * and in the edges list of the graph. 00615 * 00616 * @param aPSource pointer to a node: <b>must not be 0!</b> 00617 * @param aPTarget pointer to a node: <b>must not be 0!</b> 00618 * @param aData data to be contained in the edge 00619 * @param aFlag value of the node flag (default <b>0</b>) 00620 * 00621 * @return A pointer to the new edge. 00622 * 00623 * @warning 00624 * <b>The given (pointed) nodes must belong to the graph.</b> 00625 */ 00626 inline GenEdge<node_type,edge_type>* 00627 addEdge(GenNode<node_type,edge_type>* const aPSource, 00628 GenNode<node_type,edge_type>* const aPTarget, 00629 edge_type_const_reference aData, 00630 short int aFlag = 0); 00631 //@} 00632 00633 00634 /** @name Insertion of existing edges */ 00635 // =========================== 00636 //@{ 00637 /** 00638 * @brief Insert (a pointer to) an edge in the graph. 00639 * 00640 * The (pointer to the) edge is just inserted in the edges list 00641 * of the graph, and is not connected to any node. 00642 * 00643 * @param aPEdge a pointer to an edge: <b>must not be 0!</b> 00644 * 00645 * @return A pointer to the new edge. 00646 * 00647 * @warning 00648 * <b>The given (pointed) edge must not belong to the graph.</b> 00649 */ 00650 inline GenEdge<node_type,edge_type>* 00651 addEdge(GenEdge<node_type,edge_type>* const aPEdge); 00652 00653 /** 00654 * @brief Insert given (pointer to) edge in the graph, 00655 * so as given (pointed) node becomes its source or its target. 00656 * 00657 * The given node is supposed to belong to the graph: 00658 * - The edge is inserted in the edges list of the graph. 00659 * - The edge is inserted in the edges list of the node. 00660 * - <b>The node becomes the source of the edge if the 00661 * source is free. Otherwise, the node becomes the target.</b> 00662 * 00663 * @param aPNode pointer to a node: <b>must not be 0!</b> 00664 * @param aPEdge pointer to an edge: <b>must not be 0!</b> 00665 * 00666 * @return A pointer to the edge. 00667 * 00668 * @warning 00669 * - <b>The given (pointed) edge must not belong to the graph.</b> 00670 * - <b>The given (pointed) node must belong to the graph.</b> 00671 */ 00672 GenEdge<node_type,edge_type>* 00673 addEdge(GenEdge<node_type,edge_type>* const aPEdge, 00674 GenNode<node_type,edge_type>* const aPNode); 00675 00676 /** 00677 * @brief Insert an edge between two given nodes of the graph. 00678 * 00679 * The given nodes are supposed to belong to the current graph: 00680 * - The edge is included in the edges list of the graph. 00681 * - The first (resp. second) node becomes the source 00682 * (resp. target) of the edge. 00683 * - The edge is inserted in the edges lists of the nodes. 00684 * 00685 * @param aPEdge pointer to an edge: <b>must not be 0!</b> 00686 * @param aPNode1 pointer to a node: <b>must not be 0!</b> 00687 * @param aPNode2 pointer to a node: <b>must not be 0!</b> 00688 * 00689 * @return A pointer to the node. 00690 * 00691 * @warning 00692 * - <b>The given (pointed) edge must not belong to the graph.</b> 00693 * - <b>The given (pointed) nodes must belong to the graph.</b> 00694 */ 00695 GenEdge<node_type,edge_type>* 00696 addEdge(GenEdge<node_type,edge_type>* const aPEdge, 00697 GenNode<node_type,edge_type>* const aPNode1, 00698 GenNode<node_type,edge_type>* const aPNode2); 00699 00700 /** 00701 * @brief Insert given (pointer to) edge in the graph, 00702 * so as given (pointed) node becomes its source. 00703 * 00704 * The given node is supposed to belong to the graph: 00705 * - The edge is inserted in the edges list of the graph. 00706 * - The edge is inserted in the edges list of the node. 00707 * - The node becomes the source of the given edge. 00708 * 00709 * @param aPEdge pointer to an edge: <b>must not be 0!</b> 00710 * @param aPNode pointer to a node: <b>must not be 0!</b> 00711 * 00712 * @return A pointer to the node. 00713 * 00714 * @warning 00715 * - <b>The given (pointed) edge must not belong to the graph.</b> 00716 * - <b>The given (pointed) node must belong to the graph.</b> 00717 */ 00718 GenEdge<node_type,edge_type>* 00719 addEdgeBySource(GenEdge<node_type,edge_type>* const aPEdge, 00720 GenNode<node_type,edge_type>* const aPNode); 00721 00722 /** 00723 * @brief Insert given (pointer to) edge in the graph, 00724 * so as given (pointed) node becomes its target. 00725 * 00726 * The given node is supposed to belong to the graph: 00727 * - The edge is inserted in the edges list of the graph. 00728 * - The edge is inserted in the edges list of the node. 00729 * - The node becomes the target of the edge. 00730 * 00731 * @param aPEdge pointer to an edge 00732 * @param aPNode pointer to a node 00733 * 00734 * @return A pointer to the node. 00735 * 00736 * @warning 00737 * - <b>The given (pointed) edge must not belong to the graph.</b> 00738 * - <b>The given (pointed) node must belong to the graph.</b> 00739 */ 00740 GenEdge<node_type,edge_type>* 00741 addEdgeByTarget(GenEdge<node_type,edge_type>* const aPEdge, 00742 GenNode<node_type,edge_type>* const aPNode); 00743 00744 //@} 00745 00746 00747 // ========================================================= 00748 /** @name Node removal 00749 <b>Warning:</b> The user is in charge of the deletion of 00750 the removed nodes. 00751 */ 00752 // ========================================================= 00753 //@{ 00754 00755 /** 00756 * @brief Remove given (pointer to) node from the graph, 00757 * and return it. 00758 * 00759 * If the given (pointer to) node is not in the nodes list 00760 * of the graph, the graph remains unchanged and the function 00761 * returns <b>0</b>. Otherwise, each edge adjacent to the given 00762 * node is removed from the graph, and the given node is removed 00763 * from the nodes list of the graph. 00764 * 00765 * @param aPNode a pointer to a node: <b>must not be 0!</b> 00766 * 00767 * @return A pointer to the removed node. 00768 * 00769 * @warning 00770 * - <b>Each edge adjacent to the removed node is deleted.</b> 00771 * - The edges list of the returned (pointed) node is cleared. 00772 */ 00773 inline GenNode<node_type,edge_type>* 00774 remove(GenNode<node_type,edge_type>* const aPNode); 00775 00776 /** 00777 * @brief Remove (pointer to) node at given position in the nodes 00778 * list of the graph, and return it. 00779 * 00780 * If the given position is the end of the nodes list of the graph, 00781 * the graph remains unchanged and the function returns <b>0</b>. 00782 * Otherwise, each edge adjacent to the given node is removed from 00783 * the graph, and the given node is removed from the nodes list 00784 * of the graph. 00785 * 00786 * @param aPos a position in the nodes list of the graph 00787 * 00788 * @return A pointer to the removed node. 00789 * 00790 * @warning 00791 * - <b>Each edge adjacent to the removed node is deleted.</b> 00792 * - The edges list of the returned (pointed) node is cleared. 00793 * 00794 * @todo 00795 * Maybe the way adjacent edges of the nodes are deleted 00796 * could be more efficient. In particular, the use of function 00797 * qgar::GenUGraph::removeEdge implies: 00798 * - a copy of the edges list of the current node, 00799 * - an update of the edges list of the current node each time 00800 * an edge is removed from the graph, whereas this edges list 00801 * could be cleared in one time, once all edges are removed. 00802 */ 00803 GenNode<node_type,edge_type>* 00804 remove(typename nodes_list_type::iterator aPos); 00805 00806 //@} 00807 00808 00809 // ========================================================= 00810 /** @name Edge removal 00811 <b>Warning:</b> The user is in charge of the deletion of 00812 the removed edges. 00813 */ 00814 // ========================================================= 00815 //@{ 00816 00817 /** 00818 * @brief Remove given (pointer to) edge from the graph, 00819 * and return it. 00820 * 00821 * If the given (pointer to) edge is not in the edges list of the 00822 * graph, the graph remains unchanged and the function returns 00823 * <b>0</b>. Otherwise, the given edge is removed from the edges 00824 * list of its source and target nodes, and is removed from the 00825 * edges list of the graph. 00826 * 00827 * @param aPEdge a pointer to an edge: <b>should not be 0!</b> 00828 * 00829 * @return A pointer to the removed edge. 00830 */ 00831 inline GenEdge<node_type,edge_type>* 00832 remove(GenEdge<node_type,edge_type>* const aPEdge); 00833 00834 /** 00835 * @brief Remove (pointer to) edge at given position in the edges 00836 * list of the graph, and return it. 00837 * 00838 * If the given position is the end of the edges list of the graph, 00839 * the graph remains unchanged and the function returns <b>0</b>. 00840 * Otherwise, the given edge is removed from the edges list of its 00841 * source and target nodes, and is removed from the edges list of 00842 * the graph. 00843 * 00844 * @param aPos a position in the edges list of the graph 00845 * 00846 * @return a pointer to the removed edge. 00847 */ 00848 GenEdge<node_type,edge_type>* 00849 remove(typename edges_list_type::iterator aPos); 00850 //@} 00851 00852 00853 ///** @name Operators */ 00854 //// ========== 00855 ////@{ 00856 // 00857 ///** 00858 // * @brief Assignment. 00859 // * @warning No assignment operator is defined. 00860 // */ 00861 //GenUGraph<node_type,edge_type>& 00862 //operator=(const GenUGraph<node_type,edge_type>& aGraph); 00863 // 00864 ////@} 00865 00866 00867 // ------------------------------------------------------------------- 00868 // P R O T E C T E D M E M B E R S 00869 // ------------------------------------------------------------------- 00870 protected: 00871 00872 00873 /** @name Nodes and edges lists */ 00874 // ===================== 00875 //@{ 00876 00877 /** 00878 * @brief List of the nodes of the graph. 00879 */ 00880 nodes_list_type _nodes; 00881 00882 /** 00883 * @brief List of the edges of the graph. 00884 */ 00885 edges_list_type _edges; 00886 00887 //@} 00888 00889 00890 // ------------------------------------------------------------------- 00891 }; // class GenUGraph 00892 00893 00894 } // namespace qgar 00895 00896 00897 00898 00899 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 00900 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 00901 // I M P L E M E N T A T I O N 00902 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 00903 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 00904 00905 #include <qgarlib/GenUGraph.TCC> 00906 00907 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 00908 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 00909 00910 00911 00912 00913 #endif /* __GENUGRAPH_H_INCLUDED__ */