Main Page   Class Hierarchy   Compound List   File List   Compound Members  

PG_property.hpp

00001 #ifndef _PG_PROPERTY_HPP_
00002 #define _PG_PROPERTY_HPP_
00003 
00004 #include <boost/pending/property.hpp>
00005 #include <string>
00006 
00007 namespace ParGraph
00008 {
00009 using boost::no_property;
00010 using boost::property;
00011 
00012 struct simple_distribution
00013 {
00014   template< class Property, class Buffer >
00015   inline void put( const Property &prop, Buffer & buf ) const
00016   {
00017     buf.put( &prop, 1 );
00018   }
00019 
00020   template< class Property, class Buffer >
00021   inline void get( Property &prop, Buffer & buf ) const
00022   {
00023     buf.get( &prop, 1 );
00024   }
00025   template< class Tag, class Property, class Graph, class DistHelper, class Buffer >
00026   inline void put( Tag, const Property &prop, Graph &, DistHelper &, Buffer & buf ) const
00027   {
00028     buf.put( &prop, 1 );
00029   }
00030 
00031   template< class Tag, class Property, class Graph, class DistHelper, class Buffer >
00032   inline void get( Tag, Property &prop, Graph &, DistHelper &, Buffer & buf ) const
00033   {
00034     buf.get( &prop, 1 );
00035   }
00036 };
00037 
00038 template<class A>
00039 struct property_distribution_traits
00040 {
00041   typedef simple_distribution distribution_type;
00042 };
00043 
00044 struct string_distribution
00045 {
00046   template< class chartype, class Buffer >
00047   inline void put( const std::basic_string<chartype> &prop, Buffer & buf ) const
00048   {
00049     size_t size = prop.size();
00050     buf.put( size );
00051     buf.put( prop.data(), size );
00052   }
00053 
00054   template< class chartype, class Buffer >
00055   inline void get( std::basic_string<chartype> &prop, Buffer & buf ) const
00056   {
00057     size_t size;
00058     buf.get( &size, 1 );
00059     if( size != 0 )
00060     {
00061       tmp = new chartype[ size + 1 ];
00062       buf.get( tmp, size );
00063       tmp[size] = 0;
00064       prop = tmp;
00065       delete[] tmp;
00066     }
00067   }
00068 
00069   template< class Tag, class chartype, class Graph, class DistHelper, class Buffer >
00070   inline void put( Tag, std::basic_string<chartype> &prop, Graph &, DistHelper &, Buffer & buf ) const
00071   {
00072     put( prop, buf );
00073   }
00074 
00075   template< class Tag, class chartype, class Graph, class DistHelper, class Buffer >
00076   inline void get( Tag, std::basic_string<chartype> &prop, Graph &, DistHelper &, Buffer & buf ) const
00077   {
00078     get( prop, buf );
00079   }
00080 };
00081 
00082 template<class T>
00083 struct property_distribution_traits<std::basic_string<T> >
00084 {
00085   typedef string_distribution distribution_type;
00086 };
00087 
00088 struct complex_distribution
00089 {
00090   template< class Property, class Buffer >
00091   inline void put( const Property &prop, Buffer & buf )
00092   {
00093     prop._pgdist_fill_buf( buf );
00094   }
00095 
00096   template< class Property, class Buffer >
00097   inline void get( Property &prop, Buffer & buf )
00098   {
00099     prop._pgdist_read_buf( buf );
00100   }
00101   template< class Tag, class Property, class Graph, class DistHelper, class Buffer >
00102   inline void put( Tag t, Property &prop, Graph & g, DistHelper & dh, Buffer & buf )
00103   {
00104     prop._pgdist_fill_buf( t, g, dh, buf );
00105   }
00106 
00107   template< class Tag, class Property, class Graph, class DistHelper, class Buffer >
00108   inline void get( Tag t, Property &prop, Graph & g, DistHelper & dh, Buffer & buf )
00109   {
00110     prop._pgdist_read_buf( t, g, dh, buf );
00111   }
00112 };
00113 
00114 template< class PropertyList, class Buffer >
00115 inline void
00116 put_property_into_buffer( PropertyList& ref, Buffer & buf )
00117 {
00118   typedef typename PropertyList::value_type value_type;
00119   typedef typename property_distribution_traits<value_type>::distribution_type distribution_type;
00120 
00121   distribution_type helper;
00122 
00123   helper.put( ref.m_value, buf );
00124   put_property_into_buffer( (typename PropertyList::next_type &) ref, buf );
00125 }
00126 
00127 template< class Buffer >
00128 inline void
00129 put_property_into_buffer( no_property&, Buffer & )
00130 {
00131 }
00132 
00133 template< class Graph, class DistHelper, class PropertyList, class Buffer >
00134 inline void
00135 put_property_into_buffer( Graph & g, DistHelper & dh, PropertyList& ref, Buffer & buf )
00136 {
00137   typedef typename PropertyList::value_type value_type;
00138   typedef typename property_distribution_traits<value_type>::distribution_type distribution_type;
00139 
00140   distribution_type helper;
00141 
00142   helper.put( typename PropertyList::tag_type(), ref.m_value, g, dh, buf );
00143   put_property_into_buffer( g, dh, (typename PropertyList::next_type &) ref, buf );
00144 }
00145 
00146 template< class Graph, class DistHelper, class Buffer >
00147 inline void
00148 put_property_into_buffer( Graph &, DistHelper &, no_property&, Buffer & )
00149 {
00150 }
00151 
00152 template< class PropertyList, class Buffer >
00153 inline void
00154 get_property_from_buffer( PropertyList& ref, Buffer & buf )
00155 {
00156   typedef typename PropertyList::value_type value_type;
00157   typedef typename property_distribution_traits<value_type>::distribution_type distribution_type;
00158 
00159   distribution_type helper;
00160 
00161   helper.get( ref.m_value, buf );
00162   get_property_from_buffer( (typename PropertyList::next_type &) ref, buf );
00163 }
00164 
00165 template< class Buffer >
00166 inline void
00167 get_property_from_buffer( no_property&, Buffer & )
00168 {
00169 }
00170 
00171 template< class Graph, class DistHelper, class PropertyList, class Buffer >
00172 inline void
00173 get_property_from_buffer( Graph & g, DistHelper & dh, PropertyList& ref, Buffer & buf )
00174 {
00175   typedef typename PropertyList::value_type value_type;
00176   typedef typename property_distribution_traits<value_type>::distribution_type distribution_type;
00177 
00178   distribution_type helper;
00179 
00180   helper.get( typename PropertyList::tag_type(), ref.m_value, g, dh, buf );
00181   get_property_from_buffer( g, dh, (typename PropertyList::next_type &) ref, buf );
00182 }
00183 
00184 template< class Graph, class DistHelper,  class Buffer >
00185 inline void
00186 get_property_from_buffer( Graph &, DistHelper &, no_property&, Buffer & )
00187 {
00188 }
00189 
00190 typedef enum { white_color, gray_color, black_color } default_color_type;
00191 
00192 template< class CT >
00193 struct color_traits
00194 {
00195   static default_color_type white() { return white_color; }
00196   static default_color_type gray() { return gray_color; }
00197   static default_color_type black() { return black_color; }
00198 };
00199 
00200 template<>
00201 struct mpi_traits<default_color_type>
00202 {
00203   const MPI_Datatype mpi_type;
00204   mpi_traits() : mpi_type(MPI_INT) {}
00205   // static const MPI_Datatype mpi_type = MPI_INT;
00206 };
00207 
00208 struct vertex_name_tag {};
00209 struct vertex_color_tag {};
00210 struct vertex_level_tag {};
00211 struct vertex_proc_tag {};
00212 struct vertex_potential_tag {};
00213 
00214 struct edgelist1_tag {};
00215 struct edgelist_residual_tag {};
00216 
00217 struct edge_flow_tag {};
00218 struct edge_capacity_tag {};
00219 struct edge_reference_tag {};
00220 struct edge_flag1_tag {};
00221 
00222 }
00223 
00224 #endif // _PG_PROPERTY_HPP_

Generated on Sun Feb 29 05:14:24 2004 for ParGraph by doxygen1.3-rc3