SkelGIS  3.0
/home/helene/Documents/These/SkelGIS/SkelGIS_Library/SkelGIS_V3/skelgis/data_structures/DDAG/dpmap_nodes.hpp
00001 /*! \file pmap_nodes.hpp
00002  *  \brief Definitions of the object PMap_Nodes used by the user to map data to the nodes of a DDAG. Three template specializations are available.
00003  */
00004 #ifndef DPMAP_NODES_H
00005 #define DPMAP_NODES_H
00006 
00007 #include "dpmap_nodes_impl.hpp"
00008 
00009 namespace skelgis{
00010 
00011   //-------------------------------------------------------------------------------
00012   //!  base template class of Property map on nodes
00013   /*!
00014     This template class defines the base PMap_Nodes
00015     \tparam DD is the type of the DDAG
00016     \tparam T is the type of data in the property map
00017     \tparam node_access indicates if nodes have to have access to this property during calculation (>=1) or not (=0)
00018     \tparam size is the number of elements at each node
00019 
00020     In the case of a basic type T, node_access can't be >1
00021     In the case of a pointer type T*, if node_access>0 then it indicates the number of elements to shared at the end and at the beginning of the pointer
00022   */
00023   //-------------------------------------------------------------------------------
00024   template<class DD, class T, int node_access> struct DPMap_Nodes;
00025   //-------------------------------------------------------------------------------
00026   //!  first specialization of DPMap_Nodes
00027   /*!
00028     \tparam DD is the type of the DDAG
00029     \tparam T is the type of data in the property map
00030 
00031     The type T is a simple type in this case as float, double, int etc.
00032     The node_access is specialized to the value 1
00033   */
00034   //-------------------------------------------------------------------------------
00035   template<class DD, class T> struct DPMap_Nodes<DD,T,1>
00036   //-------------------------------------------------------------------------------
00037   {
00038   protected :
00039     bool ptr_const;
00040     DPMap_Nodes_impl<DD,T,1> * dpmap;
00041 
00042   public:
00043 
00044     typedef DPMap_Nodes_impl<DD,T,1> impl_type;
00045 
00046     //-------------------------------------------------------------------------------
00047     //!  constructor of DPMap_Nodes
00048     /*!
00049       \param dag is the DDAG object associated to this map
00050       \param file is the file with initial values of nodes wanted (each line is the value of the node "number of this line" associated in the .dot file)
00051     */
00052     //-------------------------------------------------------------------------------
00053     DPMap_Nodes(DD &dag, const char * file)
00054     {
00055       ptr_const = false;
00056       dpmap = new DPMap_Nodes_impl<DD,T,1>(dag,file);
00057     }
00058     //-------------------------------------------------------------------------------
00059     //!  constructor of DPMap_Nodes
00060     /*!
00061       \param dag is the DDAG object associated to this map
00062       \param val is the default value of nodes for the map
00063     */
00064     //-------------------------------------------------------------------------------
00065     DPMap_Nodes(DD &dag, T val)
00066     {
00067       ptr_const = false;
00068       dpmap = new DPMap_Nodes_impl<DD,T,1>(dag,val);
00069     }
00070     //-------------------------------------------------------------------------------
00071     //!  constructor from a DPMap_Nodes_impl pointer
00072     /*!
00073       \param pointer to a DPMap_Nodes_impl
00074     */
00075     //-------------------------------------------------------------------------------
00076     DPMap_Nodes(DPMap_Nodes_impl<DD,T,1> * p)
00077     {
00078       ptr_const = true;
00079       dpmap = p;
00080     }
00081     //-------------------------------------------------------------------------------
00082     //!  destructor of DPMap_Nodes
00083     /*!
00084     */
00085     //-------------------------------------------------------------------------------
00086     ~DPMap_Nodes()
00087     {
00088       if(dpmap!=NULL && !ptr_const)
00089         {delete dpmap;dpmap=NULL;}
00090     };
00091     //-------------------------------------------------------------------------------
00092     //!  to get the pointer on dpmap_impl
00093     /*!
00094       \return the dpmap implementation pointer
00095     */
00096     //-------------------------------------------------------------------------------
00097     inline DPMap_Nodes_impl<DD,T,1> * getDPMap(){return dpmap;}
00098     //-------------------------------------------------------------------------------
00099     //!  to get the begin iterator on roots nodes
00100     /*!
00101       \return the begin iterator on roots nodes
00102     */
00103     //-------------------------------------------------------------------------------
00104     inline iterator_dag begin_roots(){return dpmap->begin_roots();}
00105     //-------------------------------------------------------------------------------
00106     //!  to get the end iterator on roots nodes
00107     /*!
00108       \return the end iterator on roots nodes
00109     */
00110     //-------------------------------------------------------------------------------
00111     inline iterator_dag end_roots(){return dpmap->end_roots();}
00112     //-------------------------------------------------------------------------------
00113     //!  to get the begin iterator on leafs nodes
00114     /*!
00115       \return the begin iterator on leafs nodes
00116     */
00117     //-------------------------------------------------------------------------------
00118     inline iterator_dag begin_leafs(){return dpmap->begin_leafs();}
00119     //-------------------------------------------------------------------------------
00120     //!  to get the end iterator on leafs nodes
00121     /*!
00122       \return the end iterator on leafs nodes
00123     */
00124     //-------------------------------------------------------------------------------
00125     inline iterator_dag end_leafs(){return dpmap->end_leafs();}
00126     //-------------------------------------------------------------------------------
00127     //!  to get the begin iterator on nodes with communication with other processors
00128     /*!
00129       \return the begin iterator on communication nodes
00130     */
00131     //-------------------------------------------------------------------------------
00132     inline iterator_dag begin_comm(){return dpmap->begin_comm();}
00133     //-------------------------------------------------------------------------------
00134     //!  to get the end iterator on nodes with communication with other processors
00135     /*!
00136       \return the end iterator on communication nodes
00137     */
00138     //-------------------------------------------------------------------------------
00139     inline iterator_dag end_comm(){return dpmap->end_comm();}
00140     //-------------------------------------------------------------------------------
00141     //!  to get the begin iterator on nodes without communication with other processors
00142     /*!
00143       \return the begin iterator on local nodes
00144     */
00145     //-------------------------------------------------------------------------------
00146     inline iterator_dag begin_loc(){return dpmap->begin_loc();}
00147     //-------------------------------------------------------------------------------
00148     //!  to get the end iterator on nodes without communication with other processors
00149     /*!
00150       \return the end iterator on local nodes
00151     */
00152     //-------------------------------------------------------------------------------
00153     inline iterator_dag end_loc(){return dpmap->end_loc();}
00154     //-------------------------------------------------------------------------------
00155     //!  to get the begin iterator on inside nodes (i.e. nodes that are not roots or leafs = loc and comm nodes)
00156     /*!
00157       \return the begin iterator on inside nodes
00158     */
00159     //-------------------------------------------------------------------------------
00160     inline iterator_dag begin(){return dpmap->begin_in();}
00161     //-------------------------------------------------------------------------------
00162     //!  to get the end iterator on inside nodes (i.e. nodes that are not roots or leafs = loc and comm nodes)
00163     /*!
00164       \return the end iterator on inside nodes
00165     */
00166     //-------------------------------------------------------------------------------
00167     inline iterator_dag end(){return dpmap->end_in();}
00168     //-------------------------------------------------------------------------------
00169     //!  to get the value of the property map at the iterator position
00170     /*!
00171       \return a reference on the value (to be modified)
00172     */
00173     //-------------------------------------------------------------------------------
00174     inline T& operator[](iterator_dag it) { return dpmap->data[it._rank]; }
00175     //-------------------------------------------------------------------------------
00176     //!  to get a vector of iterator on input edges for the node it
00177     /*!
00178       \param it is the iterator on the node to get input edges
00179       \return a vector of iterator
00180     */
00181     //-------------------------------------------------------------------------------
00182     inline std::vector<iterator_dag> getInEdges(iterator_dag it){return dpmap->getInEdges(it);}
00183     //-------------------------------------------------------------------------------
00184     //!  to get a vector of iterator on output edges for the node it
00185     /*!
00186       \param it is the iterator on the node to get output edges
00187       \return a vector of iterator
00188     */
00189     //-------------------------------------------------------------------------------
00190     inline std::vector<iterator_dag> getOutEdges(iterator_dag it){return dpmap->getOutEdges(it);}
00191     //-------------------------------------------------------------------------------
00192     //!  to get a vector of iterator on input nodes for the node it
00193     /*!
00194       \param it is the iterator on the node to get input nodes
00195       \return a vector of iterator
00196     */
00197     //-------------------------------------------------------------------------------
00198     inline std::vector<iterator_dag> getInNodes(iterator_dag it){return dpmap->getInNodes(it);}
00199     //-------------------------------------------------------------------------------
00200     //!  to get a vector of iterator on output nodes for the node it
00201     /*!
00202       \param it is the iterator on the node to get output nodes
00203       \return a vector of iterator
00204     */
00205     //-------------------------------------------------------------------------------
00206     inline std::vector<iterator_dag> getOutNodes(iterator_dag it){return dpmap->getOutNodes(it);}
00207     //-------------------------------------------------------------------------------
00208     //!  start the communication process for the dpmap_nodes property
00209     /*!
00210       prepare data to send
00211       launch non blocking MPI communications
00212     */
00213     //-------------------------------------------------------------------------------
00214     inline void start_communications(){dpmap->start_communications();}
00215     //-------------------------------------------------------------------------------
00216     //!  end the communication process for the dpmap_nodes property
00217     /*!
00218       wait for the end of non-blocking communications
00219       put received values in the dpmap_nodes property
00220     */
00221     //-------------------------------------------------------------------------------
00222     inline void end_communications(){dpmap->end_communications();}
00223     //-------------------------------------------------------------------------------
00224     
00225   };
00226   //-------------------------------------------------------------------------------
00227   //!  second specialization of DPMap_Nodes
00228   /*!
00229     \tparam DD is the type of the DDAG
00230     \tparam T is the type of data in the property map
00231 
00232     The type T is a simple type in this case as float, double, int etc.
00233     The node_access is specialized to the value 0
00234   */
00235   //-------------------------------------------------------------------------------
00236   template<class DD, class T> struct DPMap_Nodes<DD,T,0>
00237   {
00238     protected :
00239     bool ptr_const;
00240     DPMap_Nodes_impl<DD,T,0> * dpmap;
00241 
00242   public:
00243 
00244     typedef DPMap_Nodes_impl<DD,T,0> impl_type;
00245 
00246     //-------------------------------------------------------------------------------
00247     //!  constructor of DPMap_Nodes
00248     /*!
00249       \param dag is the DDAG object associated to this map
00250       \param file is the file with initial values of nodes wanted (each line is the value of the node "number of this line" associated in the .dot file)
00251     */
00252     //-------------------------------------------------------------------------------
00253     DPMap_Nodes(DD &dag, const char * file)
00254     {
00255       dpmap = new DPMap_Nodes_impl<DD,T,0>(dag,file);
00256     }
00257     //-------------------------------------------------------------------------------
00258     //!  constructor of DPMap_Nodes
00259     /*!
00260       \param dag is the DDAG object associated to this map
00261       \param val is the default value of nodes for the map
00262     */
00263     //-------------------------------------------------------------------------------
00264     DPMap_Nodes(DD &dag, T val)
00265     {
00266       dpmap = new DPMap_Nodes_impl<DD,T,0>(dag,val);
00267     }
00268     //-------------------------------------------------------------------------------
00269     //!  constructor from a DPMap_Nodes_impl pointer
00270     /*!
00271       \param pointer to a DPMap_Nodes_impl
00272     */
00273     //-------------------------------------------------------------------------------
00274     DPMap_Nodes(DPMap_Nodes_impl<DD,T,0> * p)
00275     {
00276       dpmap = p;
00277     }
00278     //-------------------------------------------------------------------------------
00279     //!  destructor of DPMap_Nodes
00280     /*!
00281     */
00282     //-------------------------------------------------------------------------------
00283     ~DPMap_Nodes()
00284     {
00285       if(dpmap!=NULL && !ptr_const)
00286         {delete dpmap;dpmap=NULL;}
00287     };
00288     //-------------------------------------------------------------------------------
00289     //!  to get the pointer on dpmap_impl
00290     /*!
00291       \return the dpmap implementation pointer
00292     */
00293     //-------------------------------------------------------------------------------
00294     inline DPMap_Nodes_impl<DD,T,0> * getDPMap(){return dpmap;}
00295     //-------------------------------------------------------------------------------
00296     //!  to get the begin iterator on roots nodes
00297     /*!
00298       \return the begin iterator on roots nodes
00299     */
00300     //-------------------------------------------------------------------------------
00301     inline iterator_dag begin_roots(){return dpmap->begin_roots();}
00302     //-------------------------------------------------------------------------------
00303     //!  to get the end iterator on roots nodes
00304     /*!
00305       \return the end iterator on roots nodes
00306     */
00307     //-------------------------------------------------------------------------------
00308     inline iterator_dag end_roots(){return dpmap->end_roots();}
00309     //-------------------------------------------------------------------------------
00310     //!  to get the begin iterator on leafs nodes
00311     /*!
00312       \return the begin iterator on leafs nodes
00313     */
00314     //-------------------------------------------------------------------------------
00315     inline iterator_dag begin_leafs(){return dpmap->begin_leafs();}
00316     //-------------------------------------------------------------------------------
00317     //!  to get the end iterator on leafs nodes
00318     /*!
00319       \return the end iterator on leafs nodes
00320     */
00321     //-------------------------------------------------------------------------------
00322     inline iterator_dag end_leafs(){return dpmap->end_leafs();}
00323     //-------------------------------------------------------------------------------
00324     //!  to get the begin iterator on nodes with communication with other processors
00325     /*!
00326       \return the begin iterator on communication nodes
00327     */
00328     //-------------------------------------------------------------------------------
00329     inline iterator_dag begin_comm(){return dpmap->begin_comm();}
00330     //-------------------------------------------------------------------------------
00331     //!  to get the end iterator on nodes with communication with other processors
00332     /*!
00333       \return the end iterator on communication nodes
00334     */
00335     //-------------------------------------------------------------------------------
00336     inline iterator_dag end_comm(){return dpmap->end_comm();}
00337     //-------------------------------------------------------------------------------
00338     //!  to get the begin iterator on nodes without communication with other processors
00339     /*!
00340       \return the begin iterator on local nodes
00341     */
00342     //-------------------------------------------------------------------------------
00343     inline iterator_dag begin_loc(){return dpmap->begin_loc();}
00344     //-------------------------------------------------------------------------------
00345     //!  to get the end iterator on nodes without communication with other processors
00346     /*!
00347       \return the end iterator on local nodes
00348     */
00349     //-------------------------------------------------------------------------------
00350     inline iterator_dag end_loc(){return dpmap->end_loc();}
00351     //-------------------------------------------------------------------------------
00352     //!  to get the begin iterator on inside nodes (i.e. nodes that are not roots or leafs = loc and comm nodes)
00353     /*!
00354       \return the begin iterator on inside nodes
00355     */
00356     //-------------------------------------------------------------------------------
00357     inline iterator_dag begin(){return dpmap->begin_in();}
00358     //-------------------------------------------------------------------------------
00359     //!  to get the end iterator on inside nodes (i.e. nodes that are not roots or leafs = loc and comm nodes)
00360     /*!
00361       \return the end iterator on inside nodes
00362     */
00363     //-------------------------------------------------------------------------------
00364     inline iterator_dag end(){return dpmap->end_in();}
00365     //-------------------------------------------------------------------------------
00366     //!  to get the value of the property map at the iterator position
00367     /*!
00368       \return a reference on the value (to be modified)
00369     */
00370     //-------------------------------------------------------------------------------
00371     inline T& operator[](iterator_dag it) { return dpmap->data[it._rank]; }
00372     //-------------------------------------------------------------------------------
00373     //!  to get a vector of iterator on input edges for the node it
00374     /*!
00375       \param it is the iterator on the node to get input edges
00376       \return a vector of iterator
00377     */
00378     //-------------------------------------------------------------------------------
00379     inline std::vector<iterator_dag> getInEdges(iterator_dag it){return dpmap->getInEdges(it);}
00380     //-------------------------------------------------------------------------------
00381     //!  to get a vector of iterator on output edges for the node it
00382     /*!
00383       \param it is the iterator on the node to get output edges
00384       \return a vector of iterator
00385     */
00386     //-------------------------------------------------------------------------------
00387     inline std::vector<iterator_dag> getOutEdges(iterator_dag it){return dpmap->getOutEdges(it);}
00388     //-------------------------------------------------------------------------------
00389     //!  to get a vector of iterator on input nodes for the node it
00390     /*!
00391       \param it is the iterator on the node to get input nodes
00392       \return a vector of iterator
00393     */
00394     //-------------------------------------------------------------------------------
00395     inline std::vector<iterator_dag> getInNodes(iterator_dag it){return dpmap->getInNodes(it);}
00396     //-------------------------------------------------------------------------------
00397     //!  to get a vector of iterator on output nodes for the node it
00398     /*!
00399       \param it is the iterator on the node to get output nodes
00400       \return a vector of iterator
00401     */
00402     //-------------------------------------------------------------------------------
00403     inline std::vector<iterator_dag> getOutNodes(iterator_dag it){return dpmap->getOutNodes(it);}
00404     //-------------------------------------------------------------------------------
00405 
00406   };
00407   //-------------------------------------------------------------------------------
00408   //!  third specialization of DPMap_Nodes
00409   /*!
00410     \tparam DD is the type of the DDAG
00411     \tparam T is the type of data in the property map
00412     \tparam node_access indicates if nodes have to have access to this property during calculation (>=1) or not (=0)
00413 
00414     The type T is specialized with a specific pointer type in this case as float*, double*, int* etc.
00415     The node_access is not specialized and is [0,...,size], with size a constant value given at the construction
00416   */
00417   //-------------------------------------------------------------------------------
00418   template<class DD, class T,int node_access> struct DPMap_Nodes<DD,T*,node_access>
00419   {
00420   protected :
00421 
00422   public:
00423 
00424     typedef DPMap_Nodes_impl<DD,T*,node_access> impl_type;
00425 
00426     DPMap_Nodes(){};
00427     ~DPMap_Nodes(){};
00428     
00429   };
00430   //-------------------------------------------------------------------------------
00431   //!  fourth specialization of DPMap_Nodes
00432   /*!
00433     \tparam DD is the type of the DDAG
00434     \tparam T is the type of data in the property map
00435 
00436     The type T is specialized with a specific pointer type in this case as float*, double*, int* etc.
00437     The node_access is specialized to the value 0
00438   */
00439   //-------------------------------------------------------------------------------
00440   template<class DD, class T> struct DPMap_Nodes<DD,T*,0>
00441   {
00442   protected :
00443 
00444   public:
00445     DPMap_Nodes(){};
00446     ~DPMap_Nodes(){};
00447 
00448     typedef DPMap_Nodes_impl<DD,T*,0> impl_type;
00449   };
00450 
00451 };
00452 
00453 
00454 #endif
 All Classes Files Functions Variables Defines