IMP logo

IMP::Pointer< O > Class Template Reference


Detailed Description

template<class O>
class IMP::Pointer< O >

A reference counted pointer to an object.

Any time you store an Object in a C++ program, you should use a Pointer, rather than a raw C++ pointer. Using a pointer manages the reference counting and makes sure that the object is not deleted prematurely when, for example, all Python references go away and that it is deleted properly if an exception is thrown during the function. Use the IMP_NEW() macro to aid creation of pointers to new objects.

For example, when implementing a Restraint that uses a PairScore, store the PairScore like this:

    Pointer<PairScore> ps_;
When setting up restraints you should write code like this:
    IMP_NEW(IMP::core::Harmonic, h, (0,1));
    IMP::Pointer<IMP::em::DensityMap> map= IMP::em::read_map("file_name.mrc");
    IMP_NEW(IMP::core::DistancePairScore, dps, (h));
which is equivalent to
    IMP::Pointer<IMP::core::Harmonic> h= new IMP::core::Harmonic(0,1);
    IMP::Pointer<IMP::em::DensityMap> map= IMP::em::read_map("file_name.mrc");
    IMP::Pointer<IMP::core::DistancePairScore> dps
            = new IMP::core::DistancePairScore(h);
If IMP::em::read_map() fails because the file is not found (and throws an exception), h is deleted.

The object being pointed to must inherit from IMP::RefCountedObject. Use an IMP::WeakPointer to break cycles or to point to non-ref-counted objects.

Parameters:
[in] O The type of IMP::RefCounted-derived object to point to
Inheritance diagram for IMP::Pointer< O >:

Inheritance graph
[legend]

Public Member Functions

Pointer< O > & operator= (O *o)
 Set it from a possibly NULL pointer.
Pointeroperator= (const Pointer &o)
 Pointer (O *o)
 Pointer ()
 initialize to NULL
 Pointer (const Pointer &o)
O * release ()
 Relinquish control of the pointer.
 ~Pointer ()

Constructor & Destructor Documentation

template<class O>
IMP::Pointer< O >::Pointer ( const Pointer< O > &  o  ) 

copy constructor

template<class O>
IMP::Pointer< O >::Pointer ( O *  o  ) 

initialize from a pointer

template<class O>
IMP::Pointer< O >::~Pointer (  ) 

drop control of the object


Member Function Documentation

template<class O>
Pointer& IMP::Pointer< O >::operator= ( const Pointer< O > &  o  ) 

copy from another

template<class O>
O* IMP::Pointer< O >::release (  ) 

Relinquish control of the pointer.

This must be the only pointer pointing to the object. Its reference count will be 0 after the function is called, but the object will not be destroyed. Use this to safely return objects allocated within functions.


The documentation for this class was generated from the following file:

Generated on Mon Mar 8 23:08:43 2010 for IMP by doxygen 1.5.8