Integration of OCCT 6.5.0 from SVN
[occt.git] / src / Standard / Standard_Type.cxx
CommitLineData
7fd59977 1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <Standard_Type.ixx>
6#include <Standard_Persistent.hxx>
7
8//============================================================================
9// The constructor for a imported Type
10//============================================================================
11
12Standard_Type::Standard_Type(const Standard_CString aName,
13 const Standard_Integer aSize)
14{
15 myName = aName;
16 mySize = aSize;
17 myKind = Standard_IsImported;
18
19 //==== Just for be clean with the class and the enumeration ================
20 myNumberOfParent = 0;
21 myNumberOfAncestor = 0;
22
23 myAncestors = NULL;
24}
25
26//============================================================================
27// The constructor for a primitive Type
28//============================================================================
29
30Standard_Type::Standard_Type(const Standard_CString aName,
31 const Standard_Integer aSize,
32 const Standard_Integer aNumberOfParent ,
33 const Standard_Address aAncestors)
34{
35 myName = aName;
36 mySize = aSize;
37 myKind = Standard_IsPrimitive;
38
39 myNumberOfParent = aNumberOfParent;
40
41 //==== Calculate the number of ancestor ====================================
42 myNumberOfAncestor = 0;
43 myAncestors = aAncestors;
44 Handle(Standard_Type) *allAncestors = (Handle(Standard_Type) *)myAncestors;
45 for(Standard_Integer i=0; allAncestors && !allAncestors[i].IsNull(); i++) {
46 myNumberOfAncestor++;
47 }
48}
49
50//============================================================================
51// The constructor for an enumeration.
52//============================================================================
53
54Standard_Type::Standard_Type(const Standard_CString aName,
55 const Standard_Integer aSize,
56 const Standard_Integer ,
57 const Standard_Integer aNumberOfParent,
58 const Standard_Address aAncestors,
59 const Standard_Address )
60{
61 myName = aName;
62 mySize = aSize;
63 myKind = Standard_IsEnumeration;
64
65 myNumberOfParent = aNumberOfParent;
66
67 //==== Calculate the number of ancestor ====================================
68 myNumberOfAncestor = 0;
69 myAncestors = aAncestors;
70 Handle(Standard_Type) *allAncestors = (Handle(Standard_Type) *)myAncestors;
71 for(Standard_Integer i=0; allAncestors && !allAncestors[i].IsNull(); i++) {
72 myNumberOfAncestor++;
73 }
74}
75
76//============================================================================
77// The constructor for a class.
78//============================================================================
79
80Standard_Type::Standard_Type(const Standard_CString aName,
81 const Standard_Integer aSize,
82 const Standard_Integer aNumberOfParent ,
83 const Standard_Address aAncestors ,
84 const Standard_Address )
85{
86 myName = aName;
87 mySize = aSize;
88 myKind = Standard_IsClass;
89
90 myNumberOfParent = aNumberOfParent;
91
92 //==== Calculate the number of ancestors ===================================
93 myNumberOfAncestor = 0;
94 myAncestors = aAncestors;
95 Handle(Standard_Type) *allAncestors = (Handle(Standard_Type) *)myAncestors;
96 for(Standard_Integer i=0; allAncestors && !allAncestors[i].IsNull(); i++) {
97 myNumberOfAncestor++;
98 }
99}
100
101//============================================================================
102Standard_CString Standard_Type::Name() const
103{
104 return myName;
105}
106
107//============================================================================
108Standard_Integer Standard_Type::Size()const
109{
110 return mySize;
111}
112
113//============================================================================
114Standard_Boolean Standard_Type::IsImported()const
115{
116 return myKind == Standard_IsImported;
117}
118
119//============================================================================
120Standard_Boolean Standard_Type::IsPrimitive()const
121{
122 return myKind == Standard_IsPrimitive;
123}
124
125//============================================================================
126Standard_Boolean Standard_Type::IsEnumeration()const
127{
128 return myKind == Standard_IsEnumeration;
129}
130
131//============================================================================
132Standard_Boolean Standard_Type::IsClass()const
133{
134 return myKind == Standard_IsClass;
135}
136
137//============================================================================
138Standard_Integer Standard_Type::NumberOfParent()const
139{
140 return myNumberOfParent;
141}
142
143//============================================================================
144Standard_Integer Standard_Type::NumberOfAncestor()const
145{
146 return myNumberOfAncestor;
147}
148
149//============================================================================
150Standard_Address Standard_Type::Ancestors()const
151{
152 return myAncestors;
153}
154
155//============================================================================
156Standard_Boolean Standard_Type::SubType(const Handle_Standard_Type& anOther)const
157{
158 // Among ancestors of the type of this, there is the type of anOther
159 return anOther == this ||
160 ( myNumberOfAncestor &&
161 (*(Handle(Standard_Type)*)myAncestors)->SubType(anOther) );
162}
163
164//============================================================================
165Standard_Boolean Standard_Type::SubType(const Standard_CString theName)const
166{
167 // Among ancestors of the type of this, there is the type of anOther
168 if ( ! theName )
169 return Standard_False;
170 if ( IsSimilar(myName, theName) )
171 return Standard_True;
172 if (myNumberOfAncestor)
173 return (*(Handle(Standard_Type) *)myAncestors)->SubType(theName);
174 return Standard_False;
175}
176
177//============================================================================
178void Standard_Type::ShallowDump() const
179{
180 ShallowDump(cout) ;
181}
182
183//============================================================================
184void Standard_Type::ShallowDump(Standard_OStream& AStream) const
185{
186 Standard_Integer i;
187 Handle(Standard_Type) aType;
188
189 Handle(Standard_Type) *allAncestors;
190
191// AStream << "Standard_Type " << hex << (Standard_Address )this << dec << " " ;
192
193 allAncestors = (Handle(Standard_Type) *)myAncestors;
194
195 if(myKind == Standard_IsEnumeration) {
196 AStream << "enumeration " << myName << endl;
197 }
198
199 if(myKind == Standard_IsPrimitive) {
200 AStream << "primitive " << myName << endl;
201 }
202
203 if(myKind == Standard_IsImported) {
204 AStream << "imported " << myName << endl;
205 }
206
207 if(myKind == Standard_IsClass) {
208 AStream << "class " << myName << endl;
209 if(SubType(STANDARD_TYPE(Standard_Transient))) {
210 AStream << " -- manipulated by 'Handle'" << endl;
211 }
212 else if(SubType(STANDARD_TYPE(Standard_Persistent))) {
213 AStream << " -- manipulated by 'Handle' and is 'persistent'"<< endl;
214 }
215 }
216
217 if(myNumberOfParent > 0) {
218 AStream << " inherits ";
219 for(i=0; i<myNumberOfParent; i++){
220 aType = allAncestors[i];
221 if (i>1) AStream <<", ";
222 if ( !aType.IsNull() )
223 AStream << aType->Name();
224 else
225 AStream << " ??? (TypeIsNull)" ;
226 }
227 AStream << endl;
228 }
229
230 if(myNumberOfAncestor > myNumberOfParent) {
231 AStream << " -- Ancestors: ";
232 for(i=myNumberOfParent; i<myNumberOfAncestor; i++){
233 aType = allAncestors[i];
234 if (i>1) AStream <<", ";
235 if ( !aType.IsNull() )
236 AStream << aType->Name();
237 else
238 AStream << " ??? (TypeIsNull)" ;
239 }
240 AStream << endl;
241 }
242}
243
244// ------------------------------------------------------------------
245// Print (me; s: in out OStream) returns OStream;
246// ------------------------------------------------------------------
247void Standard_Type::Print (Standard_OStream& AStream) const
248{
249// AStream << myName ;
250 AStream << hex << (Standard_Address ) myName << " : " << dec << myName ;
251}
252
253Standard_OStream& operator << (Standard_OStream& AStream
254 ,const Handle(Standard_Type)& AType)
255{
256 AType->Print(AStream);
257 return AStream;
258}