Boost logo

Boost Users :

From: Stephen Torri (storri_at_[hidden])
Date: 2007-04-12 17:19:47


On Thu, 2007-04-12 at 23:50 +0300, Peter Dimov wrote:
> > void
> > add_Component ( Component::ptr_t obj_ptr )
> > {
> > bool no_duplicate;
> > IdVertexMap_t::iterator pos;
> > Vertex_t node;
> >
> > if ( obj_ptr.get() == 0 )
> > {
> > std::cerr << boost::format("Exception throw in %s at
> > line %d") % __FILE__
> > % __LINE__
> > << std::endl;
> >
> > return;
> > }
> >
> > boost::tie (pos, no_duplicate) = m_index.insert
> > (std::make_pair(obj_ptr->get_ID(), node));
>
> MSVC 8 says that you're using an uninitialized 'node' variable here. Is this
> intended?

The code needs to be changed to creating and fully initializing a node
before adding it. If you read the rest of the function you will notice
that I add the unitialized Vertex, grab a handle to it and then fill it
in.

I see the add_vertex function that takes in a const VertexProperties. So
I can probably do something like:

// CREATE property A to contain vertex_index and integer for id
// CREATE property B to contain vertex_name and obj_ptr and A reference
as base
// CALL add_vertex ( property B, m_graph )

        void add_Component ( Component::ptr_t obj_ptr )
        {
            if ( obj_ptr.get() == 0 )
               {
                  std::cerr << boost::format("Exception throw in %s at line %d")
                            % __FILE__
                            % __LINE__
                                  << std::endl;
        
                        return;
                }
        
             // Search to see if the ID is already in the index map
             IdVertexMap_t::iterator pos = m_index.find ( obj_ptr->get_ID() );
        
             if ( pos == m_index.end() )
                {
                     // Insertion was successful
        
                    VertexProperty_t comp_index_property ( obj_ptr->get_ID() );
                     boost::property< boost::vertex_name_t, boost::shared_ptr<Component> > comp_property ( obj_ptr, comp_index_property );
        
                     // Make a new vertex and return handle to 'node'
                     node = add_vertex ( comp_index_property, m_graph );
        
                   // Add vertex to id map
                     m_index.insert ( std::make_pair ( obj_ptr->get_ID(), node ) );
        
                     for ( std::map<boost::uint32_t,bool>::const_iterator cpos =
                                obj_ptr->get_Source_List_Begin();
                              cpos != obj_ptr->get_Source_List_End();
                              ++cpos )
                            {
                                this->add_Child ( (*cpos).first, obj_ptr );
                            }
                    }
                else
                    {
                        std::cerr << "ERROR: Duplicate source found. Skipping Component"
                                  << std::endl;
                        return;
                   }
            }
        }
        
Now I have not compiled this since I am unsure I am understanding the
boost::property constructors correctly. If my VertexProperties_t is
define as follows am I correct or do I have the order reverse? Is this
the best way to initialize a property?

        typedef property< vertex_index_t,
                          uint32_t,
                          property< vertex_name_t,
                                    boost::shared_ptr<Component> > >
        VertexProperty_t;

Stephen


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