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 under
7 // the terms of the GNU Lesser General Public License 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 _Standard_Transient_HeaderFile
16 #define _Standard_Transient_HeaderFile
18 #include <Standard.hxx>
19 #include <Standard_DefineAlloc.hxx>
20 #include <Standard_PrimitiveTypes.hxx>
24 namespace opencascade {
25 template <class T> class handle;
28 //! Abstract class which forms the root of the entire
29 //! Transient class hierarchy.
31 class Standard_Transient
34 // Standard OCCT memory allocation stuff
40 Standard_Transient() : myRefCount_(0) {}
42 //! Copy constructor -- does nothing
43 Standard_Transient (const Standard_Transient&) : myRefCount_(0) {}
45 //! Assignment operator, needed to avoid copying reference counter
46 Standard_Transient& operator= (const Standard_Transient&) { return *this; }
48 //! Destructor must be virtual
49 virtual ~Standard_Transient() {}
51 //! Memory deallocator for transient classes
52 Standard_EXPORT virtual void Delete() const;
55 //!@name Support of run-time type information (RTTI)
57 typedef void base_type;
59 static const char* get_type_name () { return "Standard_Transient"; }
61 //! Returns type descriptor of Standard_Transient class
62 Standard_EXPORT static const opencascade::handle<Standard_Type>& get_type_descriptor ();
64 //! Returns a type descriptor about this object.
65 Standard_EXPORT virtual const opencascade::handle<Standard_Type>& DynamicType() const;
67 //! Returns a true value if this is an instance of Type.
68 Standard_EXPORT Standard_Boolean IsInstance(const opencascade::handle<Standard_Type>& theType) const;
70 //! Returns a true value if this is an instance of TypeName.
71 Standard_EXPORT Standard_Boolean IsInstance(const Standard_CString theTypeName) const;
73 //! Returns true if this is an instance of Type or an
74 //! instance of any class that inherits from Type.
75 //! Note that multiple inheritance is not supported by OCCT RTTI mechanism.
76 Standard_EXPORT Standard_Boolean IsKind(const opencascade::handle<Standard_Type>& theType) const;
78 //! Returns true if this is an instance of TypeName or an
79 //! instance of any class that inherits from TypeName.
80 //! Note that multiple inheritance is not supported by OCCT RTTI mechanism.
81 Standard_EXPORT Standard_Boolean IsKind(const Standard_CString theTypeName) const;
83 //! Returns non-const pointer to this object (like const_cast).
84 //! For protection against creating handle to objects allocated in stack
85 //! or call from constructor, it will raise exception Standard_ProgramError
86 //! if reference counter is zero.
87 Standard_EXPORT Standard_Transient* This() const;
90 //!@name Reference counting, for use by handle<>
92 //! Get the reference counter of this object
93 Standard_Integer GetRefCount() const { return myRefCount_; }
95 //! Increments the reference counter of this object
96 Standard_EXPORT void IncrementRefCounter() const;
98 //! Decrements the reference counter of this object;
99 //! returns the decremented value
100 Standard_EXPORT Standard_Integer DecrementRefCounter() const;
104 //! Reference counter.
105 //! Note use of underscore, aimed to reduce probability
106 //! of conflict with names of members of derived classes.
107 mutable volatile Standard_Integer myRefCount_;
111 //! Computes a hash code for the given transient object, in the range [1, theUpperBound]
112 //! @param theTransientObject the transient object which hash code is to be computed
113 //! @param theUpperBound the upper bound of the range a computing hash code must be within
114 //! @return a computed hash code, in the range [1, theUpperBound]
115 inline Standard_Integer HashCode (const Standard_Transient* const theTransientObject,
116 const Standard_Integer theUpperBound)
118 return ::HashCode (static_cast<const void*> (theTransientObject), theUpperBound);
121 //! Definition of Handle_Standard_Transient as typedef for compatibility
122 typedef opencascade::handle<Standard_Transient> Handle_Standard_Transient;