代码之家  ›  专栏  ›  技术社区  ›  ravenspoint

修改来自访问者的绑定属性

  •  5
  • ravenspoint  · 技术社区  · 16 年前

    如何从访问者内部修改顶点的绑定属性?

    /**
    
      A visitor which identifies vertices as leafs or trees
    
    */
    class bfs_vis_leaf_finder:public default_bfs_visitor {
    
    public:
        /**
    
        Constructor
    
        @param[in] total reference to int variable to store total number of leaves
        @param[in] g reference to graph ( used to modify bundled properties )
    
        */
        bfs_vis_leaf_finder( int& total, graph_t& g ) :
          myTotal( total ), myGraph( g )
          {
              myTotal = 0;
          }
    
        /**
    
        Called when the search finds a new vertex
    
        If the vertex has no children, it is a leaf and the total leaf count is incremented
    
        */
        template <typename Vertex, typename Graph>
        void discover_vertex( Vertex u, Graph& g)
        {
            if( out_edges( u, g ).first == out_edges( u, g ).second ) {
                myTotal++;
                //g[u].myLevel = s3d::cV::leaf;
                myGraph[u].myLevel = s3d::cV::leaf;
            } else {
                //g[u].myLevel = s3d::cV::tree;
                myGraph[u].myLevel = s3d::cV::tree;
            }
        }
    
        int& myTotal;
        graph_t& myGraph;
    };
    
    2 回复  |  直到 13 年前
        1
  •  4
  •   Jeremiah Willcock    14 年前

    你的解决方案是正确的。

    要将图形类型与访问者分离,您只能将感兴趣的属性映射传递给访问者构造函数,并使用 boost::get(property, u) = s3d::cV::leaf; . 通过这种方式,您可以将任何与类型兼容的顶点属性传递给访问者(访问者将更为通用,并且对图形类型中的名称更改不敏感)。

    typedef property_map<graph_t, s3d_cv3_leaf_t your_vertex_info::*>::type your_property_map;
    

    看见 here

        2
  •  0
  •   Catskul    16 年前

    我只是在学习这些东西,但我认为你必须在访问者中存储对图表的引用是正确的。我不确定是否是因为这个原因,但可能是因为他们不想提供所有函数的两个版本/要求派生函数提供每个函数的两个版本。特别是当图形解决方案中的过程可用时。

    推荐文章