Boost logo

Boost Users :

From: Jeffrey Holle (jeff.holle_at_[hidden])
Date: 2004-11-23 15:51:18


You are not properly introducing your custom properties to boost.graph.
As an example of doing this correctly:

   using std::string;
   struct edgeStruct {
     int weight;
   };
   struct graphStruct {
     string name;
   };

   // create a tag for custom graph/edge properties
   enum graph_Datum_t { graph_Datum };
   enum edge_Datum_t { edge_Datum };
   namespace boost {
     BOOST_INSTALL_PROPERTY(graph,Datum);
     BOOST_INSTALL_PROPERTY(edge,Datum);
   }
   typedef boost::property<graph_Datum_t, graphStruct> GraphProperty;
   typedef boost::property<boost::edge_index_t, int> EdgeIndex;
   typedef boost::property<edge_Datum_t, edgeStruct, EdgeIndex>
EdgeProperty;

   int
   main()
   {
     using namespace boost;
     typedef
adjacency_list<vecS,vecS,directedS,no_property,EdgeProperty,GraphProperty>
graph_t;
     graph_t g;

In order to access properties of a populated graph, it is necessary to
employ property oriented boost.graph methods.

Your code example sugguests you expect things like operator[] methods
where they aren't. I too like to code in this fashion.
My solution was to make a "wrapper" class.
I've attached an example of such a class from my boost.graph using
application.
It has operator[] method and standard iterator interfaces.

Note that this class holds a boost subgraph by reference and accesses
properties only through the root subgraph. I found this necessary in
boost 1.31_0 because the properties of "derived" subgraphs had only
default contructed property classes. If this has been fixed in boost
1.32_0, I'd like to know about it.

TC MA wrote:
> After modifying it, still had some compile problems.
> using std::string;
> struct edgeStruct {
> int weight;
> };
> struct graphStruct {
> string name;
> };
>
> int
> main()
> {
> using namespace boost;
>
> typedef adjacency_list<vecS, vecS,
> directedS,no_property, edgeStruct, graphStruct>
> graph_t;
>
> graph_t g;
> graph_t::vertex_descriptor v = *vertices(g).first;
> graph_t::edge_descriptor e = *out_edges(v, g).first;
> g[e].weight = 1;
> g[e].name = "graphname";
>
> std::cout << "name: " << g[e].name << std::endl;
>
> typedef subgraph<graph_t> subgraph_t;
>
> subgraph_t sg;
> get_property(sg, graph_name) = "subgraph";
>
> std::cout << "name: " << get_property(sg,
> graph_name) << std::endl;
>
> return exit_success;
> }
>
> # compile output is:
> gcc-C++-action
> /home/tcma/cpp/boosttcma/libs/graph/graph_property.test/gcc/debug/inlining-on/graph_property.o
> /home/tcma/cpp/boosttcma/libs/graph/graph_property.cpp:
> In function `int main()':
> /home/tcma/cpp/boosttcma/libs/graph/graph_property.cpp:32:
> error: 'struct edgeStruct' has no member named 'name'
> /home/tcma/cpp/boosttcma/libs/graph/graph_property.cpp:34:
> error: 'struct edgeStruct' has no member named 'name'
> /home/tcma/cpp/boost_1_32_0/boost/graph/subgraph.hpp:
> At global scope:
> /home/tcma/cpp/boost_1_32_0/boost/graph/subgraph.hpp:
> In instantiation of
> `boost::subgraph<main()::graph_t>':
> /home/tcma/cpp/boosttcma/libs/graph/graph_property.cpp:39:
> instantiated from here
> /home/tcma/cpp/boost_1_32_0/boost/graph/subgraph.hpp:249:
> error: incomplete type
> `boost::STATIC_ASSERTION_FAILURE<0u>' used in nested
> name specifier
> /home/tcma/cpp/boost_1_32_0/boost/graph/subgraph.hpp:249:
> error: size of array has non-integral type `<type
> error>'
> /home/tcma/cpp/boost_1_32_0/boost/pending/detail/property.hpp:
> In instantiation of
> `boost::detail::build_property_tag_value_alist<graphStruct>':
> /home/tcma/cpp/boost_1_32_0/boost/pending/property.hpp:63:
> instantiated from
> `boost::property_value<graphStruct,
> boost::graph_name_t>'
> /home/tcma/cpp/boost_1_32_0/boost/graph/properties.hpp:235:
> instantiated from
> `boost::graph_property<main()::graph_t,
> boost::graph_name_t>'
> /home/tcma/cpp/boosttcma/libs/graph/graph_property.cpp:40:
> instantiated from here
> /home/tcma/cpp/boost_1_32_0/boost/pending/detail/property.hpp:94:
> error: no type named `next_type' in `struct
> graphStruct'
> /home/tcma/cpp/boost_1_32_0/boost/pending/detail/property.hpp:95:
> error: no type named `value_type' in `struct
> graphStruct'
> /home/tcma/cpp/boost_1_32_0/boost/pending/detail/property.hpp:96:
> error: no type named `tag_type' in `struct
> graphStruct'
> /home/tcma/cpp/boost_1_32_0/boost/pending/detail/property.hpp:97:
> error: no type named `next_type' in `struct
> graphStruct'
> /home/tcma/cpp/boost_1_32_0/boost/pending/detail/property.hpp:98:
> error: no type named `tag_type' in `struct
> graphStruct'
> /home/tcma/cpp/boost_1_32_0/boost/pending/property.hpp:
> In instantiation of
> `boost::property_value<graphStruct,
> boost::graph_name_t>':
> /home/tcma/cpp/boost_1_32_0/boost/graph/properties.hpp:235:
> instantiated from
> `boost::graph_property<main()::graph_t,
> boost::graph_name_t>'
> /home/tcma/cpp/boosttcma/libs/graph/graph_property.cpp:40:
> instantiated from here
> /home/tcma/cpp/boost_1_32_0/boost/pending/property.hpp:63:
> error: no type named `type' in `struct
> boost::detail::build_property_tag_value_alist<graphStruct>'
> /home/tcma/cpp/boost_1_32_0/boost/pending/property.hpp:64:
> error: no type named `type' in `struct
> boost::detail::build_property_tag_value_alist<graphStruct>'
> /home/tcma/cpp/boost_1_32_0/boost/graph/properties.hpp:
> In instantiation of
> `boost::graph_property<main()::graph_t,
> boost::graph_name_t>':
> /home/tcma/cpp/boosttcma/libs/graph/graph_property.cpp:40:
> instantiated from here
> /home/tcma/cpp/boost_1_32_0/boost/graph/properties.hpp:235:
> error: no type named `type' in `struct
> boost::property_value<graphStruct,
> boost::graph_name_t>'
> /home/tcma/cpp/boosttcma/libs/graph/graph_property.cpp:
> In function `int main()':
> /home/tcma/cpp/boosttcma/libs/graph/graph_property.cpp:40:
> error: no matching function for call to
> `get_property(main()::subgraph_t&,
> boost::graph_name_t)'
> /home/tcma/cpp/boosttcma/libs/graph/graph_property.cpp:42:
> error: no matching function for call to
> `get_property(main()::subgraph_t&,
> boost::graph_name_t)'
> /home/tcma/cpp/boost_1_32_0/boost/graph/subgraph.hpp:
> In constructor `boost::subgraph<Graph>::subgraph()
> [with Graph = main()::graph_t]':
> /home/tcma/cpp/boosttcma/libs/graph/graph_property.cpp:39:
> instantiated from here
> /home/tcma/cpp/boost_1_32_0/boost/graph/subgraph.hpp:106:
> error: no matching function for call to
> `boost::detail::error_property_not_found::error_property_not_found(int)'
> /home/tcma/cpp/boost_1_32_0/boost/pending/detail/property.hpp:21:
> note: candidates are:
> boost::detail::error_property_not_found::error_property_not_found()
> /home/tcma/cpp/boost_1_32_0/boost/pending/detail/property.hpp:21:
> note:
> boost::detail::error_property_not_found::error_property_not_found(const
> boost::detail::error_property_not_found&)
>
> set -e
> "g++" -c -Wall -ftemplate-depth-255 -g -O0
> -Wno-inline
> -I"../../../bin/boost/libs/graph/example" -I
> "/home/tcma/cpp/boost_1_32_0" -o
> "/home/tcma/cpp/boosttcma/libs/graph/graph_property.test/gcc/debug/inlining-on/graph_property.o"
>
> "/home/tcma/cpp/boosttcma/libs/graph/graph_property.cpp"
> "/usr/bin/objcopy" --set-section-flags
> .debug_str=contents,debug
> "/home/tcma/cpp/boosttcma/libs/graph/graph_property.test/gcc/debug/inlining-on/graph_property.o"
>
> ...failed gcc-C++-action
> /home/tcma/cpp/boosttcma/libs/graph/graph_property.test/gcc/debug/inlining-on/graph_property.o...
> ...skipped
> </home/tcma/cpp/boosttcma/libs/graph/graph_property.test/gcc/debug/inlining-on>/home/tcma/cpp/boosttcma/libs/graph/graph_property
> for lack of
> </home/tcma/cpp/boosttcma/libs/graph/graph_property.test/gcc/debug/inlining-on>graph_property.o...
> ...skipped
> </home/tcma/cpp/boosttcma/libs/graph/graph_property.test/gcc/debug/inlining-on>/home/tcma/cpp/boosttcma/libs/graph/graph_property.run
> for lack of
> </home/tcma/cpp/boosttcma/libs/graph/graph_property.test/gcc/debug/inlining-on>/home/tcma/cpp/boosttcma/libs/graph/graph_property...
> ...failed updating 1 target...
> ...skipped 3 targets...
>
>
>>Date: Mon, 22 Nov 2004 20:36:07 -0500
>>From: Doug Gregor <dgregor_at_[hidden]>
>>Subject: Re: [Boost-users] newbie: Graph library -
>
> bundled properties
>
>>To: boost-users_at_[hidden]
>>Message-ID:
>
> <0BEF9B5F-3CF0-11D9-84DF-000D932B7224_at_[hidden]>
>
>>Content-Type: text/plain; charset=US-ASCII;
>
> format=flowed
>
>>
>>On Nov 22, 2004, at 8:25 PM, TC MA wrote:
>>
>>>int
>>>main()
>>>{
>>> using namespace boost;
>>> using std::string;
>>
>>Move this struct...
>>
>>
>>> struct edgeStruct {
>>> int weight;
>>> };
>>
>>outside of main, because of this error message:
>>
>>
> /home/tcma/cpp/boosttcma/libs/graph/graph_property.cpp:21:
>
>>>error: `main()::edgeStruct' uses local type
>>>`main()::edgeStruct'
>>
>> Doug
>
>
> ______________________________________________________________________
> Post your free ad now! http://personals.yahoo.ca




Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net