Boost logo

Boost :

From: Dirk Gregorius (dirk_at_[hidden])
Date: 2004-11-12 06:04:32


My boost::shared_ptr objects hold pointees to interfaces. It might happen
that these raw pointees might become invalid or that I like to change the
implementation.

Is it possible to change the raw pointee of all boost::shared_ptr objects in
an application due to some kind of event?

Example:

I have one singleton class that provides several factory functions:

class Factory
{
public:
    boost::shared_ptr<IFoo> CreateX( void );
    // ... more factory functions

private:
    // Events -
    void OnChangeImplementationX( void );

    // Data members
    typedef std::vector< boost::shared_ptr<IFoo> > MasterColl;
    MasterColl m_FooObjects;
}

boost::shared_ptr<X> Factory::CreateX( void )
{
    // Create a new foo object
    boost::shared_ptr<IFoo> pFoo( new FooImpl );

   // Save a "master" instance
   m_FooObjects.push_back( pFoo );

  // Return the object
  return pFoo;

}

void Factory::OnChangeImplementationX( void )
{
    // Iterate over all "master" objects and change the underlying pointee
}

Can this be implement using the boost::shared_ptr class?

Regards,

-Dirk


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk