2
0
mirror of https://github.com/boostorg/graph.git synced 2026-01-31 20:22:09 +00:00

added same_property and property copy constructor

put alternate form of property usage in edge_property.cpp


[SVN r7891]
This commit is contained in:
Jeremy Siek
2000-10-03 02:56:51 +00:00
parent ce83768190
commit ea68264216
3 changed files with 72 additions and 12 deletions

View File

@@ -25,6 +25,45 @@
//
// Sample output:
//
// 0 --(8, 10)--> 1
//
// 1 --(12, 20)--> 4 --(12, 40)--> 3
// <--(8,10)-- 0 <--(16,20)-- 2
// 2 --(16, 20)--> 1
// <--(16,20)-- 5
// 3 --(12, 40)--> 6
// <--(12,40)-- 1
// 4 --(12, 20)--> 7
// <--(12,20)-- 1
// 5 --(16, 20)--> 2
// <--(16,20)-- 6
// 6 --(16, 20)--> 5 --(8, 10)--> 8
// <--(12,20)-- 7 <--(12,40)-- 3
// 7 --(12, 20)--> 6
// <--(12,20)-- 4
// 8
// <--(8,10)-- 6
//
//
// 0 --(8, 1)--> 1
//
// 1 --(12, 2)--> 4 --(12, 3)--> 3
// <--(8,1)-- 0 <--(16,4)-- 2
// 2 --(16, 4)--> 1
// <--(16,7)-- 5
// 3 --(12, 5)--> 6
// <--(12,3)-- 1
// 4 --(12, 6)--> 7
// <--(12,2)-- 1
// 5 --(16, 7)--> 2
// <--(16,8)-- 6
// 6 --(16, 8)--> 5
// <--(12,10)-- 7 <--(12,5)-- 3
// 7 --(12, 10)--> 6
// <--(12,6)-- 4
// 8
//
#include <iostream>
#include <boost/utility.hpp>
@@ -36,6 +75,7 @@ using namespace boost;
using namespace std;
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
enum edge_flow_t { edge_flow = 100 };
enum edge_capacity_t { edge_capacity = 101 };
@@ -43,6 +83,10 @@ namespace boost {
BOOST_INSTALL_PROPERTY(edge, flow);
BOOST_INSTALL_PROPERTY(edge, capacity);
}
#else
struct edge_flow_t { typedef edge_property_tag kind; } edge_flow;
struct edge_capacity_t { typedef edge_property_tag kind; } edge_capacity;
#endif
template <class Graph, class Capacity, class Flow>
void print_network(Graph& G, Capacity capacity, Flow flow)

View File

@@ -7,6 +7,23 @@ namespace boost {
namespace detail {
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
template <class Property1, class Property2>
struct same_property {
enum { value = int(property_num<Property1>::value)
== int(property_num<Property2>::value) };
};
#else
template <class Property1, class Property2>
struct same_property {
enum { value = false };
};
template <class Property>
struct same_property<Property,Property> {
enum { value = true };
};
#endif
template <int TagMatched>
struct property_value_dispatch { };
@@ -27,8 +44,7 @@ namespace boost {
static T& get_value(Property& p, T t, Tag tag) {
typedef typename Property::next_type Next;
typedef typename Next::tag_type Next_tag;
enum { match = int(property_num<Next_tag>::value)
== int(property_num<Tag>::value) };
enum { match = same_property<Next_tag,Tag>::value };
return property_value_dispatch<match>
::get_value(static_cast<Next&>(p), t, tag);
}
@@ -36,8 +52,7 @@ namespace boost {
static const T& const_get_value(const Property& p, T t, Tag tag) {
typedef typename Property::next_type Next;
typedef typename Next::tag_type Next_tag;
enum { match = int(property_num<Next_tag>::value)
== int(property_num<Tag>::value) };
enum { match = same_property<Next_tag,Tag>::value };
return property_value_dispatch<match>
::const_get_value(static_cast<const Next&>(p), t, tag);
}
@@ -95,11 +110,10 @@ namespace boost {
typedef typename TagValueAList::first_type AListFirst;
typedef typename AListFirst::first_type Tag2;
typedef typename AListFirst::second_type Value;
enum { tag1 = property_num<Tag1>::value,
tag2 = property_num<Tag2>::value };
enum { match = same_property<Tag1,Tag2>::value };
typedef typename TagValueAList::second_type Next;
typedef typename ev_selector<Next>::type Extractor;
typedef typename boost::ct_if< (tag1==tag2), Value,
typedef typename boost::ct_if< match, Value,
typename Extractor::template bind<Next,Tag1>::type
>::type type;
};

View File

@@ -16,12 +16,13 @@ namespace boost {
typedef Tag tag_type;
typedef T value_type;
property() { }
property(const property& x) : Base(x), m_value(x.m_value) { }
property(const T& v) : m_value(v) { }
property(const T& v, const Base& b) : Base(b), m_value(v) { }
T m_value;
};
// The BGL properties just specialize property_kind and
// The BGL properties specialize property_kind and
// property_num, and use enum's for the Property type (see
// graph/properties.hpp), but the user may want to use a class
// instead with a nested kind type and num. Also, we may want to
@@ -32,6 +33,9 @@ namespace boost {
typedef typename Property::kind type;
};
// The property_num is only needed for no partial spec. workaround
// in detail::same_property.
template <class Property>
struct property_num {
enum { value = Property::num };
@@ -47,16 +51,14 @@ namespace boost {
template <class Tag1, class Tag2, class T1, class T2, class Base>
inline T2&
get_property_value(property<Tag1,T1,Base>& p, T2 t2, Tag2 tag2) {
enum { match = int(property_num<Tag1>::value)
== int(property_num<Tag2>::value) };
enum { match = detail::same_property<Tag1,Tag2>::value };
typedef detail::property_value_dispatch<match> Dispatcher;
return Dispatcher::get_value(p, t2, tag2);
}
template <class Tag1, class Tag2, class T1, class T2, class Base>
inline const T2&
get_property_value(const property<Tag1,T1,Base>& p, T2 t2, Tag2 tag2) {
enum { match = int(property_num<Tag1>::value)
== int(property_num<Tag2>::value) };
enum { match = detail::same_property<Tag1,Tag2>::value };
typedef detail::property_value_dispatch<match> Dispatcher;
return Dispatcher::const_get_value(p, t2, tag2);
}