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
7 // under the terms of the GNU Lesser General Public 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.
19 #include <Standard_Type.ixx>
20 #include <Standard_Persistent.hxx>
22 //============================================================================
23 // The constructor for a imported Type
24 //============================================================================
26 Standard_Type::Standard_Type(const Standard_CString aName,
27 const Standard_Integer aSize)
31 myKind = Standard_IsImported;
33 //==== Just for be clean with the class and the enumeration ================
35 myNumberOfAncestor = 0;
40 //============================================================================
41 // The constructor for a primitive Type
42 //============================================================================
44 Standard_Type::Standard_Type(const Standard_CString aName,
45 const Standard_Integer aSize,
46 const Standard_Integer aNumberOfParent ,
47 const Standard_Address aAncestors)
51 myKind = Standard_IsPrimitive;
53 myNumberOfParent = aNumberOfParent;
55 //==== Calculate the number of ancestor ====================================
56 myNumberOfAncestor = 0;
57 myAncestors = aAncestors;
58 Handle(Standard_Type) *allAncestors = (Handle(Standard_Type) *)myAncestors;
59 for(Standard_Integer i=0; allAncestors && !allAncestors[i].IsNull(); i++) {
64 //============================================================================
65 // The constructor for an enumeration.
66 //============================================================================
68 Standard_Type::Standard_Type(const Standard_CString aName,
69 const Standard_Integer aSize,
70 const Standard_Integer ,
71 const Standard_Integer aNumberOfParent,
72 const Standard_Address aAncestors,
73 const Standard_Address )
77 myKind = Standard_IsEnumeration;
79 myNumberOfParent = aNumberOfParent;
81 //==== Calculate the number of ancestor ====================================
82 myNumberOfAncestor = 0;
83 myAncestors = aAncestors;
84 Handle(Standard_Type) *allAncestors = (Handle(Standard_Type) *)myAncestors;
85 for(Standard_Integer i=0; allAncestors && !allAncestors[i].IsNull(); i++) {
90 //============================================================================
91 // The constructor for a class.
92 //============================================================================
94 Standard_Type::Standard_Type(const Standard_CString aName,
95 const Standard_Integer aSize,
96 const Standard_Integer aNumberOfParent ,
97 const Standard_Address aAncestors ,
98 const Standard_Address )
102 myKind = Standard_IsClass;
104 myNumberOfParent = aNumberOfParent;
106 //==== Calculate the number of ancestors ===================================
107 myNumberOfAncestor = 0;
108 myAncestors = aAncestors;
109 Handle(Standard_Type) *allAncestors = (Handle(Standard_Type) *)myAncestors;
110 for(Standard_Integer i=0; allAncestors && !allAncestors[i].IsNull(); i++) {
111 myNumberOfAncestor++;
115 //============================================================================
116 Standard_CString Standard_Type::Name() const
121 //============================================================================
122 Standard_Integer Standard_Type::Size()const
127 //============================================================================
128 Standard_Boolean Standard_Type::IsImported()const
130 return myKind == Standard_IsImported;
133 //============================================================================
134 Standard_Boolean Standard_Type::IsPrimitive()const
136 return myKind == Standard_IsPrimitive;
139 //============================================================================
140 Standard_Boolean Standard_Type::IsEnumeration()const
142 return myKind == Standard_IsEnumeration;
145 //============================================================================
146 Standard_Boolean Standard_Type::IsClass()const
148 return myKind == Standard_IsClass;
151 //============================================================================
152 Standard_Integer Standard_Type::NumberOfParent()const
154 return myNumberOfParent;
157 //============================================================================
158 Standard_Integer Standard_Type::NumberOfAncestor()const
160 return myNumberOfAncestor;
163 //============================================================================
164 Standard_Address Standard_Type::Ancestors()const
169 //============================================================================
170 Standard_Boolean Standard_Type::SubType(const Handle_Standard_Type& anOther)const
172 // Among ancestors of the type of this, there is the type of anOther
173 return anOther == this ||
174 ( myNumberOfAncestor &&
175 (*(Handle(Standard_Type)*)myAncestors)->SubType(anOther) );
178 //============================================================================
179 Standard_Boolean Standard_Type::SubType(const Standard_CString theName)const
181 // Among ancestors of the type of this, there is the type of anOther
183 return Standard_False;
184 if ( IsSimilar(myName, theName) )
185 return Standard_True;
186 if (myNumberOfAncestor)
187 return (*(Handle(Standard_Type) *)myAncestors)->SubType(theName);
188 return Standard_False;
191 //============================================================================
192 void Standard_Type::ShallowDump() const
197 //============================================================================
198 void Standard_Type::ShallowDump(Standard_OStream& AStream) const
201 Handle(Standard_Type) aType;
203 Handle(Standard_Type) *allAncestors;
205 // AStream << "Standard_Type " << hex << (Standard_Address )this << dec << " " ;
207 allAncestors = (Handle(Standard_Type) *)myAncestors;
209 if(myKind == Standard_IsEnumeration) {
210 AStream << "enumeration " << myName << endl;
213 if(myKind == Standard_IsPrimitive) {
214 AStream << "primitive " << myName << endl;
217 if(myKind == Standard_IsImported) {
218 AStream << "imported " << myName << endl;
221 if(myKind == Standard_IsClass) {
222 AStream << "class " << myName << endl;
223 if(SubType(STANDARD_TYPE(Standard_Transient))) {
224 AStream << " -- manipulated by 'Handle'" << endl;
226 else if(SubType(STANDARD_TYPE(Standard_Persistent))) {
227 AStream << " -- manipulated by 'Handle' and is 'persistent'"<< endl;
231 if(myNumberOfParent > 0) {
232 AStream << " inherits ";
233 for(i=0; i<myNumberOfParent; i++){
234 aType = allAncestors[i];
235 if (i>1) AStream <<", ";
236 if ( !aType.IsNull() )
237 AStream << aType->Name();
239 AStream << " ??? (TypeIsNull)" ;
244 if(myNumberOfAncestor > myNumberOfParent) {
245 AStream << " -- Ancestors: ";
246 for(i=myNumberOfParent; i<myNumberOfAncestor; i++){
247 aType = allAncestors[i];
248 if (i>1) AStream <<", ";
249 if ( !aType.IsNull() )
250 AStream << aType->Name();
252 AStream << " ??? (TypeIsNull)" ;
258 // ------------------------------------------------------------------
259 // Print (me; s: in out OStream) returns OStream;
260 // ------------------------------------------------------------------
261 void Standard_Type::Print (Standard_OStream& AStream) const
263 // AStream << myName ;
264 AStream << hex << (Standard_Address ) myName << " : " << dec << myName ;
267 Standard_OStream& operator << (Standard_OStream& AStream
268 ,const Handle(Standard_Type)& AType)
270 AType->Print(AStream);