IMP Reference Guide
2.20.1
The Integrative Modeling Platform
|
A smart pointer to a reference counted object. More...
#include <IMP/Pointer.h>
A smart pointer to a reference counted object.
Any time you store an Object in a C++ program, you should use a Pointer, rather than a raw C++ pointer (or PointerMember, if the pointer is stored in a class). 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:
When creating Object instances in C++, you should write code like:
which is equivalent to
There are several important things to note in this code:
[in] | O | The type of RefCounted-derived object to point to |
Public Types | |
typedef IMP::internal::PointerBase < IMP::internal::RefCountedPointerTraits < O > > | P |
Public Member Functions | |
template<class Any > | |
Pointer (const Any &o) | |
O * | get () const |
get the raw pointer to the object More... | |
template<class OT > | |
Pointer< O > & | operator= (const IMP::internal::PointerBase< OT > &o) |
template<class OT > | |
Pointer< O > & | operator= (OT *o) |
Pointer< O > & | operator= (std::nullptr_t o) |
Pointer< O > & | operator= (const P &o) |
O * | release () |
Relinquish control of the raw pointer stored in the Pointer. More... | |
O* IMP::Pointer< O >::get | ( | ) | const |
get the raw pointer to the object
O* IMP::Pointer< O >::release | ( | ) |
Relinquish control of the raw pointer stored in the Pointer.
Use this to safely return objects allocated within functions. The reference count of the object will be decreased by one, but even it it becomes 0, the object will not be destroyed.