Hi guys, the boost graph library has an example on using bundled properties. I would like to serialise the resulting graph into graphml. Using dynamic_properties for the std::vector attribute fails to compile with boost 1.41. Is there a way to get this example below to work? I would greatly appreciate it. Thanks, Dominik #include <vector> #include <string> #include <boost/graph/adjacency_list.hpp> #include <boost/property_map/dynamic_property_map.hpp> struct City { std::string name; int population; std::vector<int> zipcodes; }; struct Highway { std::string name; double miles; int speed_limit; int lanes; bool divided; }; int main() { typedef boost::adjacency_list< boost::listS, boost::vecS, boost::bidirectionalS, City, Highway> Graph; Graph g; Graph::vertex_descriptor v = *vertices(g).first; g[v].name = "Troy"; g[v].population = 49170; g[v].zipcodes.push_back(12180); Graph::edge_descriptor e = *out_edges(v, g).first; g[e].name = "I-87"; g[e].miles = 10; g[e].speed_limit = 65; g[e].lanes = 4; g[e].divided = true; boost::dynamic_properties dp; // dp.property("zip_codes", boost::get(&City::zipcodes, g)); dp.property("name", boost::get(&City::name, g)); return EXIT_SUCCESS; } -- Dominik Dahlem <Dominik.Dahlem@scss.tcd.ie> ------------------------------------------------------- Trinity College Dublin School of Computer Science and Statistics, Dublin 2, Ireland tel: (+353) 1-896 3789 fax: (+353) 1-677 2204 www: http://www.cs.tcd.ie/Dominik.Dahlem/ -------------------------------------------------------
On Fri, 11 Jun 2010, Dominik Dahlem wrote:
Hi guys,
the boost graph library has an example on using bundled properties. I would like to serialise the resulting graph into graphml. Using dynamic_properties for the std::vector attribute fails to compile with boost 1.41. Is there a way to get this example below to work? I would greatly appreciate it.
What error message do you get from the vector<int> example? I do not see any obvious reason that a vector would behave differently from a string, although the lack of a streaming operator or something might break it. Is the issue in creating a dynamic_properties object (or adding your property map to it) or in the output of the properties? -- Jeremiah Willcock
Jeremiah Willcock <jewillco@osl.iu.edu> writes:
What error message do you get from the vector<int> example? I do not see any obvious reason that a vector would behave differently from a string, although the lack of a streaming operator or something might break it. Is the issue in creating a dynamic_properties object (or adding your property map to it) or in the output of the properties?
The issue is in creating the dynamic_properties object. The complete error message is as follows: /usr/include/boost/property_map/dynamic_property_map.hpp: In member function ‘std::string boost::detail::dynamic_property_map_adaptor<PropertyMap>::get_string(const boost::any&) [with PropertyMap = boost::bundle_property_map<boost::adjacency_list<boost::listS, boost::vecS, boost::bidirectionalS, City, Highway, boost::no_property, boost::listS>, unsigned int, City, std::vector<int, std::allocator<int> > >]’: network_add_vertices.cc:62: instantiated from here /usr/include/boost/property_map/dynamic_property_map.hpp:196: error: no match for ‘operator<<’ in ‘out << boost::get [with PropertyMap = boost::bundle_property_map<boost::adjacency_list<boost::listS, boost::vecS, boost::bidirectionalS, City, Highway, boost::no_property, boost::listS>, unsigned int, City, std::vector<int, std::allocator<int> > >, Reference = std::vector<int, std::allocator<int> >&, K = unsigned int](((const boost::put_get_helper<std::vector<int, std::allocator<int> >&, boost::bundle_property_map<boost::adjacency_list<boost::listS, boost::vecS, boost::bidirectionalS, City, Highway, boost::no_property, boost::listS>, unsigned int, City, std::vector<int, std::allocator<int> > > >&)((const boost::put_get_helper<std::vector<int, std::allocator<int> >&, boost::bundle_property_map<boost::adjacency_list<boost::listS, boost::vecS, boost::bidirectionalS, City, Highway, boost::no_property, boost::listS>, unsigned int, City, std::vector<int, std::allocator<int> > > >*)(&((boost::detail::dynamic_property_map_adaptor<boost::bundle_property_map<boost::adjacency_list<boost::listS, boost::vecS, boost::bidirectionalS, City, Highway, boost::no_property, boost::listS>, unsigned int, City, std::vector<int, std::allocator<int> > > >*)this)->boost::detail::dynamic_property_map_adaptor<boost::bundle_property_map<boost::adjacency_list<boost::listS, boost::vecS, boost::bidirectionalS, City, Highway, boost::no_property, boost::listS>, unsigned int, City, std::vector<int, std::allocator<int> > > >::property_map))), ((const unsigned int&)((const unsigned int*)(& boost::any_cast [with ValueType = unsigned int](((const boost::any&)((const boost::any*)key)))))))’ /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/ostream:112: note: candidates are: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>& (*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/ostream:121: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/ostream:131: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/ostream:169: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/ostream:173: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/ostream:177: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/bits/ostream.tcc:97: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/ostream:184: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/bits/ostream.tcc:111: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/ostream:195: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/ostream:204: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/ostream:208: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/ostream:213: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/ostream:217: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/ostream:225: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/ostream:229: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/bits/ostream.tcc:125: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/boost/lexical_cast.hpp: In member function ‘bool boost::detail::lexical_stream_limited_src<CharT, Base, Traits>::operator>>(InputStreamable&) [with InputStreamable = std::vector<int, std::allocator<int> >, CharT = char, Base = std::basic_streambuf<char, std::char_traits<char> >, Traits = std::char_traits<char>]’: /usr/include/boost/lexical_cast.hpp:1151: instantiated from ‘Target boost::detail::lexical_cast(typename boost::call_traits<Source>::param_type, CharT*, size_t) [with Target = std::vector<int, std::allocator<int> >, Source = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool Unlimited = false, CharT = boost::lexical_cast::char_type]’ /usr/include/boost/lexical_cast.hpp:1174: instantiated from ‘Target boost::lexical_cast(const Source&) [with Target = std::vector<int, std::allocator<int> >, Source = std::basic_string<char, std::char_traits<char>, std::allocator<char> >]’ /usr/include/boost/property_map/dynamic_property_map.hpp:42: instantiated from ‘Value boost::detail::read_value(const std::string&) [with Value = std::vector<int, std::allocator<int> >]’ /usr/include/boost/property_map/dynamic_property_map.hpp:160: instantiated from ‘void boost::detail::dynamic_property_map_adaptor<PropertyMap>::do_put(const boost::any&, const boost::any&, mpl_::bool_<true>) [with PropertyMap = boost::bundle_property_map<boost::adjacency_list<boost::listS, boost::vecS, boost::bidirectionalS, City, Highway, boost::no_property, boost::listS>, unsigned int, City, std::vector<int, std::allocator<int> > >]’ /usr/include/boost/property_map/dynamic_property_map.hpp:203: instantiated from ‘void boost::detail::dynamic_property_map_adaptor<PropertyMap>::put(const boost::any&, const boost::any&) [with PropertyMap = boost::bundle_property_map<boost::adjacency_list<boost::listS, boost::vecS, boost::bidirectionalS, City, Highway, boost::no_property, boost::listS>, unsigned int, City, std::vector<int, std::allocator<int> > >]’ network_add_vertices.cc:62: instantiated from here /usr/include/boost/lexical_cast.hpp:785: error: no match for ‘operator>>’ in ‘stream >> output’ /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/istream:123: note: candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>& (*)(std::basic_istream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/istream:127: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/istream:134: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/istream:170: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/istream:174: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/istream:177: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/istream:181: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/istream:184: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/istream:188: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/istream:192: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/istream:197: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/istream:201: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/istream:206: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(float&) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/istream:210: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(double&) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/istream:214: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long double&) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/istream:218: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/istream:242: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>] -- Dominik Dahlem <Dominik.Dahlem@scss.tcd.ie> ------------------------------------------------------- Trinity College Dublin School of Computer Science and Statistics, Dublin 2, Ireland tel: (+353) 1-896 3789 fax: (+353) 1-677 2204 www: http://www.cs.tcd.ie/Dominik.Dahlem/ -------------------------------------------------------
On Fri, 11 Jun 2010, Dominik Dahlem wrote:
Jeremiah Willcock <jewillco@osl.iu.edu> writes:
What error message do you get from the vector<int> example? I do not see any obvious reason that a vector would behave differently from a string, although the lack of a streaming operator or something might break it. Is the issue in creating a dynamic_properties object (or adding your property map to it) or in the output of the properties?
The issue is in creating the dynamic_properties object. The complete error message is as follows:
The dynamic_properties object needs to know how to print your property (here vector<int>) to a stream and read it back; the lack of that is causing the error message. The best way to solve the problem is to create a new object that wraps a vector<int> and has customized operator<<() and operator>>(); you can then use that as your property type. You cannot add those operators to vector<int> itself AFAIK. -- Jeremiah Willcock
participants (2)
-
Dominik Dahlem
-
Jeremiah Willcock