1 // Copyright (C) 2007-2008 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
22 // File : SALOME_GenericObjPtr.hh
23 // Author : Oleg UVAROV
26 #ifndef SALOME_GenericObjPointer_HH
27 #define SALOME_GenericObjPointer_HH
29 #include "SALOMEconfig.h"
30 #include CORBA_SERVER_HEADER(SALOME_GenericObj)
32 #include <iosfwd> // for std::basic_ostream
36 //----------------------------------------------------------------------------
37 template <class TGenericObj>
40 //! Pointer to the actual object.
41 TGenericObj* myPointer;
44 swap(GenericObjPtr& thePointer)
46 TGenericObj* aPointer = thePointer.myPointer;
47 thePointer.myPointer = this->myPointer;
48 this->myPointer = aPointer;
55 this->myPointer->Register();
62 this->myPointer->Destroy();
63 this->myPointer = NULL;
68 //! Initialize smart pointer to NULL.
73 //! Initialize smart pointer to given object (TSGenericObj must be complete).
74 template<class TGenObj>
76 GenericObjPtr(TGenObj* thePointer):
83 Initialize smart pointer with a new reference to the same object
84 referenced by given smart pointer.
86 GenericObjPtr(const GenericObjPtr& thePointer):
87 myPointer(thePointer.myPointer)
93 Initialize smart pointer with a new reference to the same object
94 referenced by given smart pointer.
96 template<class TGenObj>
97 GenericObjPtr(const GenericObjPtr<TGenObj>& thePointer):
98 myPointer(thePointer.get())
103 //! Destroy smart pointer and remove the reference to its object.
110 Assign object to reference. This removes any reference to an old
113 template<class TGenObj>
115 operator=(TGenObj* thePointer)
117 GenericObjPtr aTmp(thePointer);
123 Assign object to reference. This removes any reference to an old
127 operator=(const GenericObjPtr& thePointer)
129 GenericObjPtr aTmp(thePointer);
135 Assign object to reference. This removes any reference to an old
138 template<class TGenObj>
140 operator=(const GenericObjPtr<TGenObj>& thePointer)
142 GenericObjPtr aTmp(thePointer);
147 //! Get the contained pointer.
152 return this->myPointer;
155 //! Get the contained pointer.
156 operator TGenericObj* () const
162 Dereference the pointer and return a reference to the contained
171 //! Provides normal pointer target member access using operator ->.
172 TGenericObj* operator->() const
177 operator bool () const
179 return this->get() != 0;
184 template<class T, class U>
187 operator<(SALOME::GenericObjPtr<T> const & a, SALOME::GenericObjPtr<U> const & b)
189 return a.get() < b.get();
192 template<class T, class U>
195 operator==(SALOME::GenericObjPtr<T> const & a, SALOME::GenericObjPtr<U> const & b)
197 return a.get() == b.get();
200 template<class T, class U>
203 operator!=(SALOME::GenericObjPtr<T> const & a, SALOME::GenericObjPtr<U> const & b)
205 return a.get() != b.get();
210 operator<< (std::ostream & os, SALOME::GenericObjPtr<Y> const & p)