Chris@16: // (C) Copyright 2007-2009 Andrew Sutton Chris@16: // Chris@16: // Use, modification and distribution are subject to the Chris@16: // Boost Software License, Version 1.0 (See accompanying file Chris@16: // LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_GRAPH_CONSTANT_PROPERTY_HPP Chris@16: #define BOOST_GRAPH_CONSTANT_PROPERTY_HPP Chris@16: Chris@16: #include Chris@16: Chris@16: Chris@16: // TODO: This should really be part of the property maps library rather than Chris@16: // the Boost.Graph library. Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: /** Chris@16: * A constant property is one, that regardless of the edge or vertex given, Chris@16: * will always return a constant value. Chris@16: */ Chris@16: template Chris@16: struct constant_property_map Chris@16: : public boost::put_get_helper< Chris@16: const Value&, Chris@16: constant_property_map Chris@16: > Chris@16: { Chris@16: typedef Key key_type; Chris@16: typedef Value value_type; Chris@16: typedef const Value& reference; Chris@16: typedef boost::readable_property_map_tag category; Chris@16: Chris@16: constant_property_map() Chris@16: : m_value() Chris@16: { } Chris@16: Chris@16: constant_property_map(const value_type &value) Chris@16: : m_value(value) Chris@16: { } Chris@16: Chris@16: constant_property_map(const constant_property_map& copy) Chris@16: : m_value(copy.m_value) Chris@16: { } Chris@16: Chris@16: inline reference operator [](const key_type&) const Chris@16: { return m_value; } Chris@16: Chris@16: value_type m_value; Chris@16: }; Chris@16: Chris@16: template Chris@16: inline constant_property_map Chris@16: make_constant_property(const Value& value) Chris@16: { return constant_property_map(value); } Chris@16: Chris@16: /** Chris@16: * Same as above, but pretends to be writable as well. Chris@16: */ Chris@16: template Chris@16: struct constant_writable_property_map { Chris@16: typedef Key key_type; Chris@16: typedef Value value_type; Chris@16: typedef Value& reference; Chris@16: typedef boost::read_write_property_map_tag category; Chris@16: Chris@16: constant_writable_property_map() Chris@16: : m_value() Chris@16: { } Chris@16: Chris@16: constant_writable_property_map(const value_type &value) Chris@16: : m_value(value) Chris@16: { } Chris@16: Chris@16: constant_writable_property_map(const constant_writable_property_map& copy) Chris@16: : m_value(copy.m_value) Chris@16: { } Chris@16: Chris@16: friend Value get(const constant_writable_property_map& me, Key) {return me.m_value;} Chris@16: friend void put(const constant_writable_property_map&, Key, Value) {} Chris@16: Chris@16: value_type m_value; Chris@16: }; Chris@16: Chris@16: template Chris@16: inline constant_writable_property_map Chris@16: make_constant_writable_property(const Value& value) Chris@16: { return constant_writable_property_map(value); } Chris@16: Chris@16: } /* namespace boost */ Chris@16: Chris@16: #endif