Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

GenNode.H

Go to the documentation of this file.
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 __GENNODE_H_INCLUDED__
00029 #define __GENNODE_H_INCLUDED__
00030 
00031 
00032 /**
00033  * @file   GenNode.H
00034  * @brief  Header file of class qgar::GenNode.
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.1.2
00039  */
00040 
00041 
00042 // For RCS/CVS use: Do not delete
00043 /* $Id: GenNode.H,v 1.4 2005/07/13 16:29:01 masini Exp $ */
00044 
00045 
00046 
00047 // STD
00048 #include <list>
00049 // QGAR
00050 #include <qgarlib/GenEdge.H>
00051 
00052 
00053 
00054 namespace qgar
00055 {
00056 
00057 
00058 /**
00059  * @ingroup DS_GRAPH
00060  * @class GenNode GenNode.H "qgarlib/GenNode.H"
00061  * @brief Node of a parameterized graph containing (user-defined) data.
00062  *
00063  * A node includes:
00064  *
00065  * - an object of type <b>TNODE</b>, called the <i>node type</i>,
00066  * - an <b>integer</b> flag, that any client may use
00067  *   for own specific purposes,
00068  * - a STL list of pointers to the edges which are adjacent to the node,
00069  *   called the <i>edges list</i>.
00070  *
00071  * See class qgar::GenEdge for edges.
00072  *
00073  * @warning
00074  * - The class is not supposed to be derived: No function
00075  *   member (destructor or whatever else) is virtual.
00076  * - <b>For efficiency reasons, the validity of pointers (to edges)
00077  *   given as arguments to constructors and other function members
00078  *   is not checked. In particular, they may be <i>null</i>, which
00079  *   will undoubtedly be the cause of a further program abortion.</b>
00080  *
00081  * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Gérald Masini">Gérald Masini</a>
00082  * @date   July 29, 2004  17:18
00083  * @since  Qgar 2.1.2
00084  */
00085 template <class TNODE, class TEDGE> class GenNode
00086 {
00087 // -------------------------------------------------------------------
00088 // T Y P E   D E F I N I T I O N S
00089 // -------------------------------------------------------------------
00090 public:
00091 
00092   /** @name Types */
00093   //        =====
00094   //@{
00095 
00096   /**
00097    * @brief Type of the data stored in an edge.
00098    */
00099   typedef TEDGE edge_type;
00100 
00101   /**
00102    * @brief Reference to qgar::GenEdge::edge_type.
00103    */
00104   typedef edge_type& edge_type_reference;
00105 
00106   /**
00107    * @brief Constant reference to qgar::GenEdge::edge_type.
00108    */
00109   typedef const edge_type& edge_type_const_reference;
00110 
00111   /**
00112    * @brief Pointer to qgar::GenEdge::edge_type.
00113    */
00114   typedef edge_type* edge_type_pointer;
00115 
00116   /**
00117    * @brief Constant pointer to qgar::GenEdge::edge_type.
00118    */
00119   typedef const edge_type* edge_type_const_pointer;
00120 
00121   /**
00122    * @brief Type of the data stored in a node.
00123    */
00124   typedef TNODE node_type;
00125 
00126   /**
00127    * @brief Reference to qgar::GenEdge::node_type.
00128    */
00129   typedef node_type& node_type_reference;
00130 
00131   /**
00132    * @brief Constant reference to qgar::GenEdge::node_type.
00133    */
00134   typedef const node_type& node_type_const_reference;
00135 
00136   /**
00137    * @brief Pointer to qgar::GenEdge::node_type.
00138    */
00139   typedef node_type* node_type_pointer;
00140 
00141   /**
00142    * @brief Constant pointer to qgar::GenEdge::node_type.
00143    */
00144   typedef const node_type* node_type_const_pointer;
00145 
00146   //@}
00147 
00148 
00149 // -------------------------------------------------------------------
00150 // P U B L I C    M E M B E R S
00151 // -------------------------------------------------------------------
00152 public:
00153 
00154 
00155   /** @name Constructors */
00156   //        ============
00157   //@{
00158 
00159   /**
00160    * @brief Default constructor.
00161    *
00162    * The edges list of the node is empty.
00163    *
00164    * @param  aFlag  value of the node flag (default <b>0</b>)
00165    */
00166   GenNode(short int aFlag = 0);
00167 
00168   /**
00169    * @brief Initialize with data.
00170    *
00171    * The edges list of the node is empty.
00172    *
00173    * @param  aData  data to be contained in the node
00174    * @param  aFlag  value of the node flag (default <b>0</b>)
00175    */
00176   GenNode(node_type_const_reference aData,
00177           short int aFlag = 0);
00178 
00179   /**
00180    * @brief Initialize with a pointer to an edge, and data.
00181    *
00182    * The pointer to the edge is inserted in the edges list of the node.
00183    *
00184    * @param  aPEdge  pointer to an edge: <b>Should not be 0!</b>
00185    * @param  aData   data to be contained in the node
00186    * @param  aFlag   value of the node flag (default <b>0</b>)
00187    */
00188   GenNode(GenEdge<node_type,edge_type>* const aPEdge,
00189           node_type_const_reference aData,
00190           short int aFlag = 0);
00191 
00192   /**
00193    * @brief Initialize with two pointers to an edge, and data.
00194    *
00195    * The pointers to edges are inserted in the edges list of the node.
00196    *
00197    * @param  aPEdge1  pointer to an edge <b>Should not be 0!</b>
00198    * @param  aPEdge2  pointer to an edge <b>Should not be 0!</b>
00199    * @param  aData    data to be contained in the node
00200    * @param  aFlag    value of the node flag (default <b>0</b>)
00201    */
00202   GenNode(GenEdge<node_type,edge_type>* const aPEdge1,
00203           GenEdge<node_type,edge_type>* const aPEdge2,
00204           node_type_const_reference aData,
00205           short int aFlag = 0);
00206 
00207   /**
00208    * @brief Initialize with three pointers to an edge, and data.
00209    *
00210    * The pointers to edges are inserted in the edges list of the node.
00211    *
00212    * @param  aPEdge1  pointer to an edge <b>Should not be 0!</b>
00213    * @param  aPEdge2  pointer to an edge <b>Should not be 0!</b>
00214    * @param  aPEdge3  pointer to an edge <b>Should not be 0!</b>
00215    * @param  aData    data to be contained in the node
00216    * @param  aFlag    value of the node flag (default <b>0</b>)
00217    */
00218   GenNode(GenEdge<node_type,edge_type>* const aPEdge1,
00219           GenEdge<node_type,edge_type>* const aPEdge2,
00220           GenEdge<node_type,edge_type>* const aPEdge3,
00221           node_type_const_reference aData,
00222           short int aFlag = 0);
00223 
00224   /**
00225    * @brief Copy constructor.
00226    *
00227    * @param  aNode  a node to be copied
00228    *
00229    * @warning The constructor performs a shallow copy:
00230    * The edges adjacent to the node are not duplicated.
00231    *
00232    * @todo This constructor performs a shallow copy.
00233    * Could it perform a deep copy? Edges adjacent to the node
00234    * would thus be copied, and then all nodes adjacent to these
00235    * edges, and the edges adjacent to these nodes... and then
00236    * the whole graph!
00237    */
00238   GenNode(const GenNode<node_type,edge_type>& aNode);
00239 
00240   //@}
00241 
00242 
00243   /** @name Destructor */
00244   //        ==========
00245   //@{
00246 
00247   /**
00248    * @brief Non-virtual destructor.
00249    */
00250   ~GenNode();
00251 
00252   //@}
00253 
00254 
00255   /** @name Node characteristics */
00256   //        ====================
00257 
00258   //@{
00259    /**
00260    * @brief Get node degree (number of edges adjacent to the node).
00261    */
00262   inline int degree() const;
00263 
00264   //@}
00265 
00266 
00267   /** @name Node data */
00268   //        =========
00269   //@{
00270 
00271   /**
00272    * @brief Get node data.
00273     */
00274   inline node_type_const_reference accessData() const;
00275 
00276    /**
00277     * @brief Get a copy of the node data.
00278     */
00279   inline node_type data() const;
00280 
00281   /**
00282    * @brief Set node data.
00283    *
00284    * @param  aData  data to be contained in the node
00285    */
00286   inline void setData(node_type_const_reference aData);
00287 
00288   /**
00289    * @brief Get node flag.
00290    */
00291   inline short int flag() const;
00292 
00293   /**
00294    * @brief Set node flag.
00295    *
00296    * @param aFlag  value to assign to the flag
00297    */
00298   inline void setFlag(short int aFlag);
00299 
00300   //@}
00301 
00302 
00303   /** @name Access to edges */
00304   //        ===============
00305   //@{
00306 
00307   /**
00308    * @brief Get (a constant reference to) the edges list.
00309    */
00310   inline const std::list< GenEdge<node_type,edge_type>* >&
00311   accessEdges() const;
00312 
00313   /**
00314    * @brief Get the edges list.
00315    */
00316   inline std::list< GenEdge<node_type,edge_type>* >& getEdges();
00317 
00318   /**
00319    * @brief Get a copy of the edges list.
00320    */
00321   inline std::list< GenEdge<node_type,edge_type>* > edges() const;
00322 
00323   //@}
00324 
00325 
00326   /** @name Edge insertion */
00327   //        ==============
00328   //@{
00329 
00330 //   /**
00331 //    * @brief Add a created edge from given data and flag,
00332 //    * and return a pointer to it.
00333 //    *
00334 //    * The current node becomes the source of the new edge.
00335 //    * The edge is inserted at the end of the edges list of the node.
00336 //    * Iterators to the edges list are not invalidated.
00337 //    *
00338 //    * @param  aData  data to be contained in the new edge
00339 //    * @param  aFlag  value of the edge flag (default <b>0</b>)
00340 //    */
00341 //   inline GenEdge<TNODE,TEDGE>*
00342 //   addEdge(const TEDGE& aData, short int aFlag = 0);
00343 
00344   /**
00345    * @brief Add (a pointer to) an edge at the end
00346    *   of the edges list of the node.
00347    *
00348    * Iterators to the edges list are not invalidated.
00349    *
00350    * @param  aPEdge  a pointer to an edge: <b>Should not be 0!</b>
00351    */
00352   inline GenEdge<node_type,edge_type>*
00353   addEdge(GenEdge<node_type,edge_type>* const aPEdge);
00354 
00355   /**
00356    * @brief Add (a pointer to) an edge at the beginning
00357    * of the edges list of the node.
00358    *
00359    * Iterators to the edges list are not invalidated.
00360    *
00361    * @param  aPEdge  a pointer to an edge: <b>Should not be 0!</b>
00362    */
00363   inline GenEdge<node_type,edge_type>*
00364   addEdgeFront(GenEdge<node_type,edge_type>* const aPEdge);
00365   //@}
00366 
00367 
00368   // ==========================================================
00369   /** @name Edge removal
00370       <b>Warning:</b> The client is in charge of the deletion
00371       of the removed elements. Removals invalidate iterators
00372       pointing to removed elements.
00373    */
00374   // ==========================================================
00375   //@{
00376  
00377   /**
00378    * @brief Remove the edge at given position in the edges list,
00379    * and return it.
00380    *
00381    * No effect when <b>aPos</b> points to the end of the list.
00382    *
00383    * @param  aPos  a position in the STL list of adjacent edges
00384    */
00385   GenEdge<node_type,edge_type>*
00386   removeEdge(typename std::list< GenEdge<node_type,edge_type>* >::iterator aPos);
00387  
00388   /**
00389    * @brief Remove the <i>first</i> pointer to an edge that
00390    * compares equal to the given pointer in the edges list.
00391    *
00392    * The function return the given pointer if the removal
00393    * is performed, <b>0</b> otherwise.
00394    *
00395    * @param  aPEdge  a pointer to an edge: <b>Should not be 0!</b>
00396    */
00397   GenEdge<node_type,edge_type>*
00398   removeEdge(GenEdge<node_type,edge_type>* const aPEdge);
00399 
00400   //@}
00401 
00402 
00403   /** @name Operators */
00404   //        =========
00405   //@{
00406 
00407   /**
00408    * @brief Assignment.
00409    *
00410    * @param  aNode  node to be assigned
00411    *
00412    * @warning The function performs a shallow copy:
00413    * The edges adjacent to the node are not duplicated.
00414    *
00415    * @todo This constructor performs a shallow copy.
00416    * Could it perform a deep copy? Edges adjacent to the node
00417    * would thus be copied, and then all nodes adjacent to these
00418    * edges, and the edges adjacent to these nodes... and then
00419    * the whole graph!
00420    */
00421   GenNode<node_type,edge_type>&
00422   operator=(const GenNode<node_type,edge_type>& aNode);
00423  
00424   /**
00425    * @brief Equality.
00426    *
00427    * Tests if the data of the current node compare equal to the data
00428    * of given node <b>aNode</b>, using operator <b>==</b>
00429    * applying to objects of type <b>TNODE</b>,
00430    * The values of the flags are not taken into account.
00431    *
00432    * @param  aNode  a node
00433    */
00434   inline bool operator==(const GenNode<node_type,edge_type>& aNode);
00435 
00436   /**
00437    * @brief Inequality.
00438    *
00439    * Tests if the data of the current node do not compare equal
00440    * to the data of given node <b>aNode</b>, using operator
00441    * <b>!=</b> applying to objects of type <b>TNODE</b>,
00442    * The values of the flags are not taken into account.
00443    *
00444    * @param  aNode  a node
00445    */
00446   inline bool operator!=(const GenNode<node_type,edge_type>& aNode);
00447 
00448   //@}
00449 
00450 
00451 // -------------------------------------------------------------------
00452 // P R O T E C T E D    M E M B E R S
00453 // -------------------------------------------------------------------
00454 protected:
00455 
00456 
00457   /** @name Representation of a node */
00458   //        ========================
00459   //@{
00460 
00461   /**
00462    * @brief Data contained in the node.
00463    */
00464   node_type _data;
00465 
00466   /**
00467    * @brief Flag at client's disposal (default <b>0</b>).
00468    */
00469   short int _flag;
00470 
00471   /**
00472    * @brief List of (pointers to) edges adjacent to the node.
00473    */
00474   std::list< GenEdge<node_type,edge_type>* > _edges;
00475 
00476   //@}
00477 
00478 // -------------------------------------------------------------------
00479 }; // class GenNode
00480 
00481 
00482 } // namespace qgar
00483 
00484 
00485 
00486 
00487 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00488 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00489 // I M P L E M E N T A T I O N
00490 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00491 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00492 
00493 #include <qgarlib/GenNode.TCC>
00494 
00495 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00496 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00497 
00498 
00499 
00500 
00501 #endif /* __GENNODE_H_INCLUDED__ */