Version: 9.12.0
GEOM::GenericObjPtr< TInterface > Class Template Reference

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

#include <GEOM_GenericObjPtr.h>

Public Member Functions

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

Private Attributes

TInterfaceVar myObject
 

Detailed Description

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

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:

  • If you want to assign the smart pointer to the CORBA _var type variable, use copy() function to make a copy of the stored CORBA object. Otherwise you might cause Segmentation Fault error.
  • To pass the smart pointer to the function that requires CORBA _ptr type parameter, use get() function.
  • If you want to take an ownership on the CORBA object, use take() function. In case of SALOME Generic object this is useful when some function returns newly created object that should be removed by the caller as soon as the object is no more required. For example, function GetSubShape() of the GEOM_IShapesOperation interface always creates new servant object and returns new object reference to it. If the object is not published in the study, it has to be destroyed and the corresponding servant should be deleted.

Examples:

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
A smart pointer for the SALOME GenericObj interface.
Definition: GEOM_GenericObjPtr.h:78

Member Typedef Documentation

◆ TInterfacePtr

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

◆ TInterfaceVar

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

Constructor & Destructor Documentation

◆ GenericObjPtr() [1/3]

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

◆ GenericObjPtr() [2/3]

template<typename TInterface >
GEOM::GenericObjPtr< TInterface >::GenericObjPtr ( TInterfacePtr  theObject)
inline

◆ GenericObjPtr() [3/3]

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

◆ ~GenericObjPtr()

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

Member Function Documentation

◆ copy()

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

◆ get()

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

◆ isNull()

template<typename TInterface >
bool GEOM::GenericObjPtr< TInterface >::isNull ( ) const
inline

◆ isSame() [1/3]

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

◆ isSame() [2/3]

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

◆ isSame() [3/3]

template<typename TInterface >
static bool GEOM::GenericObjPtr< TInterface >::isSame ( TInterfacePtr  theLeft,
TInterfacePtr  theRight 
)
inlinestatic

◆ nullify()

template<typename TInterface >
void GEOM::GenericObjPtr< TInterface >::nullify ( )
inline

◆ operator bool()

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

◆ operator!=() [1/2]

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

◆ operator!=() [2/2]

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

◆ operator->()

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

◆ operator=() [1/2]

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

◆ operator=() [2/2]

template<typename TInterface >
GenericObjPtr& GEOM::GenericObjPtr< TInterface >::operator= ( TInterfacePtr  theObject)
inline

◆ operator==() [1/2]

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

◆ operator==() [2/2]

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

◆ Register()

template<typename TInterface >
void GEOM::GenericObjPtr< TInterface >::Register ( )
inlineprivate

◆ take()

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

◆ UnRegister()

template<typename TInterface >
void GEOM::GenericObjPtr< TInterface >::UnRegister ( )
inlineprivate

Member Data Documentation

◆ myObject

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

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