1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SALOME_GenericObjPtr.hh
24 // Author : Oleg UVAROV
27 #ifndef SALOME_GenericObjPointer_HH
28 #define SALOME_GenericObjPointer_HH
30 #include "SALOMEconfig.h"
31 #include CORBA_SERVER_HEADER(SALOME_GenericObj)
33 #include <iosfwd> // for std::basic_ostream
37 //----------------------------------------------------------------------------
38 template <class TGenericObj>
41 //! Pointer to the actual object.
42 TGenericObj* myPointer;
45 swap(GenericObjPtr& thePointer)
47 TGenericObj* aPointer = thePointer.myPointer;
48 thePointer.myPointer = this->myPointer;
49 this->myPointer = aPointer;
56 this->myPointer->Register();
63 this->myPointer->UnRegister();
64 this->myPointer = NULL;
69 //! Initialize smart pointer to NULL.
74 //! Initialize smart pointer to given object (TSGenericObj must be complete).
75 template<class TGenObj>
77 GenericObjPtr(TGenObj* thePointer):
84 Initialize smart pointer with a new reference to the same object
85 referenced by given smart pointer.
87 GenericObjPtr(const GenericObjPtr& thePointer):
88 myPointer(thePointer.myPointer)
94 Initialize smart pointer with a new reference to the same object
95 referenced by given smart pointer.
97 template<class TGenObj>
98 GenericObjPtr(const GenericObjPtr<TGenObj>& thePointer):
99 myPointer(thePointer.get())
104 //! Destroy smart pointer and remove the reference to its object.
111 Assign object to reference. This removes any reference to an old
114 template<class TGenObj>
116 operator=(TGenObj* thePointer)
118 GenericObjPtr aTmp(thePointer);
124 Assign object to reference. This removes any reference to an old
128 operator=(const GenericObjPtr& thePointer)
130 GenericObjPtr aTmp(thePointer);
136 Assign object to reference. This removes any reference to an old
139 template<class TGenObj>
141 operator=(const GenericObjPtr<TGenObj>& thePointer)
143 GenericObjPtr aTmp(thePointer);
148 //! Get the contained pointer.
153 return this->myPointer;
156 //! Get the contained pointer.
157 operator TGenericObj* () const
163 Dereference the pointer and return a reference to the contained
172 //! Provides normal pointer target member access using operator ->.
173 TGenericObj* operator->() const
178 operator bool () const
180 return this->get() != 0;
185 template<class T, class U>
188 operator<(SALOME::GenericObjPtr<T> const & a, SALOME::GenericObjPtr<U> const & b)
190 return a.get() < b.get();
193 template<class T, class U>
196 operator==(SALOME::GenericObjPtr<T> const & a, SALOME::GenericObjPtr<U> const & b)
198 return a.get() == b.get();
201 template<class T, class U>
204 operator!=(SALOME::GenericObjPtr<T> const & a, SALOME::GenericObjPtr<U> const & b)
206 return a.get() != b.get();
211 operator<< (std::ostream & os, SALOME::GenericObjPtr<Y> const & p)