Back to index

salome-geom  6.5.0
GEOM_GenericObjPtr.h
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 //  File   : GEOM_GenericObjPtr.h
00023 //  Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
00024 
00025 #ifndef GEOM_GenericObjPtr_H
00026 #define GEOM_GenericObjPtr_H
00027 
00028 #include "GEOM_GEOMBase.hxx"
00029 
00030 #include "SALOMEconfig.h"
00031 #include CORBA_SERVER_HEADER(GEOM_Gen)
00032 
00033 namespace GEOM
00034 {
00077   template <typename TInterface> class GenericObjPtr
00078   {
00079     typedef typename TInterface::_var_type TInterfaceVar;
00080     typedef typename TInterface::_ptr_type TInterfacePtr;
00081     
00082   private:
00083     TInterfaceVar myObject;
00084 
00085   private:
00087     void Register()
00088     {
00089       if ( !CORBA::is_nil( this->myObject ) )
00090        this->myObject->Register();
00091     }
00092 
00094     void UnRegister()
00095     {
00096       if ( !CORBA::is_nil( this->myObject ) ) {
00097        this->myObject->UnRegister();
00098        this->myObject = TInterface::_nil();
00099       }
00100     }
00101       
00102   public:
00104     GenericObjPtr()
00105     {}
00106     
00108     GenericObjPtr( TInterfacePtr theObject )
00109     {
00110       this->myObject = TInterface::_duplicate( theObject );
00111       this->Register();
00112     }
00113     
00115     GenericObjPtr( const GenericObjPtr& thePointer )
00116     {
00117       this->myObject = thePointer.myObject;
00118       this->Register();
00119     }
00120     
00122     ~GenericObjPtr()
00123     {
00124       this->UnRegister();
00125     }
00126     
00128     GenericObjPtr& operator=( TInterfacePtr theObject )
00129     {
00130       this->UnRegister();
00131       this->myObject = TInterface::_duplicate( theObject );
00132       this->Register();
00133       return *this;
00134     }
00135 
00137     GenericObjPtr& operator=( const GenericObjPtr& thePointer )
00138     {
00139       this->UnRegister();
00140       this->myObject = thePointer.myObject;
00141       this->Register();
00142       return *this;
00143     }
00144 
00145     static bool isSame( TInterfacePtr theLeft, TInterfacePtr theRight )
00146     {
00147       return theLeft->_is_equivalent( theRight );
00148     }
00149 
00151     bool operator==( TInterfacePtr theObject )
00152     {
00153       return isSame( this->myObject, theObject );
00154     }
00155 
00157     bool operator==( const GenericObjPtr& thePointer )
00158     {
00159       return isSame( this->myObject, thePointer.get() );;
00160     }
00161 
00163     bool operator!=( TInterfacePtr theObject )
00164     {
00165       return !isSame( this->myObject, theObject );
00166     }
00167 
00169     bool operator!=( const GenericObjPtr& thePointer )
00170     {
00171       return !isSame( this->myObject, thePointer.get() );;
00172     }
00173 
00175     TInterfacePtr operator->() const
00176     {
00177       return this->get();
00178     }
00179 
00181     operator bool() const
00182     {
00183        return !this->isNull();
00184     }
00185 
00187     void take( TInterfacePtr theObject )
00188     {
00189       this->UnRegister();
00190       this->myObject = TInterface::_duplicate( theObject );
00191     }
00192 
00194     TInterfacePtr get() const
00195     {
00196       return this->myObject;
00197     }
00198 
00200     TInterfacePtr copy() const
00201     {
00202       return TInterface::_duplicate( this->myObject );
00203     }
00204     
00206     bool isNull() const
00207     {
00208       return CORBA::is_nil( this->myObject );
00209     }
00210 
00212     void nullify()
00213     {
00214       this->UnRegister();
00215     }
00216   };
00217   
00218   typedef GenericObjPtr<GEOM::GEOM_Object>               GeomObjPtr;
00219   typedef GenericObjPtr<GEOM::GEOM_IBasicOperations>     BasicOpPtr;
00220   typedef GenericObjPtr<GEOM::GEOM_ITransformOperations> TransformOpPtr;
00221   typedef GenericObjPtr<GEOM::GEOM_I3DPrimOperations>    I3DPrimOpPtr;
00222   typedef GenericObjPtr<GEOM::GEOM_IShapesOperations>    ShapesOpPtr;
00223   typedef GenericObjPtr<GEOM::GEOM_IBlocksOperations>    BlocksOpPtr;
00224   typedef GenericObjPtr<GEOM::GEOM_IBooleanOperations>   BooleanOpPtr;
00225   typedef GenericObjPtr<GEOM::GEOM_ICurvesOperations>    CurvesOpPtr;
00226   typedef GenericObjPtr<GEOM::GEOM_ILocalOperations>     LocalOpPtr;
00227   typedef GenericObjPtr<GEOM::GEOM_IHealingOperations>   HealingOpPtr;
00228   typedef GenericObjPtr<GEOM::GEOM_IInsertOperations>    InsertOpPtr;
00229   typedef GenericObjPtr<GEOM::GEOM_IMeasureOperations>   MeasureOpPtr;
00230   typedef GenericObjPtr<GEOM::GEOM_IGroupOperations>     GroupOpPtr;
00231   typedef GenericObjPtr<GEOM::GEOM_IAdvancedOperations>  AdvancedOpPtr;
00232 
00233   template<> bool GEOMBASE_EXPORT GenericObjPtr<GEOM::GEOM_Object>::isSame( GEOM::GEOM_Object_ptr theLeft, GEOM::GEOM_Object_ptr theRight );
00234 }
00235 
00236 #endif // GEOM_GenericObjPtr_H