class O2G2Ptr(T)

Brief

Auto-release template class

Parameters
T

The class name.

The class must be derived from IAddRef interface.

Details

The class is designed to release an instance of the specified class automatically, when the scope (for example function) is finished or when containing class is destroyed.

You may use this class instead of pointer to class T to be sure that an instance referenced will be released properly.

Using IAddRef-derived class without O2G2Ptr template [hide]

{
    IO2GResponseReaderFactory *factory = mSession->getResponseReaderFactory();
    if (factory)
    {
        IO2GOrderResponseReader *reader = factory->createOrderResponseReader(response);
        if (reader == 0)
        {
            factory->release();
            return;
        }
 
        // use reader
        ...
        reader->release();
    }
 
    factory->release();
}

Using IAddRef-derived class with O2G2Ptr template [hide]

{
    O2G2Ptr<IO2GResponseReaderFactory> factory = mSession->getResponseReaderFactory();
    if (factory)
    {
        O2G2Ptr<IO2GOrderResponseReader> reader = factory->createOrderResponseReader(response);
        if (reader == 0)
            return;
 
        // use reader
        ...
    }
}

Public Constructors

O2G2Ptr

Parameterized constructor

O2G2Ptr

Copying constructor

Public Methods

~O2G2Ptr

Destructor

Detach

Detaches the contained object.

operator !()

Returns true if the pointer contained is null.

operator ==()

Returns true if the pointer contained is equal to the pointer specified.

operator ->()

Member operator.

operator bool()

Returns true if the pointer contained is not null.

operator T*()

Gets the pointer to contained object.

back