1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and / or modify it
7 // under the terms of the GNU Lesser General Public version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef _Handle_Standard_Transient_HeaderFile
16 #define _Handle_Standard_Transient_HeaderFile
17 #ifndef _Standard_HeaderFile
18 #include <Standard.hxx>
20 #ifndef _Standard_DefineAlloc_HeaderFile
21 #include <Standard_DefineAlloc.hxx>
23 #ifndef _Standard_Macro_HeaderFile
24 #include <Standard_Macro.hxx>
26 #ifndef _Standard_PrimitiveTypes_HeaderFile
27 #include <Standard_PrimitiveTypes.hxx>
29 #ifndef _Standard_Transient_proto_HeaderFile
30 #include <Standard_Transient_proto.hxx>
34 // Disable the warning "conversion from 'unsigned int' to Standard_Transient *"
35 #pragma warning (push)
36 #pragma warning (disable:4312)
39 class Handle_Standard_Transient;
41 Standard_EXPORT Standard_Integer HashCode(const Handle(Standard_Transient)& ,const Standard_Integer);
44 * Base class for hierarchy of smart pointers (Handles) for Transient
45 * objects. Uses reference counting technique to control life time
46 * of the referred object.
48 * Note that Handle should never be initialized by pointer to object
49 * created in the stack; only dinamically allocated pointers shall be used.
52 class Handle(Standard_Transient)
59 Handle(Standard_Transient) ()
64 //! Constructor from pointer to new object
65 Handle(Standard_Transient) (const Standard_Transient *anItem)
66 : entity ( (Standard_Transient*)anItem )
72 Handle(Standard_Transient) (const Handle(Standard_Transient)& aTid)
73 : entity ( aTid.entity )
79 ~Handle(Standard_Transient)()
84 //! Assignment operator
85 Handle(Standard_Transient)& operator=(const Handle(Standard_Transient)& aHandle)
87 Assign(aHandle.Access());
91 //! Assignment operator
92 Handle(Standard_Transient)& operator=(const Standard_Transient* anItem)
98 //! Nullify the handle
104 //! Check for being null
105 Standard_Boolean IsNull() const
110 //! Returns pointer to referred object
111 Standard_Transient* Access()
116 //! Returns const pointer to referred object
117 const Standard_Transient* Access() const
122 //! Cast to pointer to referred object
123 operator Standard_Transient*()
128 //! Cast to const pointer to referred object
129 operator const Standard_Transient*() const
134 //! Member access operator (note non-const)
135 Standard_Transient* operator->() const
140 //! Dereferencing operator
141 Standard_Transient& operator*()
146 //! Const dereferencing operator
147 const Standard_Transient& operator*() const
152 //! Check for equality
153 int operator==(const Handle(Standard_Transient)& right) const
155 return entity == right.entity;
158 //! Check for equality
159 int operator==(const Standard_Transient *right) const
161 return entity == right;
164 //! Check for equality
165 friend bool operator==(const Standard_Transient *left, const Handle(Standard_Transient)& right)
167 return left == right.entity;
170 //! Check for inequality
171 bool operator!=(const Handle(Standard_Transient)& right) const
173 return entity != right.entity;
176 //! Check for inequality
177 bool operator!=(const Standard_Transient *right) const
179 return entity != right;
182 //! Check for inequality
183 friend bool operator!=(const Standard_Transient *left, const Handle(Standard_Transient)& right)
185 return left != right.entity;
188 //! Down casting operator; dummy provided for consistency with other classes
190 static const Handle(Standard_Transient)& DownCast(const Handle(Standard_Transient)& AnObject)
195 //! Dump pointer to a referred object to a stream
196 Standard_EXPORT void Dump(Standard_OStream& out) const;
199 // Protected methods for descendants
201 //! Returns non-const pointer to referred object
202 Standard_Transient* ControlAccess() const
208 Standard_EXPORT void Assign (const Standard_Transient *anItem);
213 //! Increment reference counter of referred object
214 Standard_EXPORT void BeginScope();
216 //! Decrement reference counter and if 0, destroy referred object
217 Standard_EXPORT void EndScope();
221 DEFINE_STANDARD_ALLOC
225 Standard_Transient *entity;
228 //! Function in global scope to check handles for equality.
229 //! Will be used with standard OCCT collections like NCollection_DataMap within NCollection_DefaultHasher
230 //! when there are no specialization defined for concrete type.
231 //! Notice that this implementation compares only pointers to objects!
232 inline Standard_Boolean IsEqual (const Handle(Standard_Transient)& theFirst,
233 const Handle(Standard_Transient)& theSecond)
235 return theFirst == theSecond;
239 #pragma warning (pop)