PropertyWriter problem - how to handle a boost::shared_ptr type

I have the following graph: typedef property< vertex_index_t, uint32_t, property< vertex_name_t, boost::shared_ptr<Component> > > VertexProperty; typedef adjacency_list<setS, // OutEdgeList setS, // VertexList directedS, // Directed VertexProperty> // VertexProperties Graph_Type; When I looked at the documentation I did not see an example which used a boost::shared_ptr to store information at the vertex. Here is my attempt at writing a PropertyWriter. I cannot figure out how to write the 2nd function argument type: class Component_Writer { public: void operator()(std::ostream& out, const boost::shared_ptr<Component> obj) const { out << "[label=\"" << obj_ptr->get_Name() << "\n" << obj_ptr->get_ID() << "\"]"; } }; The error I get is: cd /home/storri/src/libreverse/src/infrastructure/ g++ -g -Wall -o graph_test2 graph_test2.cpp /usr/include/boost/graph/graphviz.hpp: In function `void boost::write_graphviz(std::ostream&, const Graph&, VertexPropertiesWriter, EdgePropertiesWriter, GraphPropertiesWriter) [with Graph = boost::adjacency_list<boost::setS, boost::setS, boost::directedS, boost::property<boost::vertex_index_t, uint32_t, boost::property<boost::vertex_name_t, boost::shared_ptr<Component>, boost::no_property> >, boost::no_property, boost::no_property, boost::listS>, VertexPropertiesWriter = Component_Writer, EdgePropertiesWriter = boost::default_writer, GraphPropertiesWriter = boost::default_writer]': /usr/include/boost/graph/graphviz.hpp:292: instantiated from `void boost::write_graphviz(std::ostream&, const Graph&, VertexWriter) [with Graph = boost::adjacency_list<boost::setS, boost::setS, boost::directedS, boost::property<boost::vertex_index_t, uint32_t, boost::property<boost::vertex_name_t, boost::shared_ptr<Component>, boost::no_property> >, boost::no_property, boost::no_property, boost::listS>, VertexWriter = Component_Writer]' graph_test2.cpp:484: instantiated from here /usr/include/boost/graph/graphviz.hpp:264: error: no match for call to `( Component_Writer) (std::basic_ostream<char, std::char_traits<char>
&, void* const&)' graph_test2.cpp:49: error: candidates are: void Component_Writer::operator()(std::ostream&, const boost::shared_ptr<Component>&) const
Compilation exited abnormally with code 1 at Mon Nov 8 00:15:3 Stephen -- Email: storri@torri.org

On Nov 8, 2004, at 12:16 AM, Stephen torri wrote:
I have the following graph:
typedef property< vertex_index_t, uint32_t, property< vertex_name_t, boost::shared_ptr<Component> > > VertexProperty;
typedef adjacency_list<setS, // OutEdgeList setS, // VertexList directedS, // Directed VertexProperty> // VertexProperties Graph_Type;
When I looked at the documentation I did not see an example which used a boost::shared_ptr to store information at the vertex. Here is my attempt at writing a PropertyWriter. I cannot figure out how to write the 2nd function argument type:
class Component_Writer { public: void operator()(std::ostream& out, const boost::shared_ptr<Component> obj) const { out << "[label=\"" << obj_ptr->get_Name() << "\n" << obj_ptr->get_ID() << "\"]"; } };
A property writer is passed the output stream and the descriptor, so you want to write Component_Writer like so: class Component_Writer { public: typedef boost::graph_traits<Graph_Type>::vertex_descriptor Vertex_Type; Component_Writer(const Graph_Type& g) : g(g) {} void operator()(std::ostream& out, Vertex_Type v) { boost::shared_ptr<Component> obj_ptr = get(vertex_name, g, v); // code from before... } }; Doug

On Mon, 2004-11-08 at 11:32, Doug Gregor wrote:
A property writer is passed the output stream and the descriptor, so you want to write Component_Writer like so:
class Component_Writer { public: typedef boost::graph_traits<Graph_Type>::vertex_descriptor Vertex_Type;
Component_Writer(const Graph_Type& g) : g(g) {}
void operator()(std::ostream& out, Vertex_Type v) { boost::shared_ptr<Component> obj_ptr = get(vertex_name, g, v); // code from before... } };
Doug
So if I store the Component in the Vertex by value instead of within a boost::shared_ptr then I would write the Component_Writer as: class Component_Writer { public: typedef boost::graph_traits<Graph_Type>::vertex_descriptor Vertex_Type; Component_Writer (const Graph_Type& g) : g(g) {} void operator() (std::ostream& out, Vertex_Type v) { Component obj = get (vertex_name, g, v); // code from before. } I appreciate the information. I will try these changes. Stephen -- Email: storri@torri.org

On Mon, 2004-11-08 at 11:32, Doug Gregor wrote:
A property writer is passed the output stream and the descriptor, so you want to write Component_Writer like so:
class Component_Writer { public: typedef boost::graph_traits<Graph_Type>::vertex_descriptor Vertex_Type;
Component_Writer(const Graph_Type& g) : g(g) {}
void operator()(std::ostream& out, Vertex_Type v) { boost::shared_ptr<Component> obj_ptr = get(vertex_name, g, v); // code from before... } };
Ignore previous email. My graph stores the parent type, Component, while the actual type is either A or B. So my ability to store them by the Component type alone will not work since the class contains a pure virtual function. Its still balking at compile time. I have changed the Component_Writer but I get the following compile error. The file is attached. Stephen ------------------ g++ -g -Wall -o graph_test2 graph_test2.cpp /usr/include/boost/graph/graphviz.hpp: In function `void boost::write_graphviz(std::ostream&, const Graph&, VertexPropertiesWriter, EdgePropertiesWriter, GraphPropertiesWriter) [with Graph = boost::adjacency_list<boost::setS, boost::setS, boost::directedS, boost::property<boost::vertex_index_t, uint32_t, boost::property<boost::vertex_name_t, boost::shared_ptr<Component>, boost::no_property> >, boost::no_property, boost::no_property, boost::listS>, VertexPropertiesWriter = Component_Writer, EdgePropertiesWriter = boost::default_writer, GraphPropertiesWriter = boost::default_writer]': /usr/include/boost/graph/graphviz.hpp:292: instantiated from `void boost::write_graphviz(std::ostream&, const Graph&, VertexWriter) [with Graph = boost::adjacency_list<boost::setS, boost::setS, boost::directedS, boost::property<boost::vertex_index_t, uint32_t, boost::property<boost::vertex_name_t, boost::shared_ptr<Component>, boost::no_property> >, boost::no_property, boost::no_property, boost::listS>, VertexWriter = Component_Writer]' graph_test2.cpp:499: instantiated from here /usr/include/boost/graph/graphviz.hpp:264: error: no match for call to `( Component_Writer) (std::basic_ostream<char, std::char_traits<char>
&, void* const&)' graph_test2.cpp:260: error: candidates are: void Component_Writer::operator()(std::ostream&, void*&) const
-- Email: storri@torri.org

On Nov 8, 2004, at 1:10 PM, Stephen torri wrote:
Its still balking at compile time. I have changed the Component_Writer but I get the following compile error. The file is attached.
You changed the "Vertex_Type v" to "Vertex_Type& v". You need to use either the former (copying vertex descriptors is cheap) or make that a reference to const Vertex_Type. Doug
participants (2)
-
Doug Gregor
-
Stephen torri