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

GenEdge.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 __GENEDGE_H_INCLUDED__
00029 #define __GENEDGE_H_INCLUDED__
00030 
00031 
00032 /**
00033  * @file   GenEdge.H
00034  * @brief  Header file of class qgar::GenEdge.
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 // For RCS/CVS use: Do not delete
00043 /* $Id: GenEdge.H,v 1.6 2005/10/14 17:05:46 masini Exp $ */
00044 
00045 
00046 
00047 // QGAR
00048 namespace qgar
00049 {
00050   // ___________________________________________________________________
00051   // 
00052   // As class GenEdge is a client of class GenNode and class Genode
00053   // is a client of class GenEdge, compilation aborts because
00054   // of unresolved forward declarations without this prototype
00055   // (the text of one class is necessarily placed before the text
00056   // of the other by the precompiler). 
00057   // ___________________________________________________________________
00058   //
00059   template<class TNODE, class TEDGE> class GenNode;
00060 }
00061 
00062 
00063 
00064 namespace qgar
00065 {
00066 
00067 /**
00068  * @ingroup DS_GRAPH
00069  * @class GenEdge GenEdge.H "qgarlib/GenEdge.H"
00070  * @brief Edge of a parameterized graph containing (user-defined) data.
00071  *
00072  * An edge includes:
00073  * - an object of type <b>TEDGE</b>, called the <i>edge type</i>,
00074  * - an <b>integer</b> flag that any client may use
00075  *   for its own purposes,
00076  * - two pointers to the nodes which are adjacent to the edge.
00077  *
00078  * The adjacent nodes are arbitrarily called the <i>source</i> and
00079  * the <i>target</i>. The source (resp. target) is the first (resp.
00080  * second) node given as argument to the constructor at the creation
00081  * of the edge.
00082  *
00083  * See class qgar::GenNode for nodes.
00084  *
00085  * @warning
00086  * - The class is not supposed to be derived: No function
00087  *   member (destructor or whatever else) is virtual.
00088  * - <b>Pointers (to nodes) given as arguments to constructors and
00089  *   other function members may be null, which <i>may</i> further
00090  *   lead to hard bugs, when it results from a programmer's mistake.</b>
00091  *
00092  * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Gérald Masini">Gérald Masini</a>
00093  * @date   July 29, 2004  17:18
00094  * @since  Qgar 2.2
00095  */
00096 template <class TNODE, class TEDGE> class GenEdge
00097 {
00098 // -------------------------------------------------------------------
00099 // T Y P E   D E F I N I T I O N S
00100 // -------------------------------------------------------------------
00101 public:
00102 
00103   /** @name Types */
00104   //        =====
00105   //@{
00106 
00107   /**
00108    * @brief Type of the data stored in an edge.
00109    */
00110   typedef TEDGE edge_type;
00111 
00112   /**
00113    * @brief Reference to qgar::GenEdge::edge_type.
00114    */
00115   typedef edge_type& edge_type_reference;
00116 
00117   /**
00118    * @brief Constant reference to qgar::GenEdge::edge_type.
00119    */
00120   typedef const edge_type& edge_type_const_reference;
00121 
00122   /**
00123    * @brief Pointer to qgar::GenEdge::edge_type.
00124    */
00125   typedef edge_type* edge_type_pointer;
00126 
00127   /**
00128    * @brief Constant pointer to qgar::GenEdge::edge_type.
00129    */
00130   typedef const edge_type* edge_type_const_pointer;
00131 
00132   /**
00133    * @brief Type of the data stored in a node.
00134    */
00135   typedef TNODE node_type;
00136 
00137   /**
00138    * @brief Reference to qgar::GenEdge::node_type.
00139    */
00140   typedef node_type& node_type_reference;
00141 
00142   /**
00143    * @brief Constant reference to qgar::GenEdge::node_type.
00144    */
00145   typedef const node_type& node_type_const_reference;
00146 
00147   /**
00148    * @brief Pointer to qgar::GenEdge::node_type.
00149    */
00150   typedef node_type* node_type_pointer;
00151 
00152   /**
00153    * @brief Constant pointer to qgar::GenEdge::node_type.
00154    */
00155   typedef const node_type* node_type_const_pointer;
00156 
00157   //@}
00158 
00159 // -------------------------------------------------------------------
00160 // P U B L I C    M E M B E R S
00161 // -------------------------------------------------------------------
00162 public:
00163 
00164   /** @name Constructors */
00165   //        ============
00166   //@{
00167 
00168   /**
00169    * @brief Default constructor.
00170    *
00171    * The source and target of the edge are set to <b>0</b>.
00172    *
00173    * @param  aFlag  value of the node flag (default <b>0</b>)
00174    */
00175   GenEdge(short int aFlag = 0);
00176 
00177    /**
00178     * @brief Initialize with data.
00179     *
00180     * The source and target of the edge are set to <b>0</b>.
00181     *
00182     * @param  aData  data to be contained in the edge
00183     * @param  aFlag  value of the node flag (default <b>0</b>)
00184     */
00185   GenEdge(edge_type_const_reference aData,
00186           short int aFlag = 0);
00187 
00188    /**
00189     * @brief Initialize with source and target.
00190     *
00191     * @param  aPSource  a pointer to the source node (may be <b>0</b>)
00192     * @param  aPTarget  a pointer to the target node (may be <b>0</b>)
00193     * @param  aFlag     value of the node flag (default <b>0</b>)
00194     */
00195   GenEdge(GenNode<node_type, edge_type>* const aPSource,
00196           GenNode<node_type, edge_type>* const aPTarget,
00197           short int aFlag = 0);
00198 
00199    /**
00200     * @brief Initialize with data, source and target.
00201     *
00202     * @param  aData     data to be contained in the edge
00203     * @param  aPSource  a pointer to the source node (may be <b>0</b>)
00204     * @param  aPTarget  a pointer to the target node (may be <b>0</b>)
00205     * @param  aFlag     value of the node flag (default <b>0</b>)
00206     */
00207   GenEdge(GenNode<node_type, edge_type>* const aPSource,
00208           GenNode<node_type, edge_type>* const aPTarget,
00209           edge_type_const_reference aData,
00210           short int aFlag = 0);
00211 
00212   /**
00213    * @brief Copy constructor.
00214    *
00215    * @param  anEdge  edge to be copied
00216    *
00217    * @warning The constructor performs a shallow copy:
00218    * The two nodes adjacent to the edge are not duplicated.
00219    *
00220    * @todo This constructor performs a shallow copy.
00221    * Could it perform a deep copy? Nodes adjacent to the edge
00222    * would thus be copied, and then all edges adjacent to these
00223    * nodes, and the nodes adjacent to these edges... and then
00224    * the whole graph!...
00225    */
00226   GenEdge(const GenEdge<node_type, edge_type>& anEdge);
00227 
00228   //@}
00229 
00230 
00231   /** @name Destructor */
00232   //        ==========
00233   //@{
00234 
00235   /**
00236    * @brief Non-virtual destructor.
00237    */
00238   ~GenEdge();
00239 
00240   //@}
00241 
00242 
00243   /** @name Edge data */
00244   //        =========
00245   //@{
00246 
00247   /**
00248    * @brief Get edge data.
00249    */
00250   inline edge_type_const_reference accessData() const;
00251 
00252    /**
00253     * @brief Get a copy of edge data.
00254     */
00255   inline edge_type data() const;
00256 
00257   /**
00258    * @brief Set edge data.
00259    *
00260    * @param  aData  data to be contained in the edge
00261    */
00262   inline void setData(edge_type_const_reference aData);
00263 
00264   /**
00265    * @brief Get edge flag.
00266    */
00267   inline short int flag() const;
00268 
00269   /**
00270    * @brief Set edge flag.
00271    *
00272    * @param aFlag  value to assign to the flag
00273    */
00274   inline void setFlag(short int aFlag);
00275 
00276   //@}
00277 
00278 
00279   /** @name Adjacent nodes */
00280   //        ==============
00281   //@{
00282 
00283   /**
00284    * @brief Get source node.
00285    */
00286   inline const GenNode<node_type, edge_type>& accessSource() const;
00287 
00288   /**
00289    * @brief Get a copy of source node.
00290    */
00291   GenNode<node_type, edge_type> source() const;
00292 
00293   /**
00294    * @brief Get a pointer to source node.
00295    */
00296   inline GenNode<node_type, edge_type>* pSource() const;
00297 
00298   /**
00299    * @brief Get target node.
00300    */
00301   inline const GenNode<node_type, edge_type>& accessTarget() const;
00302 
00303   /**
00304    * @brief Get a copy of target node.
00305    */
00306   inline GenNode<node_type, edge_type> target() const;
00307 
00308   /**
00309    * @brief Get a pointer to target node.
00310    */
00311   inline GenNode<TNODE,TEDGE>* pTarget() const;
00312 
00313   /**
00314    * @brief Set (pointer to) source node.
00315    *
00316    * @param  aPSource  pointer to a node (may be <b>0</b>)
00317    */
00318   inline void setPSource(GenNode<node_type, edge_type>* aPSource);
00319 
00320   /**
00321    * @brief Set (pointer to the) target node.
00322    *
00323    * @param  aPTarget  pointer to a node (may be <b>0</b>)
00324    */
00325   inline void setPTarget(GenNode<node_type, edge_type>* aPTarget);
00326 
00327   /**
00328    * @brief Set (pointer to) given node as source or target.
00329    *
00330    * The given node becomes the source of the current edge
00331    * if the source is free. Otherwise, the given node becomes
00332    * the target of the current edge.
00333    *
00334    * @param  aPNode  pointer to a node (may be <b>0</b>)
00335    */
00336   inline void setPNode(GenNode<node_type, edge_type>* aPNode);
00337 
00338   //@}
00339 
00340 
00341   /** @name Operators */
00342   //        =========
00343   //@{
00344 
00345   /**
00346    * @brief Assignment.
00347    *
00348    * @param  anEdge  edge to be assigned
00349    *
00350    * @warning The function performs a shallow copy:
00351    * The two nodes adjacent to the edge are not duplicated.
00352    *
00353    * @todo This constructor performs a shallow copy.
00354    * Could it perform a deep copy? Nodes adjacent to the edge
00355    * would thus be copied, and then all edges adjacent to these
00356    * nodes, and the nodes adjacent to these edges... and then
00357    * the whole graph!...
00358    */
00359   GenEdge<node_type, edge_type>&
00360   operator=(const GenEdge<node_type, edge_type>& anEdge);
00361  
00362   /**
00363    * @brief Equality.
00364    *
00365    * @param  anEdge  an edge
00366    *
00367    * Test if the data of the current edge compare equal to the data
00368    * of given edge <b>anEdge</b>, using operator <b>==</b>
00369    * applying to objects of type <b>TEDGE</b>,
00370    * The values of the flags are not taken into account.
00371    */
00372   inline bool operator==(const GenEdge<node_type, edge_type>& anEdge);
00373 
00374   /**
00375    * @brief Inequality.
00376    *
00377    * Test if the data of the current edge do not compare equal
00378    * to the data of given edge <b>anEdge</b>, using operator <b>==</b>
00379    * applying to objects of type <b>TEDGE</b>,
00380    * The values of the flags are not taken into account.
00381    *
00382    * @param  anEdge  an edge
00383    */
00384   inline bool operator!=(const GenEdge<node_type, edge_type>& anEdge);
00385 
00386   //@}
00387 
00388 
00389 // -------------------------------------------------------------------
00390 // P R O T E C T E D    M E M B E R S
00391 // -------------------------------------------------------------------
00392 protected:
00393 
00394 
00395   /** @name Representation of an edge */
00396   //        =========================
00397   //@{
00398 
00399   /**
00400    * @brief Data contained in the edge.
00401    */
00402   edge_type _data;
00403 
00404   /**
00405    * @brief Flag at client's disposal (default <b>0</b>).
00406    */
00407   short int _flag;
00408 
00409   /**
00410    * @brief Pointer to the source node.
00411    */
00412   GenNode<node_type, edge_type>* _pSource;
00413 
00414   /** 
00415    * @brief Pointer to the target node.
00416    */
00417   GenNode<node_type, edge_type>* _pTarget;
00418 
00419   //@}
00420 
00421 // -------------------------------------------------------------------
00422 }; // Class GenEdge
00423 
00424 
00425 } // namespace qgar
00426 
00427 
00428 
00429 
00430 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00431 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00432 // I M P L E M E N T A T I O N
00433 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00434 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00435 
00436 #include <qgarlib/GenEdge.TCC>
00437 
00438 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00439 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00440 
00441 
00442 
00443 
00444 #endif /* __GENEDGE_H_INCLUDED__ */