ReleasablePtr



Helper template class to manage releasable object pointers safely. When releasable object is assigned, its Release() method will be called at proper time. Can be used as follows.

ReleasablePtr<CReleasableObject> obj{ new CReleasableObject() }; 
// ...
// You may access CReleasableObject properties as methods in the usual way when you work with CReleasableObject pointer: obj->method() 
// ...
// Instance of CReleasableObject stored in obj will be automatically released when obj is destroyed 

You can find more information in comments below. Overrided methods can be found in corresponding base interface.

// TReleasable should be derived from IReleasable
template<class TReleasable>
class ReleasablePtr
{
public:
    ReleasablePtr(); // Create without releasable object attached 
    ReleasablePtr(TReleasable *releasable); // Create with specified releasable object attached 
    ReleasablePtr(const ReleasablePtr &other); // Copy constructor 
    ReleasablePtr(ReleasablePtr &&other); // Move constructor 
    ~ReleasablePtr(); // Destructor 

    ReleasablePtr &operator=(const ReleasablePtr &other); // Copy assignment operator 
    ReleasablePtr &operator=(ReleasablePtr &&other); // Move assignment operator 

    ReleasablePtr &operator=(TReleasable *releasable); // Assign releasable object 

    TReleasable *operator->();
    operator TReleasable*();
        
    TReleasable *move() // Return assigned releasable object and clear internal reference to it so it is not released during class instance destruction 
};
Namespace: nitisa
Include: Nitisa/Core/ReleasablePtr.h