ALPS Project: lattice library

Header file: lattice/propertymap.h

includes traits classes to inquire about the internal properties of a graph (implement the ReflectablePropertyGraph concept) and useful property maps, extending the Boost property maps

Synopsis

namespace alps {

template <class PropertyTag, class Graph, class Default=int>
struct has_property {
static const bool edge_property = false;
static const bool vertex_property = false;
static const bool graph_property = false;
static const bool any_property = false;
typedef Default vertex_property_type;
typedef Default edge_property_type;
typedef Default graph_property_type;
typedef Default property_type;
typedef property_type type;
};

template <class s1, class s2, class s3, class VP, class EP, class GP, class s4, class P, class D>
struct has_property<P, boost::adjacency_list<s1,s2,s3,VP,EP,GP,s4>, D>
{
...
};

template <class s1, class s2, class s3, class VP, class EP, class GP, class s4, class P, class D>
struct has_property<P, const boost::adjacency_list<s1,s2,s3,VP,EP,GP,s4>, D>
{
...
};

template <class PropertyTag, class Graph, class Default>
struct property_map
{
typedef ... type;
typedef ... const_type;
};

template <class PropertyTag, class Graph, class Default>
struct property_map<PropertyTag, const Graph, Default>
{
typedef ... type;
typedef ... const_type;
};


template <class PropertTag, class Graph, class Default>
typename property_map<PropertTag,Graph,Default>::type get_or_default(P p, G& g, const Default& v)


template <class V, class K=std::size_t>
class singleton_property_map {
public:
typedef K key_type;
typedef V value_type;
typedef V& reference;
typedef boost::lvalue_property_map_tag category;

singleton_property_map(V v=V());

operator value_type () const;

const singleton_property_map<V>& operator=(const value_type& v);

template <class T> V& operator[](T );
template <class T> const V& operator[](T ) const;
};

}

The has_property traits class

can be used to reflect upton the property types in a graph:
template <class PropertyTag, class Graph, class Default=int>
struct has_property

has_property is templated on the property and graph type. A default type can be provided for which a singleton_property_map is constructed if a property is not available. The traits class is currently specialized only for the boost::adjacency_list graph type and has the following members:

edge_property
is true if the property is an edge property of the graph
vertex_property
is true if the property is a vertex property of the graph
graph_property
is true if the property is a graph property of the graph
any_property
is true if the property is either a graph, edge of vertex property
vertex_property_type
is the type of property map if it is a vertex property, otherwise a singleton_property_map<Default>
edge_property_type
is the type of property map if it is an edge property, otherwise a singleton_property_map<Default>
graph_property_type
is the type of property map if it is a graph property, otherwise a singleton_property_map<Default>
property_type
is the type of property map if it is a vertex, edge or graph property, otherwise a singleton_property_map<Default>

The property_map traits class

The property_map class is an extension of the property_map class in the Boost graph library. While the Boost property_map requires that the graph has the requested property, the ALPS version provides a singleton_property_map as a default if the property does not exist. This is useful for generic functions if one does not want to specialize on the existence of a certain property.

template <class PropertyTag, class Graph, class Default>
struct property_map
{
typedef ... type;
typedef ... const_type;
};

The type members type and const_type are the types of property maps provided by boost::property_map if the property exists in the graph (i.e. if has_property<PropertyTag,Graph>::any_property is true. Otherwise it is singleton_property_map<Default>.

The singleton_property_map class

is a property map for which the value is independent of the key. Accessing it with any key will give the same value and setting the value for one key (or globally by using operator= of the property map) will set that value.
template <class V, class K=std::size_t>
class singleton_property_map

The first type V is the type of the value stored in the property map. The second type is the type used as key_type. Note that since the value of the singleton_property_map is independent of the key type, actually accessing with keys of ay type is allowed.

  typedef K key_type;
typedef V value_type;
typedef V& reference;
typedef boost::lvalue_property_map_tag category;

are the usual type defintions for property maps. Note that since the value of the singleton_property_map is independent of the key type, actually accessing with keys of ay type is allowed. The key_type is included here only because it is required of property maps.

  singleton_property_map(V =V());

initializes the property map


operator value_type () const;

const singleton_property_map<V>& operator=(const value_type& v);

template <class T> V& operator[](T );
template <class T> const V& operator[](T ) const;
};


copyright (c) 1994-2010 by Matthias Troyer

Distributed under the Boost Software License, Version 1.0. (See http://www.boost.org/LICENSE_1_0.txt)