[BGL] Structure for BFSvisitor is in header file (visitor & property confusion)??

I have my graph working with BFS, and a BFSvisitor. But, I don't want the BFSvisitor to be in the header file. Since, it is, I have to declare properties I want to use in the visitor, but then I have to pass them in in the constructor for the class that contains the graph and the visitor structure ... Here is my visitor (in .hpp): /* ... other code */ /*! Structure for creating BFSvisitor * * The property maps are being assigned in the constructor for the * Ann object - I don't know how inneficient of a method that is. * i.e. if I should be using references. */ struct propagate_node : public boost::base_visitor<propagate_node> { // getting the dynamically created VoltageMap boost::property_map<Digraph, vertex_voltage_t>::type voltmap; boost::property_map<Digraph, vertex_input_t>::type inputmap; boost::property_map<Digraph, vertex_output_t>::type outputmap; typedef boost::on_discover_vertex event_filter; /* * This is a functor For Breadth First Visit. */ template <class Vertex, class Digraph> void operator()(Vertex v, Digraph& G) { boost::graph_traits<Digraph>::out_edge_iterator ed; // getting the dynamically created VoltageMap && InputMap double volt = boost::get(voltmap, v); bool in = boost::get(inputmap, v); bool out = boost::get(outputmap, v); // mapping sigmoid (don't apply sigmoid to input/output layers) if (in == false && out == false) { // justify this sigmoid ??? volt = 1/(1+pow(MYEXP,-volt)); boost::put(voltmap, v, volt); } if (v != *vertices(G).first) { for ( ed = boost::out_edges(v, G).first; ed != boost::out_edges(v, G).second; ed++) { boost::put( voltmap, target(*ed, G), get(voltmap,target(*ed,G))+get(boost::edge_weight,G,*ed)* volt); } } } } prop; /* ... other code */ So in the c'tor I have to do (in .cpp): /* ... in initializer list */ VoltageMap(get(vertex_voltage_t(), net)), InputMap(get(vertex_input_t(), net)), OutputMap(get(vertex_output_t(), net)), /* ... other code */ prop.voltmap = VoltageMap; prop.inputmap = InputMap; prop.outputmap = OutputMap; to pass my properties from the graph to the visitor ... there has to be a better way to do this. How can I put the visitor definition into the .cpp, and only declare it in the .hpp?

The full files are at: http://public.reducis.org/downloads/ann.hpp http://public.reducis.org/downloads/ann.cpp Also, if you see any other weird things that I'm doing with the graph library, let me know because I need to significantly improve my BGL/C++.

to pass my properties from the graph to the visitor ... there has to be a better way to do this. How can I put the visitor definition into the .cpp, and only declare it in the .hpp?
If the only place you're using the visitor is within the cpp file, then you just put it where it's being used. If you're going to be using the same visitor in multiple sources, it has to be in an hpp - unless you want to #include a cpp file, but that's not done very often. As for the rest... it looks okay, but I only really gave a cursory glance. Property maps are (almost) always passed by value, so you don't need to worry about keeping references to them. Andrew Sutton andrew.n.sutton@gmail.com
participants (2)
-
Andrew Sutton
-
Trevor Bain