1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and / or modify it
6 // under the terms of the GNU Lesser General Public version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <StepData_SelectType.ixx>
15 #include <Standard_TypeMismatch.hxx>
16 #include <StepData_SelectNamed.hxx>
17 #include <StepData_SelectReal.hxx>
18 #include <StepData_SelectInt.hxx>
19 #include <Interface_Macros.hxx>
23 Standard_Boolean StepData_SelectType::Matches
24 (const Handle(Standard_Transient)& ent) const
26 if (CaseNum(ent) > 0) return Standard_True;
27 DeclareAndCast(StepData_SelectMember,sm,ent);
28 if (sm.IsNull()) return Standard_False;
29 if (CaseMem(sm) > 0) return Standard_True;
30 return Standard_False;
33 void StepData_SelectType::SetValue (const Handle(Standard_Transient)& ent)
35 if (ent.IsNull()) thevalue.Nullify();
36 else if (!Matches(ent))
37 Standard_TypeMismatch::Raise ("StepData : SelectType, SetValue");
41 void StepData_SelectType::Nullify ()
42 { thevalue.Nullify(); }
44 const Handle(Standard_Transient)& StepData_SelectType::Value () const
47 Standard_Boolean StepData_SelectType::IsNull () const
48 { return thevalue.IsNull(); }
50 Handle(Standard_Type) StepData_SelectType::Type () const
52 if (thevalue.IsNull()) return STANDARD_TYPE(Standard_Transient);
53 return thevalue->DynamicType();
56 Standard_Integer StepData_SelectType::CaseNumber () const
57 { if (thevalue.IsNull()) return 0; return CaseNum(thevalue); }
60 // ********** Types Immediats ***********
62 Handle(StepData_PDescr) StepData_SelectType::Description () const
63 { Handle(StepData_PDescr) nuldescr; return nuldescr; }
65 Handle(StepData_SelectMember) StepData_SelectType::NewMember () const
66 { Handle(StepData_SelectMember) nulmem; return nulmem; }
68 Standard_Integer StepData_SelectType::CaseMem (const Handle(StepData_SelectMember)& /*ent*/) const
71 Standard_Integer StepData_SelectType::CaseMember () const
73 DeclareAndCast(StepData_SelectMember,sm,thevalue);
74 if (sm.IsNull()) return 0;
78 Handle(StepData_SelectMember) StepData_SelectType::Member () const
79 { return GetCasted(StepData_SelectMember,thevalue); }
81 Standard_CString StepData_SelectType::SelectName () const
83 DeclareAndCast(StepData_SelectMember,sm,thevalue);
84 if (sm.IsNull()) return "";
88 Standard_Integer StepData_SelectType::Int () const
90 DeclareAndCast(StepData_SelectMember,sm,thevalue);
91 if (sm.IsNull()) return 0;
95 void StepData_SelectType::SetInt (const Standard_Integer val)
97 DeclareAndCast(StepData_SelectMember,sm,thevalue);
98 if (sm.IsNull()) Standard_TypeMismatch::Raise ("StepData : SelectType, SetInt");
102 // ********** Types Immediats : Differents Cas ***********
104 static Handle(StepData_SelectMember) SelectVal
105 (const Handle(Standard_Transient)& thevalue, const Standard_CString name,
108 DeclareAndCast(StepData_SelectMember,sm,thevalue);
110 if (name && name[0] != '\0')
111 if (!sm->SetName(name)) Standard_TypeMismatch::Raise ("StepData : SelectType, SetInteger");
113 else if (name && name[0] != '\0') {
114 Handle(StepData_SelectNamed) sn = new StepData_SelectNamed;
118 if (mode == 0) sm = new StepData_SelectInt;
119 if (mode == 1) sm = new StepData_SelectReal;
125 Standard_Integer StepData_SelectType::Integer () const
127 DeclareAndCast(StepData_SelectMember,sm,thevalue);
128 if (sm.IsNull()) return 0;
129 return sm->Integer();
132 void StepData_SelectType::SetInteger
133 (const Standard_Integer val, const Standard_CString name)
135 Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,0);
136 sm->SetInteger (val);
137 if (CaseMem (sm) == 0) Standard_TypeMismatch::Raise ("StepData : SelectType, SetInteger");
141 Standard_Boolean StepData_SelectType::Boolean () const
143 DeclareAndCast(StepData_SelectMember,sm,thevalue);
144 if (sm.IsNull()) return Standard_False;
145 return sm->Boolean();
148 void StepData_SelectType::SetBoolean
149 (const Standard_Boolean val, const Standard_CString name)
151 Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,0);
152 sm->SetBoolean (val);
153 if (CaseMem (sm) == 0) Standard_TypeMismatch::Raise ("StepData : SelectType, SetBoolean");
157 StepData_Logical StepData_SelectType::Logical () const
159 DeclareAndCast(StepData_SelectMember,sm,thevalue);
160 if (sm.IsNull()) return StepData_LUnknown;
161 return sm->Logical();
164 void StepData_SelectType::SetLogical
165 (const StepData_Logical val, const Standard_CString name)
167 Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,0);
168 sm->SetLogical (val);
169 if (CaseMem (sm) == 0) Standard_TypeMismatch::Raise ("StepData : SelectType, SetLogical");
173 Standard_Real StepData_SelectType::Real () const
175 DeclareAndCast(StepData_SelectMember,sm,thevalue);
176 if (sm.IsNull()) return 0.0;
180 void StepData_SelectType::SetReal
181 (const Standard_Real val, const Standard_CString name)
183 Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,1);
185 if (CaseMem (sm) == 0) Standard_TypeMismatch::Raise ("StepData : SelectType, SetReal");
189 void StepData_SelectType::Destroy(){}