Back to index

salome-geom  6.5.0
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes
GEOM::GenericObjPtr< TInterface > Class Template Reference

A smart pointer for the SALOME GenericObj interface. More...

#include <GEOM_GenericObjPtr.h>

List of all members.

Public Member Functions

 GenericObjPtr ()
 Initialize pointer to nil generic object reference.
 GenericObjPtr (TInterfacePtr theObject)
 Initialize pointer to the given generic object reference.
 GenericObjPtr (const GenericObjPtr &thePointer)
 Initialize pointer with a new reference to the same object referenced by given pointer.
 ~GenericObjPtr ()
 Destroy pointer and remove the reference to the object.
GenericObjPtroperator= (TInterfacePtr theObject)
 Assign object to reference and remove reference to an old object.
GenericObjPtroperator= (const GenericObjPtr &thePointer)
 Assign object to reference and remove reference to an old object.
bool operator== (TInterfacePtr theObject)
 Check equivalence.
bool operator== (const GenericObjPtr &thePointer)
 Check equivalence.
bool operator!= (TInterfacePtr theObject)
 Check difference.
bool operator!= (const GenericObjPtr &thePointer)
 Check difference.
TInterfacePtr operator-> () const
 Provides normal pointer target member access using operator ->.
 operator bool () const
 Check validity of the pointer.
void take (TInterfacePtr theObject)
 Initialize pointer to the given generic object reference and take ownership on it.
TInterfacePtr get () const
 Get the contained object.
TInterfacePtr copy () const
 Make the copy of the contained object and return it (caller becomes owner of the CORBA reference).
bool isNull () const
 Check if pointer is null.
void nullify ()
 Nullify pointer.
template<>
bool isSame (GEOM::GEOM_Object_ptr theLeft, GEOM::GEOM_Object_ptr theRight)
template<>
bool GEOMBASE_EXPORT isSame (GEOM::GEOM_Object_ptr theLeft, GEOM::GEOM_Object_ptr theRight)

Static Public Member Functions

static bool isSame (TInterfacePtr theLeft, TInterfacePtr theRight)

Private Types

typedef TInterface::_var_type TInterfaceVar
typedef TInterface::_ptr_type TInterfacePtr

Private Member Functions

void Register ()
 Increment counter for the object.
void UnRegister ()
 Decrement counter for the object.

Private Attributes

TInterfaceVar myObject

Detailed Description

template<typename TInterface>
class GEOM::GenericObjPtr< TInterface >

A smart pointer for the SALOME GenericObj interface.

This class can be used in conjunction with the references to the CORBA objects which interfaces are inherited from the SALOME::GenericObj CORBA interface.

The smart pointer class automatically invokes Register() / UnRegister() functions of th interface in order to prevent memory leaks and other such problems caused by improper usage of the CORBA references.

Smart pointers can be easily copied, stored within class as data members, passed to the functions requiring native CORBA reference as parameters, etc.

Usage:

Examples:

    typedef GEOM::GenericObjPtr<MyInterface> MyIPtr;
    void MyInterface_ptr foo();
    void MyInterface_ptr bar( MyInterface_ptr p );

    MyIPtr v1;                       // create empty (nil) pointer
    MyIPtr v2 = foo();               // get some CORBA reference and store it within the smart pointer
    v1 = v2;                         // copy smart pointer (reference counter is incremented)
    v2 = bar( v1.get() );            // pass smart pointer to the function
    MyInterface_var var = v2.copy(); // initialize _var variable with the smart pointer contents
    v1.take( foo() );                // take ownership on the newly created object

Definition at line 77 of file GEOM_GenericObjPtr.h.


Member Typedef Documentation

template<typename TInterface >
typedef TInterface::_ptr_type GEOM::GenericObjPtr< TInterface >::TInterfacePtr [private]

Definition at line 80 of file GEOM_GenericObjPtr.h.

template<typename TInterface >
typedef TInterface::_var_type GEOM::GenericObjPtr< TInterface >::TInterfaceVar [private]

Definition at line 79 of file GEOM_GenericObjPtr.h.


Constructor & Destructor Documentation

template<typename TInterface >
GEOM::GenericObjPtr< TInterface >::GenericObjPtr ( ) [inline]

Initialize pointer to nil generic object reference.

Definition at line 104 of file GEOM_GenericObjPtr.h.

    {}
template<typename TInterface >
GEOM::GenericObjPtr< TInterface >::GenericObjPtr ( TInterfacePtr  theObject) [inline]

Initialize pointer to the given generic object reference.

Definition at line 108 of file GEOM_GenericObjPtr.h.

    {
      this->myObject = TInterface::_duplicate( theObject );
      this->Register();
    }

Here is the call graph for this function:

template<typename TInterface >
GEOM::GenericObjPtr< TInterface >::GenericObjPtr ( const GenericObjPtr< TInterface > &  thePointer) [inline]

Initialize pointer with a new reference to the same object referenced by given pointer.

Definition at line 115 of file GEOM_GenericObjPtr.h.

    {
      this->myObject = thePointer.myObject;
      this->Register();
    }

Here is the call graph for this function:

template<typename TInterface >
GEOM::GenericObjPtr< TInterface >::~GenericObjPtr ( ) [inline]

Destroy pointer and remove the reference to the object.

Definition at line 122 of file GEOM_GenericObjPtr.h.

    {
      this->UnRegister();
    }

Here is the call graph for this function:


Member Function Documentation

template<typename TInterface >
TInterfacePtr GEOM::GenericObjPtr< TInterface >::copy ( ) const [inline]

Make the copy of the contained object and return it (caller becomes owner of the CORBA reference).

Definition at line 200 of file GEOM_GenericObjPtr.h.

    {
      return TInterface::_duplicate( this->myObject );
    }

Here is the caller graph for this function:

template<typename TInterface >
TInterfacePtr GEOM::GenericObjPtr< TInterface >::get ( ) const [inline]

Get the contained object.

Definition at line 194 of file GEOM_GenericObjPtr.h.

    {
      return this->myObject;
    }
template<typename TInterface >
bool GEOM::GenericObjPtr< TInterface >::isNull ( ) const [inline]

Check if pointer is null.

Definition at line 206 of file GEOM_GenericObjPtr.h.

    {
      return CORBA::is_nil( this->myObject );
    }

Here is the caller graph for this function:

template<>
bool GEOM::GenericObjPtr< GEOM::GEOM_Object >::isSame ( GEOM::GEOM_Object_ptr  theLeft,
GEOM::GEOM_Object_ptr  theRight 
)

Definition at line 29 of file GEOM_GenericObjPtr.cxx.

  {
    return !CORBA::is_nil( theLeft ) && !CORBA::is_nil( theRight ) && theLeft->IsSame( theRight );
  }
template<typename TInterface >
static bool GEOM::GenericObjPtr< TInterface >::isSame ( TInterfacePtr  theLeft,
TInterfacePtr  theRight 
) [inline, static]

Definition at line 145 of file GEOM_GenericObjPtr.h.

    {
      return theLeft->_is_equivalent( theRight );
    }

Here is the caller graph for this function:

template<>
bool GEOMBASE_EXPORT GEOM::GenericObjPtr< GEOM::GEOM_Object >::isSame ( GEOM::GEOM_Object_ptr  theLeft,
GEOM::GEOM_Object_ptr  theRight 
)
template<typename TInterface >
void GEOM::GenericObjPtr< TInterface >::nullify ( ) [inline]

Nullify pointer.

Definition at line 212 of file GEOM_GenericObjPtr.h.

    {
      this->UnRegister();
    }

Here is the call graph for this function:

template<typename TInterface >
GEOM::GenericObjPtr< TInterface >::operator bool ( ) const [inline]

Check validity of the pointer.

Definition at line 181 of file GEOM_GenericObjPtr.h.

    {
       return !this->isNull();
    }

Here is the call graph for this function:

template<typename TInterface >
bool GEOM::GenericObjPtr< TInterface >::operator!= ( TInterfacePtr  theObject) [inline]

Check difference.

Definition at line 163 of file GEOM_GenericObjPtr.h.

    {
      return !isSame( this->myObject, theObject );
    }

Here is the call graph for this function:

template<typename TInterface >
bool GEOM::GenericObjPtr< TInterface >::operator!= ( const GenericObjPtr< TInterface > &  thePointer) [inline]

Check difference.

Definition at line 169 of file GEOM_GenericObjPtr.h.

    {
      return !isSame( this->myObject, thePointer.get() );;
    }

Here is the call graph for this function:

template<typename TInterface >
TInterfacePtr GEOM::GenericObjPtr< TInterface >::operator-> ( ) const [inline]

Provides normal pointer target member access using operator ->.

Definition at line 175 of file GEOM_GenericObjPtr.h.

    {
      return this->get();
    }
template<typename TInterface >
GenericObjPtr& GEOM::GenericObjPtr< TInterface >::operator= ( TInterfacePtr  theObject) [inline]

Assign object to reference and remove reference to an old object.

Definition at line 128 of file GEOM_GenericObjPtr.h.

    {
      this->UnRegister();
      this->myObject = TInterface::_duplicate( theObject );
      this->Register();
      return *this;
    }

Here is the call graph for this function:

template<typename TInterface >
GenericObjPtr& GEOM::GenericObjPtr< TInterface >::operator= ( const GenericObjPtr< TInterface > &  thePointer) [inline]

Assign object to reference and remove reference to an old object.

Definition at line 137 of file GEOM_GenericObjPtr.h.

    {
      this->UnRegister();
      this->myObject = thePointer.myObject;
      this->Register();
      return *this;
    }

Here is the call graph for this function:

template<typename TInterface >
bool GEOM::GenericObjPtr< TInterface >::operator== ( TInterfacePtr  theObject) [inline]

Check equivalence.

Definition at line 151 of file GEOM_GenericObjPtr.h.

    {
      return isSame( this->myObject, theObject );
    }

Here is the call graph for this function:

template<typename TInterface >
bool GEOM::GenericObjPtr< TInterface >::operator== ( const GenericObjPtr< TInterface > &  thePointer) [inline]

Check equivalence.

Definition at line 157 of file GEOM_GenericObjPtr.h.

    {
      return isSame( this->myObject, thePointer.get() );;
    }

Here is the call graph for this function:

template<typename TInterface >
void GEOM::GenericObjPtr< TInterface >::Register ( ) [inline, private]

Increment counter for the object.

Definition at line 87 of file GEOM_GenericObjPtr.h.

    {
      if ( !CORBA::is_nil( this->myObject ) )
       this->myObject->Register();
    }

Here is the caller graph for this function:

template<typename TInterface >
void GEOM::GenericObjPtr< TInterface >::take ( TInterfacePtr  theObject) [inline]

Initialize pointer to the given generic object reference and take ownership on it.

Definition at line 187 of file GEOM_GenericObjPtr.h.

    {
      this->UnRegister();
      this->myObject = TInterface::_duplicate( theObject );
    }

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename TInterface >
void GEOM::GenericObjPtr< TInterface >::UnRegister ( ) [inline, private]

Decrement counter for the object.

Definition at line 94 of file GEOM_GenericObjPtr.h.

    {
      if ( !CORBA::is_nil( this->myObject ) ) {
       this->myObject->UnRegister();
       this->myObject = TInterface::_nil();
      }
    }

Here is the caller graph for this function:


Member Data Documentation

template<typename TInterface >
TInterfaceVar GEOM::GenericObjPtr< TInterface >::myObject [private]

Definition at line 83 of file GEOM_GenericObjPtr.h.


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