Map Adaptors

The same group on the Doxygen site.

group Map Adaptors

Tools to create new maps from existing ones.

This group contains map adaptors that are used to create “implicit” maps from other maps.

Most of them are read-only maps. They can make arithmetic and logical operations between one or two maps (negation, shifting, addition, multiplication, logical ‘and’, ‘or’, ‘not’ etc.) or e.g. convert a map to another one of different Value type.

The typical usage of this classes is passing implicit maps to algorithms. If a function type algorithm is called then the function type map adaptors can be used comfortable. For example let’s see the usage of map adaptors with the graphToEps() function.

Color nodeColor( int deg )
{
 if( deg >= 2 ) {
return( Color( 0.5 , 0.0 , 0.5 ) );
  }
 else if( deg == 1 ) {
return( Color( 1.0 , 0.5 , 1.0 ) );
  }
 else {
return( Color( 0.0 , 0.0 , 0.0 ) );
  }
 }

Digraph::NodeMap< int > degree_map( graph );

graphToEps( graph , "graph.eps" )
  .coords( coords )
  .scaleToA4()
  .undirected()
  .nodeColors( composeMap( functorToMap( nodeColor ) , degree_map ) )
  .run();
The functorToMap() function makes an int to Color map from the nodeColor() function. The composeMap() compose the degree_map and the previously created map. The composed map is a proper function to get the color of each node.

The usage with class type algorithms is little bit harder. In this case the function type map adaptors can not be used, because the function map adaptors give back temporary objects.

Digraph graph;

typedef Digraph::ArcMap< double > DoubleArcMap;
DoubleArcMap length( graph );
DoubleArcMap speed( graph );

typedef DivMap< DoubleArcMap , DoubleArcMap > TimeMap;
TimeMap time( length , speed );

Dijkstra< Digraph , TimeMap > dijkstra( graph , time );
dijkstra.run( source , target );
We have a length map and a maximum speed map on the arcs of a digraph. The minimum time to pass the arc can be calculated as the division of the two maps which can be done implicitly with the DivMap template class. We use the implicit minimum time map as the length map of the Dijkstra algorithm.

Classes

Class

Description

ComposeMap

Composition of two maps.

CombineMap

FunctorToMap

Converts an STL style (unary) functor to a map.

MapToFunctor

Converts a map to an STL style (unary) functor.

ConvertMap

Map adaptor to convert the Value type of a map to another type using the default conversion.

ForkMap

Applies all map setting operations to two maps.

AddMap

Sum of two maps.

SubMap

Difference of two maps.

MulMap

Product of two maps.

DivMap

Quotient of two maps.

ShiftMap

Shifts a map with a constant.

ShiftWriteMap

Shifts a map with a constant (read-write version).

ScaleMap

Scales a map with a constant.

ScaleWriteMap

Scales a map with a constant (read-write version).

NegMap

Negative of a map.

NegWriteMap

Negative of a map (read-write version).

AbsMap

Absolute value of a map.

AndMap

Logical ‘and’ of two maps.

OrMap

Logical ‘or’ of two maps.

NotMap

Logical ‘not’ of a map.

NotWriteMap

Logical ‘not’ of a map (read-write version).

EqualMap

Combination of two maps using the == operator.

LessMap

Combination of two maps using the < operator.

Functions and other members

template< typename M1 , typename M2 , typename F >
inline CombineMap< M1 , M2 , F , typename _maps_bits::CombineValue< M1 , M2 , F >::type > combineMap(
const M1 & m1,
const M2 & m2,
const F & f
)
template< typename M1 , typename M2 , typename K1 , typename K2 , typename V >
inline CombineMap< M1 , M2 , V (*)(K1, K2) , V > combineMap(
const M1 & m1,
const M2 & m2,
V (*f)(K1, K2)
)
template< typename F >
inline FunctorToMap< F , typename F::argument_type , typename F::result_type > functorToMap(
const F & f
)
template< typename K , typename V >
inline FunctorToMap< V (*)(K) , K , V > functorToMap(
V (*f)(K)
)