Version: 9.16.0
GEOM_GenericObjPtr.h
Go to the documentation of this file.
1// Copyright (C) 2007-2026 CEA, EDF, OPEN CASCADE
2//
3// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5//
6// This library is free software; you can redistribute it and/or
7// modify it under the terms of the GNU Lesser General Public
8// License as published by the Free Software Foundation; either
9// version 2.1 of the License, or (at your option) any later version.
10//
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// Lesser General Public License for more details.
15//
16// You should have received a copy of the GNU Lesser General Public
17// License along with this library; if not, write to the Free Software
18// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19//
20// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21//
22// File : GEOM_GenericObjPtr.h
23// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
24
25#ifndef GEOM_GenericObjPtr_H
26#define GEOM_GenericObjPtr_H
27
28#include "GEOM_GEOMBase.hxx"
29
30#include "SALOMEconfig.h"
31#include CORBA_SERVER_HEADER(GEOM_Gen)
32
33namespace GEOM
34{
77 template <typename TInterface> class GenericObjPtr
78 {
79 typedef typename TInterface::_var_type TInterfaceVar;
80 typedef typename TInterface::_ptr_type TInterfacePtr;
81
82 private:
84
85 private:
87 void Register()
88 {
89 if ( !CORBA::is_nil( this->myObject ) )
90 this->myObject->Register();
91 }
92
95 {
96 if ( !CORBA::is_nil( this->myObject ) ) {
97 this->myObject->UnRegister();
98 this->myObject = TInterface::_nil();
99 }
100 }
101
102 public:
105 {}
106
109 {
110 this->myObject = TInterface::_duplicate( theObject );
111 this->Register();
112 }
113
115 GenericObjPtr( const GenericObjPtr& thePointer )
116 {
117 this->myObject = thePointer.myObject;
118 this->Register();
119 }
120
123 {
124 this->UnRegister();
125 }
126
129 {
130 this->UnRegister();
131 this->myObject = TInterface::_duplicate( theObject );
132 this->Register();
133 return *this;
134 }
135
138 {
139 this->UnRegister();
140 this->myObject = thePointer.myObject;
141 this->Register();
142 return *this;
143 }
144
145 static bool isSame( TInterfacePtr theLeft, TInterfacePtr theRight )
146 {
147 return theLeft->_is_equivalent( theRight );
148 }
149
151 bool operator==( TInterfacePtr theObject )
152 {
153 return isSame( this->myObject, theObject );
154 }
155
157 bool operator==( const GenericObjPtr& thePointer )
158 {
159 return isSame( this->myObject, thePointer.get() );;
160 }
161
163 bool operator!=( TInterfacePtr theObject )
164 {
165 return !isSame( this->myObject, theObject );
166 }
167
169 bool operator!=( const GenericObjPtr& thePointer )
170 {
171 return !isSame( this->myObject, thePointer.get() );;
172 }
173
176 {
177 return this->get();
178 }
179
181 operator bool() const
182 {
183 return !this->isNull();
184 }
185
187 void take( TInterfacePtr theObject )
188 {
189 this->UnRegister();
190 this->myObject = TInterface::_duplicate( theObject );
191 }
192
195 {
196 return this->myObject;
197 }
198
200 TInterfacePtr copy() const
201 {
202 return TInterface::_duplicate( this->myObject );
203 }
204
206 bool isNull() const
207 {
208 return CORBA::is_nil( this->myObject );
209 }
210
212 void nullify()
213 {
214 this->UnRegister();
215 }
216 };
217
232
233 template<> bool GEOMBASE_EXPORT GenericObjPtr<GEOM::GEOM_Object>::isSame( GEOM::GEOM_Object_ptr theLeft, GEOM::GEOM_Object_ptr theRight );
234}
235
236#endif // GEOM_GenericObjPtr_H
#define GEOMBASE_EXPORT
Definition: GEOM_GEOMBase.hxx:36
A smart pointer for the SALOME GenericObj interface.
Definition: GEOM_GenericObjPtr.h:78
GenericObjPtr & operator=(const GenericObjPtr &thePointer)
Assign object to reference and remove reference to an old object.
Definition: GEOM_GenericObjPtr.h:137
TInterfacePtr operator->() const
Provides normal pointer target member access using operator ->.
Definition: GEOM_GenericObjPtr.h:175
bool isNull() const
Check if pointer is null.
Definition: GEOM_GenericObjPtr.h:206
GenericObjPtr & operator=(TInterfacePtr theObject)
Assign object to reference and remove reference to an old object.
Definition: GEOM_GenericObjPtr.h:128
void nullify()
Nullify pointer.
Definition: GEOM_GenericObjPtr.h:212
TInterfacePtr copy() const
Make the copy of the contained object and return it (caller becomes owner of the CORBA reference).
Definition: GEOM_GenericObjPtr.h:200
TInterfaceVar myObject
Definition: GEOM_GenericObjPtr.h:83
GenericObjPtr(const GenericObjPtr &thePointer)
Initialize pointer with a new reference to the same object referenced by given pointer.
Definition: GEOM_GenericObjPtr.h:115
void Register()
Increment counter for the object.
Definition: GEOM_GenericObjPtr.h:87
TInterface::_var_type TInterfaceVar
Definition: GEOM_GenericObjPtr.h:79
static bool isSame(TInterfacePtr theLeft, TInterfacePtr theRight)
Definition: GEOM_GenericObjPtr.h:145
TInterface::_ptr_type TInterfacePtr
Definition: GEOM_GenericObjPtr.h:80
~GenericObjPtr()
Destroy pointer and remove the reference to the object.
Definition: GEOM_GenericObjPtr.h:122
bool operator!=(const GenericObjPtr &thePointer)
Check difference.
Definition: GEOM_GenericObjPtr.h:169
GenericObjPtr()
Initialize pointer to nil generic object reference.
Definition: GEOM_GenericObjPtr.h:104
void take(TInterfacePtr theObject)
Initialize pointer to the given generic object reference and take ownership on it.
Definition: GEOM_GenericObjPtr.h:187
void UnRegister()
Decrement counter for the object.
Definition: GEOM_GenericObjPtr.h:94
GenericObjPtr(TInterfacePtr theObject)
Initialize pointer to the given generic object reference.
Definition: GEOM_GenericObjPtr.h:108
bool operator==(const GenericObjPtr &thePointer)
Check equivalence.
Definition: GEOM_GenericObjPtr.h:157
bool operator==(TInterfacePtr theObject)
Check equivalence.
Definition: GEOM_GenericObjPtr.h:151
TInterfacePtr get() const
Get the contained object.
Definition: GEOM_GenericObjPtr.h:194
bool operator!=(TInterfacePtr theObject)
Check difference.
Definition: GEOM_GenericObjPtr.h:163
Definition: GEOM_PythonDump.cxx:33
GenericObjPtr< GEOM::GEOM_IGroupOperations > GroupOpPtr
Definition: GEOM_GenericObjPtr.h:231
GenericObjPtr< GEOM::GEOM_ICurvesOperations > CurvesOpPtr
Definition: GEOM_GenericObjPtr.h:226
GenericObjPtr< GEOM::GEOM_Field > GeomFieldPtr
Definition: GEOM_GenericObjPtr.h:219
GenericObjPtr< GEOM::GEOM_IHealingOperations > HealingOpPtr
Definition: GEOM_GenericObjPtr.h:228
GenericObjPtr< GEOM::GEOM_IInsertOperations > InsertOpPtr
Definition: GEOM_GenericObjPtr.h:229
GenericObjPtr< GEOM::GEOM_ILocalOperations > LocalOpPtr
Definition: GEOM_GenericObjPtr.h:227
GenericObjPtr< GEOM::GEOM_IBasicOperations > BasicOpPtr
Definition: GEOM_GenericObjPtr.h:220
GenericObjPtr< GEOM::GEOM_IBooleanOperations > BooleanOpPtr
Definition: GEOM_GenericObjPtr.h:225
GenericObjPtr< GEOM::GEOM_IShapesOperations > ShapesOpPtr
Definition: GEOM_GenericObjPtr.h:223
GenericObjPtr< GEOM::GEOM_IMeasureOperations > MeasureOpPtr
Definition: GEOM_GenericObjPtr.h:230
GenericObjPtr< GEOM::GEOM_I3DPrimOperations > I3DPrimOpPtr
Definition: GEOM_GenericObjPtr.h:222
GenericObjPtr< GEOM::GEOM_ITransformOperations > TransformOpPtr
Definition: GEOM_GenericObjPtr.h:221
GenericObjPtr< GEOM::GEOM_Object > GeomObjPtr
Definition: GEOM_GenericObjPtr.h:218
GenericObjPtr< GEOM::GEOM_IBlocksOperations > BlocksOpPtr
Definition: GEOM_GenericObjPtr.h:224