IMP logo
Public Types | Public Member Functions
IMP::base::Pointer< O > Struct Template Reference

Detailed Description

template<class O>
struct IMP::base::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 creating Object instances in C++, you should write code like:

em::FitRestraint* create_fit_restraint(std::string mapname,
const ParticlesTemp &ps) {
IMP_NEW(core::LeavesRefiner, lr, (atom::Hierarchy::get_traits()));
IMP_NEW(em::FitRestraint, fr, (ps, map, lr));
return fr.release();
}

which is equivalent to

IMP::em::FitRestraint* create_fit_restraint(std::string mapname,
const ParticlesTemp &ps) {
Pointer<core::LeavesRefiner> lr
= new core::LeavesRefiner(atom::Hierarchy::get_traits());
= em::read_map("file_name.mrc");
Pointer<em::FitRestraint> fr= new em::FitRestraint(ps, map, lr));
return fr.release();
}

There are several important things to note in this code:

Note:
Use an IMP::WeakPointer to break cycles or to point to non-ref-counted objects.
Parameters:
[in]OThe type of IMP::RefCounted-derived object to point to

Inherits PointerBase< internal::RefCountedPointerTraits< O > >.

List of all members.

Public Types

typedef internal::PointerBase
< internal::RefCountedPointerTraits
< O > > 
P

Public Member Functions

template<class Any >
 Pointer (const Any &o)
template<class OT >
Pointer< O > & operator= (const internal::PointerBase< OT > &o)
template<class OT >
Pointer< O > & operator= (OT *o)
Pointer< O > & operator= (nullptr_t o)
Pointer< O > & operator= (const P &o)

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

Generated on Tue May 22 2012 23:33:28 for IMP by doxygen 1.8.1