1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : SALOME_GenericObjPtr.hh
22 // Author : Oleg UVAROV
25 #ifndef SALOME_GenericObjPointer_HH
26 #define SALOME_GenericObjPointer_HH
28 #include "SALOMEconfig.h"
29 #include CORBA_SERVER_HEADER(SALOME_GenericObj)
31 #include <iosfwd> // for std::basic_ostream
35 //----------------------------------------------------------------------------
36 template <class TGenericObj>
39 //! Pointer to the actual object.
40 TGenericObj* myPointer;
43 swap(GenericObjPtr& thePointer)
45 TGenericObj* aPointer = thePointer.myPointer;
46 thePointer.myPointer = this->myPointer;
47 this->myPointer = aPointer;
54 this->myPointer->Register();
61 this->myPointer->Destroy();
62 this->myPointer = NULL;
67 //! Initialize smart pointer to NULL.
72 //! Initialize smart pointer to given object (TSGenericObj must be complete).
73 template<class TGenObj>
75 GenericObjPtr(TGenObj* thePointer):
82 Initialize smart pointer with a new reference to the same object
83 referenced by given smart pointer.
85 GenericObjPtr(const GenericObjPtr& thePointer):
86 myPointer(thePointer.myPointer)
92 Initialize smart pointer with a new reference to the same object
93 referenced by given smart pointer.
95 template<class TGenObj>
96 GenericObjPtr(const GenericObjPtr<TGenObj>& thePointer):
97 myPointer(thePointer.get())
102 //! Destroy smart pointer and remove the reference to its object.
109 Assign object to reference. This removes any reference to an old
112 template<class TGenObj>
114 operator=(TGenObj* thePointer)
116 GenericObjPtr aTmp(thePointer);
122 Assign object to reference. This removes any reference to an old
126 operator=(const GenericObjPtr& thePointer)
128 GenericObjPtr aTmp(thePointer);
134 Assign object to reference. This removes any reference to an old
137 template<class TGenObj>
139 operator=(const GenericObjPtr<TGenObj>& thePointer)
141 GenericObjPtr aTmp(thePointer);
146 //! Get the contained pointer.
151 return this->myPointer;
154 //! Get the contained pointer.
155 operator TGenericObj* () const
161 Dereference the pointer and return a reference to the contained
170 //! Provides normal pointer target member access using operator ->.
171 TGenericObj* operator->() const
176 operator bool () const
178 return this->get() != 0;
183 template<class T, class U>
186 operator<(SALOME::GenericObjPtr<T> const & a, SALOME::GenericObjPtr<U> const & b)
188 return a.get() < b.get();
191 template<class T, class U>
194 operator==(SALOME::GenericObjPtr<T> const & a, SALOME::GenericObjPtr<U> const & b)
196 return a.get() == b.get();
199 template<class T, class U>
202 operator!=(SALOME::GenericObjPtr<T> const & a, SALOME::GenericObjPtr<U> const & b)
204 return a.get() != b.get();
209 operator<< (std::ostream & os, SALOME::GenericObjPtr<Y> const & p)