PrevNextUpHome SophiaFramework UNIVERSE 5.3

22.2. Smart Pointer Class for the BREW Interface

The SFXBrewPointer class is the smart pointer class for managing an instance of the BREW interface. This class is template class that generates automatically types for all the kinds of wrapper classes.

To generate a type explicitly is also possible as the below.

Example 22.1.  How to use the SFXBrewPointer class

Void SFXPointerExplainer::_SFXBrewPointer(Void) const
    // Both of the following variable declarations are equivalent.
    // In general, use the Smp version which is easy to describe.

    SFXBrewPointer<SFBDisplay> display1;
    SFBDisplaySmp display2;

    // To create an instance of the wrapper class, 
    // use the  NewInstance() or GetInstance() function of each wrapper class.
    // It is unnecessary to release the instance since the smart pointer manages it.

    SFBGraphicsSmp graphics;
    SFBGraphicsPtr raw_graphics;

    if ((graphics = SFBGraphics::NewInstance()) != null) {

        // when succeed to create an insatnce

    // Get the raw pointer managed by the smart pointer.

    raw_graphics = graphics.Get();

    // Compare smart pointers of the same type.

    if (display1 == display2) {

    if (display1 != display2) {

    // Compare a smart pointer with a raw pointer.

    if (graphics == raw_graphics) {

    // Compare a smart pointer with a null pointer.

    if (graphics != null) {

    // Compare smart pointers of the different type
    // This is not recommendable, but possible by its desgin.

    if (graphics != display1) {

    // To cast the pointer of an instance managed by the smart pointer, 
    // use the opeartor such as static_pointer_cast.
    // The static_cast opeartor must not be used.

    SFBBaseSmp base;
    SFBBitmapSmp bitmap;

    base = bitmap;
    bitmap = static_pointer_cast<SFBBitmap>(base);

    // Get the empty instance.
    // This can be used as the return value of the reference to the empty instance.

    SFBFileSmpConstRef file(SFBFileSmp::EmptyInstance());


    // Release the instance managed by the smart pointer explicitly.

    SFBFileMgrSmp filemgr;

    if ((filemgr = SFBFileMgr::NewInstance()) != null) {

        // Call the Release() function of the SFXBrewPointer class.


        // In the SophiaFramework 3.0 or higher, the AddRef() or Release() function of the SFBBase (IBase) class cannot be called.