0023024: Update headers of OCCT files
[occt.git] / src / Standard / Standard_Type.cxx
CommitLineData
b311480e 1// Copyright (c) 1998-1999 Matra Datavision
2// Copyright (c) 1999-2012 OPEN CASCADE SAS
3//
4// The content of this file is subject to the Open CASCADE Technology Public
5// License Version 6.5 (the "License"). You may not use the content of this file
6// except in compliance with the License. Please obtain a copy of the License
7// at http://www.opencascade.org and read it completely before using this file.
8//
9// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11//
12// The Original Code and all software distributed under the License is
13// distributed on an "AS IS" basis, without warranty of any kind, and the
14// Initial Developer hereby disclaims all such warranties, including without
15// limitation, any warranties of merchantability, fitness for a particular
16// purpose or non-infringement. Please see the License for the specific terms
17// and conditions governing the rights and limitations under the License.
18
7fd59977 19#ifdef HAVE_CONFIG_H
20# include <config.h>
21#endif
22
23#include <Standard_Type.ixx>
24#include <Standard_Persistent.hxx>
25
26//============================================================================
27// The constructor for a imported Type
28//============================================================================
29
30Standard_Type::Standard_Type(const Standard_CString aName,
31 const Standard_Integer aSize)
32{
33 myName = aName;
34 mySize = aSize;
35 myKind = Standard_IsImported;
36
37 //==== Just for be clean with the class and the enumeration ================
38 myNumberOfParent = 0;
39 myNumberOfAncestor = 0;
40
41 myAncestors = NULL;
42}
43
44//============================================================================
45// The constructor for a primitive Type
46//============================================================================
47
48Standard_Type::Standard_Type(const Standard_CString aName,
49 const Standard_Integer aSize,
50 const Standard_Integer aNumberOfParent ,
51 const Standard_Address aAncestors)
52{
53 myName = aName;
54 mySize = aSize;
55 myKind = Standard_IsPrimitive;
56
57 myNumberOfParent = aNumberOfParent;
58
59 //==== Calculate the number of ancestor ====================================
60 myNumberOfAncestor = 0;
61 myAncestors = aAncestors;
62 Handle(Standard_Type) *allAncestors = (Handle(Standard_Type) *)myAncestors;
63 for(Standard_Integer i=0; allAncestors && !allAncestors[i].IsNull(); i++) {
64 myNumberOfAncestor++;
65 }
66}
67
68//============================================================================
69// The constructor for an enumeration.
70//============================================================================
71
72Standard_Type::Standard_Type(const Standard_CString aName,
73 const Standard_Integer aSize,
74 const Standard_Integer ,
75 const Standard_Integer aNumberOfParent,
76 const Standard_Address aAncestors,
77 const Standard_Address )
78{
79 myName = aName;
80 mySize = aSize;
81 myKind = Standard_IsEnumeration;
82
83 myNumberOfParent = aNumberOfParent;
84
85 //==== Calculate the number of ancestor ====================================
86 myNumberOfAncestor = 0;
87 myAncestors = aAncestors;
88 Handle(Standard_Type) *allAncestors = (Handle(Standard_Type) *)myAncestors;
89 for(Standard_Integer i=0; allAncestors && !allAncestors[i].IsNull(); i++) {
90 myNumberOfAncestor++;
91 }
92}
93
94//============================================================================
95// The constructor for a class.
96//============================================================================
97
98Standard_Type::Standard_Type(const Standard_CString aName,
99 const Standard_Integer aSize,
100 const Standard_Integer aNumberOfParent ,
101 const Standard_Address aAncestors ,
102 const Standard_Address )
103{
104 myName = aName;
105 mySize = aSize;
106 myKind = Standard_IsClass;
107
108 myNumberOfParent = aNumberOfParent;
109
110 //==== Calculate the number of ancestors ===================================
111 myNumberOfAncestor = 0;
112 myAncestors = aAncestors;
113 Handle(Standard_Type) *allAncestors = (Handle(Standard_Type) *)myAncestors;
114 for(Standard_Integer i=0; allAncestors && !allAncestors[i].IsNull(); i++) {
115 myNumberOfAncestor++;
116 }
117}
118
119//============================================================================
120Standard_CString Standard_Type::Name() const
121{
122 return myName;
123}
124
125//============================================================================
126Standard_Integer Standard_Type::Size()const
127{
128 return mySize;
129}
130
131//============================================================================
132Standard_Boolean Standard_Type::IsImported()const
133{
134 return myKind == Standard_IsImported;
135}
136
137//============================================================================
138Standard_Boolean Standard_Type::IsPrimitive()const
139{
140 return myKind == Standard_IsPrimitive;
141}
142
143//============================================================================
144Standard_Boolean Standard_Type::IsEnumeration()const
145{
146 return myKind == Standard_IsEnumeration;
147}
148
149//============================================================================
150Standard_Boolean Standard_Type::IsClass()const
151{
152 return myKind == Standard_IsClass;
153}
154
155//============================================================================
156Standard_Integer Standard_Type::NumberOfParent()const
157{
158 return myNumberOfParent;
159}
160
161//============================================================================
162Standard_Integer Standard_Type::NumberOfAncestor()const
163{
164 return myNumberOfAncestor;
165}
166
167//============================================================================
168Standard_Address Standard_Type::Ancestors()const
169{
170 return myAncestors;
171}
172
173//============================================================================
174Standard_Boolean Standard_Type::SubType(const Handle_Standard_Type& anOther)const
175{
176 // Among ancestors of the type of this, there is the type of anOther
177 return anOther == this ||
178 ( myNumberOfAncestor &&
179 (*(Handle(Standard_Type)*)myAncestors)->SubType(anOther) );
180}
181
182//============================================================================
183Standard_Boolean Standard_Type::SubType(const Standard_CString theName)const
184{
185 // Among ancestors of the type of this, there is the type of anOther
186 if ( ! theName )
187 return Standard_False;
188 if ( IsSimilar(myName, theName) )
189 return Standard_True;
190 if (myNumberOfAncestor)
191 return (*(Handle(Standard_Type) *)myAncestors)->SubType(theName);
192 return Standard_False;
193}
194
195//============================================================================
196void Standard_Type::ShallowDump() const
197{
198 ShallowDump(cout) ;
199}
200
201//============================================================================
202void Standard_Type::ShallowDump(Standard_OStream& AStream) const
203{
204 Standard_Integer i;
205 Handle(Standard_Type) aType;
206
207 Handle(Standard_Type) *allAncestors;
208
209// AStream << "Standard_Type " << hex << (Standard_Address )this << dec << " " ;
210
211 allAncestors = (Handle(Standard_Type) *)myAncestors;
212
213 if(myKind == Standard_IsEnumeration) {
214 AStream << "enumeration " << myName << endl;
215 }
216
217 if(myKind == Standard_IsPrimitive) {
218 AStream << "primitive " << myName << endl;
219 }
220
221 if(myKind == Standard_IsImported) {
222 AStream << "imported " << myName << endl;
223 }
224
225 if(myKind == Standard_IsClass) {
226 AStream << "class " << myName << endl;
227 if(SubType(STANDARD_TYPE(Standard_Transient))) {
228 AStream << " -- manipulated by 'Handle'" << endl;
229 }
230 else if(SubType(STANDARD_TYPE(Standard_Persistent))) {
231 AStream << " -- manipulated by 'Handle' and is 'persistent'"<< endl;
232 }
233 }
234
235 if(myNumberOfParent > 0) {
236 AStream << " inherits ";
237 for(i=0; i<myNumberOfParent; i++){
238 aType = allAncestors[i];
239 if (i>1) AStream <<", ";
240 if ( !aType.IsNull() )
241 AStream << aType->Name();
242 else
243 AStream << " ??? (TypeIsNull)" ;
244 }
245 AStream << endl;
246 }
247
248 if(myNumberOfAncestor > myNumberOfParent) {
249 AStream << " -- Ancestors: ";
250 for(i=myNumberOfParent; i<myNumberOfAncestor; i++){
251 aType = allAncestors[i];
252 if (i>1) AStream <<", ";
253 if ( !aType.IsNull() )
254 AStream << aType->Name();
255 else
256 AStream << " ??? (TypeIsNull)" ;
257 }
258 AStream << endl;
259 }
260}
261
262// ------------------------------------------------------------------
263// Print (me; s: in out OStream) returns OStream;
264// ------------------------------------------------------------------
265void Standard_Type::Print (Standard_OStream& AStream) const
266{
267// AStream << myName ;
268 AStream << hex << (Standard_Address ) myName << " : " << dec << myName ;
269}
270
271Standard_OStream& operator << (Standard_OStream& AStream
272 ,const Handle(Standard_Type)& AType)
273{
274 AType->Print(AStream);
275 return AStream;
276}