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. |
7fd59977 |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
b311480e |
14 | |
15 | //============================================================================ |
7fd59977 |
16 | // Title : Handle_Standard_Persistent.hxx |
17 | // Role : This file just include <Standard_Persistent.hxx> |
7fd59977 |
18 | //============================================================================ |
19 | |
20 | #ifndef _Handle_Standard_Persistent_HeaderFile |
21 | #define _Handle_Standard_Persistent_HeaderFile |
22 | |
1c35b92f |
23 | #include <Standard_DefineAlloc.hxx> |
ebc93ae7 |
24 | #include <Standard_TypeDef.hxx> |
7fd59977 |
25 | #include <Standard_Persistent_proto.hxx> |
7fd59977 |
26 | |
27 | #ifdef _WIN32 |
28 | // Disable the warning "conversion from 'unsigned int' to Standard_Persistent *" |
29 | #pragma warning (push) |
30 | #pragma warning (disable:4312) |
31 | #endif |
32 | |
7fd59977 |
33 | class Standard_Persistent; |
34 | class Handle_Standard_Type; |
35 | class Handle_Standard_Persistent; |
36 | |
37 | Standard_EXPORT Standard_Integer HashCode(const Handle(Standard_Persistent)& , |
38 | const Standard_Integer); |
7fd59977 |
39 | |
40 | class Handle(Standard_Persistent) |
41 | { |
42 | private: |
43 | |
44 | Standard_Persistent *entity; |
45 | |
46 | Standard_EXPORT void RaiseNullObject(const Standard_CString S) const; |
47 | |
48 | void BeginScope() const |
49 | { |
4d9421a9 |
50 | if (entity != 0) entity->count++; |
7fd59977 |
51 | } |
52 | |
53 | void EndScope() |
54 | { |
4d9421a9 |
55 | if (entity != 0) |
7fd59977 |
56 | { |
57 | entity->count--; |
58 | if (entity->count == 0) { |
59 | entity->Delete(); |
4d9421a9 |
60 | entity = 0 ; |
7fd59977 |
61 | } |
62 | } |
63 | } |
64 | |
65 | |
66 | public: |
67 | |
1c35b92f |
68 | DEFINE_STANDARD_ALLOC |
7fd59977 |
69 | |
70 | Handle(Standard_Persistent)() |
71 | { |
4d9421a9 |
72 | entity = 0 ; |
7fd59977 |
73 | } |
74 | |
75 | Handle(Standard_Persistent)(const Handle(Standard_Persistent)& aTid) |
76 | { |
77 | entity = aTid.entity; |
78 | BeginScope(); |
79 | } |
80 | |
81 | Handle(Standard_Persistent)(const Standard_Persistent *anItem) |
82 | { |
83 | if (!anItem) |
4d9421a9 |
84 | entity = 0 ; |
7fd59977 |
85 | else { |
86 | entity = (Standard_Persistent *)anItem; |
87 | BeginScope(); |
88 | } |
89 | } |
90 | |
91 | Standard_EXPORT void Dump(Standard_OStream& out) const; |
92 | |
93 | Standard_EXPORT ~Handle(Standard_Persistent)(); |
94 | |
4d9421a9 |
95 | bool operator==(const Handle(Standard_Persistent)& right) const |
7fd59977 |
96 | { |
97 | return entity == right.entity; |
98 | } |
99 | |
4d9421a9 |
100 | bool operator==(const Standard_Persistent *right) const |
7fd59977 |
101 | { |
102 | return entity == right; |
103 | } |
104 | |
4d9421a9 |
105 | friend bool operator==(const Standard_Persistent *left, const Handle(Standard_Persistent)& right) |
7fd59977 |
106 | { |
107 | return left == right.entity; |
108 | } |
109 | |
4d9421a9 |
110 | bool operator!=(const Handle(Standard_Persistent)& right) const |
7fd59977 |
111 | { |
112 | return entity != right.entity; |
113 | } |
114 | |
4d9421a9 |
115 | bool operator!=(const Standard_Persistent *right) const |
7fd59977 |
116 | { |
117 | return entity != right; |
118 | } |
119 | |
4d9421a9 |
120 | friend bool operator!=(const Standard_Persistent *left, const Handle(Standard_Persistent)& right) |
7fd59977 |
121 | { |
122 | return left != right.entity; |
123 | } |
124 | |
125 | void Nullify() |
126 | { |
127 | EndScope(); |
4d9421a9 |
128 | entity = 0 ; |
7fd59977 |
129 | } |
130 | |
131 | Standard_Boolean IsNull() const |
132 | { |
4d9421a9 |
133 | return entity == 0 ; |
7fd59977 |
134 | } |
135 | |
136 | Standard_Persistent* Access() const |
137 | { |
138 | return entity; |
139 | } |
140 | |
141 | protected: |
142 | |
143 | Standard_Persistent* ControlAccess() const |
144 | { |
145 | return entity; |
146 | } |
147 | |
148 | void Assign(const Standard_Persistent *anItem) |
149 | { |
150 | EndScope(); |
151 | if (!anItem) |
4d9421a9 |
152 | entity = 0 ; |
7fd59977 |
153 | else { |
154 | entity = (Standard_Persistent *)anItem; |
155 | BeginScope(); |
156 | } |
157 | } |
158 | |
159 | |
160 | public: |
161 | |
162 | operator Standard_Persistent*() |
163 | { |
164 | return Access(); |
165 | } |
166 | |
167 | |
168 | Standard_EXPORT Handle(Standard_Persistent)& operator=(const Handle(Standard_Persistent)& aHandle); |
169 | Standard_EXPORT Handle(Standard_Persistent)& operator=(const Standard_Persistent* anItem); |
170 | |
171 | Standard_Persistent* operator->() |
172 | { |
173 | return ControlAccess(); |
174 | } |
175 | |
176 | Standard_Persistent* operator->() const |
177 | { |
178 | return ControlAccess(); |
179 | } |
180 | |
181 | Standard_Persistent& operator*() |
182 | { |
183 | return *(ControlAccess()); |
184 | } |
185 | |
186 | const Standard_Persistent& operator*() const |
187 | { |
188 | return *(ControlAccess()); |
189 | } |
190 | |
191 | Standard_EXPORT static const Handle(Standard_Persistent) DownCast(const Handle(Standard_Persistent)& AnObject); |
192 | }; |
193 | |
194 | class Standard_Type; |
195 | |
196 | #ifdef _WIN32 |
197 | #pragma warning (pop) |
198 | #endif |
199 | |
200 | #endif |