Version: 8.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
GEOM_GenericObjPtr.h
Go to the documentation of this file.
1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, 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 
33 namespace 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 
94  void UnRegister()
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 
137  GenericObjPtr& operator=( const GenericObjPtr& thePointer )
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 
194  TInterfacePtr get() const
195  {
196  return this->myObject;
197  }
198 
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