Main Page   Class Hierarchy   Compound List   File List   Compound Members  

PG_property_map.hpp

00001 #ifndef _PG_PROPERTY_MAP_HPP_
00002 #define _PG_PROPERTY_MAP_HPP_
00003 
00004 #include <boost/pending/property.hpp>
00005 
00006 namespace ParGraph
00007 {
00008 using boost::get_property_value;
00009 
00011 template< class Tag, class Graph >
00012 struct EdgeMap
00013 {
00014   typedef Tag tag;
00015   typedef typename boost::property_value< typename Graph::VertexProperty, Tag >::type value_type;
00016   typedef typename value_type::edge_kind edge_kind;
00017   typedef typename value_type::property_type edge_property_type;
00018   typedef typename value_type::edge_type edge_type;
00019   typedef typename value_type::out_iterator out_iterator;
00020   typedef typename value_type::in_iterator in_iterator;
00021   typedef typename value_type::Edge Edge;
00022   typedef typename value_type::mapiterator mapiterator;
00023   typedef typename value_type::const_mapiterator const_mapiterator;
00024 };
00025 
00026 
00027 template< class Tag, class Graph >
00028 EdgeMap< Tag, Graph >
00029 get_edge_map( Tag, Graph )
00030 {
00031   return EdgeMap< Tag, Graph >();
00032 }
00033 
00037 template< class T, class V, class G >
00038 typename EdgeMap< T, G >::value_type::map_type &
00039 get_out_edges( EdgeMap< T, G >, V v, G & g )
00040 {
00041   return get_property_value( g.get_property_reference( v ), typename EdgeMap<T,G>::tag() ).out_edges;
00042 };
00043 
00047 template< class T, class G, class VProp >
00048 typename EdgeMap< T, G >::value_type::map_type &
00049 get_out_edges( EdgeMap< T, G >, VProp & vp )
00050 {
00051   return get_property_value( vp, typename EdgeMap< T, G >::tag() ).out_edges;
00052 }
00053 
00054 template< class T, class G, class P >
00055 inline typename EdgeMap< T, G >::value_type::map_type &
00056 get_out_edges( EdgeMap< T, G >, DirectedInOutEdges<P> & el )
00057 {
00058   return el.out_edges;
00059 }
00060 
00061 template< class T, class G, class P >
00062 inline typename EdgeMap< T, G >::value_type::map_type &
00063 get_out_edges( EdgeMap< T, G >, DirectedOutEdges<P> & el )
00064 {
00065   return el.out_edges;
00066 }
00067 
00071 template< class T, class V, class G >
00072 inline typename EdgeMap< T, G >::value_type::map_type &
00073 get_in_edges( EdgeMap< T, G >, V v, G & g )
00074 {
00075   return get_property_value( g.get_property_reference( v ), typename EdgeMap<T,G>::tag() ).in_edges;
00076 };
00077 
00081 template< class T, class G, class VProp >
00082 typename EdgeMap< T, G >::value_type::map_type &
00083 get_in_edges( EdgeMap< T, G >, VProp & vp )
00084 {
00085   return get_property_value( vp, typename EdgeMap< T, G >::tag() ).in_edges;
00086 }
00087 
00088 template< class T, class G, class P >
00089 inline typename EdgeMap< T, G >::value_type::map_type &
00090 get_in_edges( EdgeMap< T, G >, DirectedInOutEdges<P> & el )
00091 {
00092   return el.in_edges;
00093 }
00094 
00095 template< class Tag, class Graph >
00096 struct ReverseEdgeMap
00097 {
00098   typedef Tag tag;
00099   typedef typename boost::property_value< typename Graph::VertexProperty, Tag >::type value_type;
00100   typedef typename value_type::edge_kind edge_kind;
00101   typedef typename value_type::property_type edge_property_type;
00102   typedef typename value_type::edge_type edge_type;
00103   typedef typename value_type::in_iterator in_iterator;
00104   typedef typename value_type::out_iterator out_iterator;
00105   typedef typename value_type::Edge Edge;
00106   typedef typename value_type::mapiterator mapiterator;
00107   typedef typename value_type::const_mapiterator const_mapiterator;
00108 };
00109 
00110 template< class T, class V, class G >
00111 inline typename ReverseEdgeMap< T, G >::value_type::map_type &
00112 get_out_edges( ReverseEdgeMap< T, G >, V v, G & g )
00113 {
00114   return get_property_value( g.get_property_reference( v ), typename ReverseEdgeMap<T,G>::tag() ).in_edges;
00115 };
00116 
00117 template< class T, class G, class VProp >
00118 inline typename ReverseEdgeMap< T, G >::value_type::map_type &
00119 get_out_edges( ReverseEdgeMap< T, G >, VProp & vp )
00120 {
00121   return get_property_value( vp, typename ReverseEdgeMap< T, G >::tag() ).in_edges;
00122 }
00123 
00124 template< class T, class G, class P >
00125 inline typename ReverseEdgeMap< T, G >::value_type::map_type &
00126 get_out_edges( ReverseEdgeMap< T, G >, DirectedInOutEdges<P> & el )
00127 {
00128   return el.in_edges;
00129 }
00130 
00131 template< class T, class V, class G >
00132 inline typename ReverseEdgeMap< T, G >::value_type::map_type &
00133 get_in_edges( ReverseEdgeMap< T, G >, V v, G & g )
00134 {
00135   return get_property_value( g.get_property_reference( v ), typename ReverseEdgeMap<T,G>::tag() ).out_edges;
00136 };
00137 
00138 template< class T, class G, class VProp >
00139 inline typename ReverseEdgeMap< T, G >::value_type::map_type &
00140 get_in_edges( ReverseEdgeMap< T, G >, VProp & vp )
00141 {
00142   return get_property_value( vp, typename ReverseEdgeMap< T, G >::tag() ).out_edges;
00143 }
00144 
00145 template< class T, class G, class P >
00146 inline typename ReverseEdgeMap< T, G >::value_type::map_type &
00147 get_in_edges( ReverseEdgeMap< T, G >, DirectedInOutEdges<P> & el )
00148 {
00149   return el.out_edges;
00150 }
00151 
00152 template< class Filter, class Iterator >
00153 class FilteredEdgeIterator
00154 {
00155   typedef FilteredEdgeIterator< Filter, Iterator > self_type;
00156   Iterator iter, it_end;
00157   Filter f;
00158   void find_next()
00159   {
00160     while( iter != it_end )
00161     {
00162       if( f( *iter ) ) return;
00163       iter++;
00164     }
00165   }
00166 public:
00167   FilteredEdgeIterator() {}
00168   FilteredEdgeIterator( Filter filter, Iterator & it, Iterator & end )
00169   {
00170     f = filter;
00171     it_end = end;
00172     iter = it;
00173     find_next();
00174   }
00175   void operator++(int)
00176   {
00177     iter++;
00178     find_next();
00179   }
00180   bool operator==( const self_type & other )
00181   {
00182     return iter == other.iter;
00183   }
00184   bool operator!=( const self_type & other )
00185   {
00186     return iter != other.iter;
00187   }
00188   typename Iterator::value_type operator* ()
00189   {
00190     return *iter;
00191   }
00192 };
00193 
00194 template< class Filter, class BaseEdgeMap >
00195 struct FilteredEdgeMap
00196 {
00197   Filter f;
00198   typedef typename BaseEdgeMap::tag tag;
00199   typedef typename BaseEdgeMap::value_type value_type;
00200   typedef typename BaseEdgeMap::edge_kind edge_kind;
00201   typedef typename BaseEdgeMap::edge_property_type edge_property_type;
00202   typedef typename BaseEdgeMap::edge_type edge_type;
00203   typedef typename BaseEdgeMap::Edge Edge;
00204   typedef FilteredEdgeIterator< Filter, typename BaseEdgeMap::out_iterator > out_iterator;
00205   typedef FilteredEdgeIterator< Filter, typename BaseEdgeMap::in_iterator > in_iterator;
00206   FilteredEdgeMap( Filter _f ) : f(_f) {}
00207 };
00208 
00209 template< class Graph, class V, class F, class B >
00210 inline std::pair< typename FilteredEdgeMap<F,B>::out_iterator,
00211              typename FilteredEdgeMap<F,B>::out_iterator >
00212 out_edges( Graph &g, V v, FilteredEdgeMap<F,B> m )
00213 {
00214   typedef typename FilteredEdgeMap<F,B>::out_iterator Iter;
00215   pair< typename B::out_iterator, typename B::out_iterator > tmp =
00216       out_edges( g, v, B() );
00217   Iter it1 = Iter( m.f, tmp.first, tmp.second );
00218   Iter it2 = Iter( m.f, tmp.second, tmp.second );
00219   return std::make_pair( it1, it2 );
00220 }
00221 
00223 template< class T, class EdgeMap >
00224 struct EdgePropertyMap
00225 {
00226   typedef T tag;
00227   typedef EdgeMap edge_map;
00228   typedef typename boost::property_value< typename edge_map::value_type::property_type, tag >::type value_type;
00229 };
00230 
00231 template< class Tag, class EdgeMap >
00232 EdgePropertyMap< Tag, EdgeMap >
00233 get_edge_property_map( Tag, EdgeMap )
00234 {
00235   return EdgePropertyMap< Tag, EdgeMap >();
00236 };
00237 
00238 
00239 template< class T, class M, class Iter >
00240 typename EdgePropertyMap< T, M >::value_type &
00241 get( EdgePropertyMap< T, M >, Iter iter )
00242 {
00243   return get_property_value( get_edge_property(iter), typename EdgePropertyMap< T, M >::tag() );
00244 };
00245 
00246 template< class T, class M, class Iter >
00247 void
00248 put( EdgePropertyMap< T, M >, Iter iter, typename EdgePropertyMap< T, M >::value_type value)
00249 {
00250   get_property_value( get_edge_property(iter), typename EdgePropertyMap< T, M >::tag() ) = value;
00251 };
00252 
00253 
00255 template< class T, class G >
00256 struct VertexPropertyMap
00257 {
00258   typedef T tag;
00259   typedef typename boost::property_value< typename G::VertexProperty, T >::type value_type;
00260 };
00261 
00263 template< class Tag, class Graph >
00264 VertexPropertyMap< Tag, Graph >
00265 get_vertex_property_map( Tag, Graph )
00266 {
00267   return VertexPropertyMap< Tag, Graph >();
00268 }
00269 
00271 template< class Map, class Vertex, class Graph >
00272 inline void
00273 put( Map, Vertex v, Graph & g, typename Map::value_type value )
00274 {
00275   get( Map(), g.get_property_reference( v ) ) = value;
00276 }
00277 
00279 template< class Map, class Vertex, class Graph >
00280 inline typename Map::value_type &
00281 get( Map, Vertex v, Graph & g )
00282 {
00283   return get_property_value( g.get_property_reference( v ), typename Map::tag() );
00284 }
00285 
00286 template< class T, class P >
00287 struct PropertyMap
00288 {
00289   typedef T tag;
00290   typedef typename boost::property_value< P, T >::type value_type;
00291 };
00292 
00293 template< class Tag, class PropertyList >
00294 PropertyMap< Tag, PropertyList >
00295 get_property_map( Tag, PropertyList )
00296 {
00297   return PropertyMap< Tag, PropertyList >();
00298 }
00299 
00300 template< class Map, class Property >
00301 inline typename Map::value_type &
00302 get( Map, Property & p )
00303 {
00304   return get_property_value( p, Map::tag );
00305 }
00306 
00307 template< class Map, class Property >
00308 inline void
00309 put( Map, Property & p, typename Map::value_type value )
00310 {
00311   get( Map(), p ) = value;
00312 }
00313 
00314 }
00315 #endif // _PG_PROPERTY_MAP_HPP_

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