b311480e |
1 | // Copyright (c) 1998-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
b311480e |
14 | |
7fd59977 |
15 | #ifndef _Standard_Transient_HeaderFile |
16 | #define _Standard_Transient_HeaderFile |
17 | |
e7195ab4 |
18 | #include <Standard.hxx> |
19 | #include <Standard_DefineAlloc.hxx> |
7fd59977 |
20 | #include <Standard_PrimitiveTypes.hxx> |
e7195ab4 |
21 | |
22 | class Standard_Type; |
23 | |
24 | namespace opencascade { |
25 | template <class T> class handle; |
26 | } |
27 | |
28 | //! Abstract class which forms the root of the entire |
29 | //! Transient class hierarchy. |
30 | |
31 | class Standard_Transient |
32 | { |
33 | public: |
34 | // Standard OCCT memory allocation stuff |
35 | DEFINE_STANDARD_ALLOC |
36 | |
37 | public: |
38 | |
39 | //! Empty constructor |
40 | Standard_Transient() : count(0) {} |
41 | |
42 | //! Copy constructor -- does nothing |
43 | Standard_Transient (const Standard_Transient&) : count(0) {} |
44 | |
45 | //! Assignment operator, needed to avoid copying reference counter |
46 | Standard_Transient& operator= (const Standard_Transient&) { return *this; } |
47 | |
48 | //! Destructor must be virtual |
49 | virtual ~Standard_Transient() {} |
50 | |
51 | //! Memory deallocator for transient classes |
52 | Standard_EXPORT virtual void Delete() const; |
53 | |
54 | public: |
55 | //!@name Support of run-time type information (RTTI) |
56 | |
57 | typedef void base_type; |
58 | |
59 | static const char* get_type_name () { return "Standard_Transient"; } |
60 | |
61 | //! Returns a type information object about this object. |
62 | Standard_EXPORT virtual const opencascade::handle<Standard_Type>& DynamicType() const; |
63 | |
64 | //! Returns a true value if this is an instance of Type. |
65 | Standard_EXPORT Standard_Boolean IsInstance(const opencascade::handle<Standard_Type>& theType) const; |
66 | |
67 | //! Returns a true value if this is an instance of TypeName. |
68 | Standard_EXPORT Standard_Boolean IsInstance(const Standard_CString theTypeName) const; |
69 | |
70 | //! Returns true if this is an instance of Type or an |
71 | //! instance of any class that inherits from Type. |
72 | //! Note that multiple inheritance is not supported by OCCT RTTI mechanism. |
73 | Standard_EXPORT Standard_Boolean IsKind(const opencascade::handle<Standard_Type>& theType) const; |
74 | |
75 | //! Returns true if this is an instance of TypeName or an |
76 | //! instance of any class that inherits from TypeName. |
77 | //! Note that multiple inheritance is not supported by OCCT RTTI mechanism. |
78 | Standard_EXPORT Standard_Boolean IsKind(const Standard_CString theTypeName) const; |
79 | |
80 | //! Returns non-const pointer to this object (like const_cast). |
81 | //! For protection against creating handle to objects allocated in stack |
82 | //! or call from constructor, it will raise exception Standard_ProgramError |
83 | //! if reference counter is zero. |
84 | Standard_EXPORT Standard_Transient* This() const; |
85 | |
86 | public: |
87 | //!@name Reference counting, for use by handle<> |
88 | |
89 | //! Get the reference counter of this object |
90 | Standard_EXPORT Standard_Integer GetRefCount() const { return count; } |
91 | |
92 | //! Increments the reference counter of this object |
93 | Standard_EXPORT void IncrementRefCounter() const; |
94 | |
95 | //! Decrements the reference counter of this object; |
96 | //! returns the decremented value |
97 | Standard_EXPORT Standard_Integer DecrementRefCounter() const; |
98 | |
99 | private: |
100 | |
101 | //! Reference counter |
102 | mutable volatile Standard_Integer count; |
103 | }; |
104 | |
105 | //! Global method HashCode(), for use in hash maps |
106 | inline Standard_Integer HashCode (const Standard_Transient* theObject, const Standard_Integer theUpper) |
107 | { |
108 | return ::HashCode ((Standard_Address*)theObject, theUpper); |
109 | } |
110 | |
111 | //! Definition of Handle_Standard_Transient as typedef for compatibility |
112 | typedef opencascade::handle<Standard_Transient> Handle_Standard_Transient; |
7fd59977 |
113 | |
114 | #endif |