// (C) Copyright Andrew Sutton 2009 // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #include #include #include #include "typestr.hpp" using namespace boost; struct TestProps { typedef property VertexProp; typedef property EdgeName; typedef property EdgeProp; typedef adjacency_list< vecS, vecS, bidirectionalS, VertexProp, EdgeProp > Graph; typedef subgraph Subgraph; typedef graph_traits::vertex_descriptor Vertex; typedef graph_traits::edge_descriptor Edge; typedef graph_traits::vertex_iterator VertexIter; typedef std::pair VertexRange; static void run() { // Create a graph with some vertices. Subgraph g(5); VertexRange r = vertices(g); // Create a child subgraph and add some vertices. Subgraph& sg = g.create_subgraph(); Vertex v = add_vertex(*r.first, sg); typedef property_map::type DefaultMap; DefaultMap map = get(vertex_name, g); BOOST_ASSERT(get(map, v) == 0); put(map, v, 5); BOOST_ASSERT(get(map, v) == 5); typedef global_property GlobalProp; typedef property_map::type GlobalVertMap; GlobalVertMap groot = get(global(vertex_name), g); GlobalVertMap gsub = get(global(vertex_name), sg); BOOST_ASSERT(get(groot, v) == 5); BOOST_ASSERT(get(gsub, v) == 5); put(gsub, v, 10); BOOST_ASSERT(get(groot, v) == 10); BOOST_ASSERT(get(gsub, v) == 10); BOOST_ASSERT(get(map, v) == 10); typedef local_property LocalProp; typedef property_map::type LocalVertMap; LocalVertMap lroot = get(local(vertex_name), g); // Actually global! LocalVertMap lsub = get(local(vertex_name), sg); BOOST_ASSERT(get(lroot, v) == 10); // Recall it's 10 from above! BOOST_ASSERT(get(lsub, v) == 0); put(lsub, v, 5); BOOST_ASSERT(get(lsub, v) == 5); BOOST_ASSERT(get(lroot, v) == 10); // Don't change the root prop BOOST_ASSERT(get(map, v) == 10); // Don't change the root prop // typedef detail::subgraph_local_pmap::bind_ PM; // std::cout << typestr() << "\n"; // std::cout << typestr() << "\n"; } }; struct TestBundles { struct Node { Node() : value(-1) { } int value; }; struct Arc { Arc() : value(-1) { } int value; }; typedef property EdgeProp; typedef adjacency_list< vecS, vecS, bidirectionalS, Node, EdgeProp > Graph; typedef subgraph Subgraph; typedef graph_traits::vertex_descriptor Vertex; typedef graph_traits::edge_descriptor Edge; typedef graph_traits::vertex_iterator VertexIter; typedef std::pair VertexRange; static void run() { // Create a graph with some vertices. Subgraph g(5); VertexRange r = vertices(g); // Create a child subgraph and add some vertices. Subgraph& sg = g.create_subgraph(); Vertex v = add_vertex(*r.first, sg); sg[v].value = 1; BOOST_ASSERT(sg[v].value == 1); BOOST_ASSERT(sg[global(v)].value == 1); BOOST_ASSERT(sg[local(v)].value == -1); sg[local(v)].value = 5; BOOST_ASSERT(sg[local(v)].value == 5); BOOST_ASSERT(sg[global(v)].value == 1); BOOST_ASSERT(sg[v].value == 1); typedef property_map< Subgraph, local_property >::type LocalVertMap; LocalVertMap lvm = get(local(&Node::value), sg); BOOST_ASSERT(get(lvm, v) == 5); typedef property_map< Subgraph, global_property >::type GlobalVertMap; GlobalVertMap gvm = get(global(&Node::value), sg); BOOST_ASSERT(get(gvm, v) == 1); } }; int main(int argc, char* argv[]) { TestProps::run(); TestBundles::run(); return 0; }