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 under
6 // the terms of the GNU Lesser General Public License 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>
20 #include <Standard_Transient.hxx>
24 Standard_Boolean StepData_SelectType::Matches
25 (const Handle(Standard_Transient)& ent) const
27 if (CaseNum(ent) > 0) return Standard_True;
28 DeclareAndCast(StepData_SelectMember,sm,ent);
29 if (sm.IsNull()) return Standard_False;
30 if (CaseMem(sm) > 0) return Standard_True;
31 return Standard_False;
34 void StepData_SelectType::SetValue (const Handle(Standard_Transient)& ent)
36 if (ent.IsNull()) thevalue.Nullify();
37 else if (!Matches(ent))
38 Standard_TypeMismatch::Raise ("StepData : SelectType, SetValue");
42 void StepData_SelectType::Nullify ()
43 { thevalue.Nullify(); }
45 const Handle(Standard_Transient)& StepData_SelectType::Value () const
48 Standard_Boolean StepData_SelectType::IsNull () const
49 { return thevalue.IsNull(); }
51 Handle(Standard_Type) StepData_SelectType::Type () const
53 if (thevalue.IsNull()) return STANDARD_TYPE(Standard_Transient);
54 return thevalue->DynamicType();
57 Standard_Integer StepData_SelectType::CaseNumber () const
58 { if (thevalue.IsNull()) return 0; return CaseNum(thevalue); }
61 // ********** Types Immediats ***********
63 Handle(StepData_PDescr) StepData_SelectType::Description () const
64 { Handle(StepData_PDescr) nuldescr; return nuldescr; }
66 Handle(StepData_SelectMember) StepData_SelectType::NewMember () const
67 { Handle(StepData_SelectMember) nulmem; return nulmem; }
69 Standard_Integer StepData_SelectType::CaseMem (const Handle(StepData_SelectMember)& /*ent*/) const
72 Standard_Integer StepData_SelectType::CaseMember () const
74 DeclareAndCast(StepData_SelectMember,sm,thevalue);
75 if (sm.IsNull()) return 0;
79 Handle(StepData_SelectMember) StepData_SelectType::Member () const
80 { return GetCasted(StepData_SelectMember,thevalue); }
82 Standard_CString StepData_SelectType::SelectName () const
84 DeclareAndCast(StepData_SelectMember,sm,thevalue);
85 if (sm.IsNull()) return "";
89 Standard_Integer StepData_SelectType::Int () const
91 DeclareAndCast(StepData_SelectMember,sm,thevalue);
92 if (sm.IsNull()) return 0;
96 void StepData_SelectType::SetInt (const Standard_Integer val)
98 DeclareAndCast(StepData_SelectMember,sm,thevalue);
99 if (sm.IsNull()) Standard_TypeMismatch::Raise ("StepData : SelectType, SetInt");
103 // ********** Types Immediats : Differents Cas ***********
105 static Handle(StepData_SelectMember) SelectVal
106 (const Handle(Standard_Transient)& thevalue, const Standard_CString name,
109 DeclareAndCast(StepData_SelectMember,sm,thevalue);
111 if (name && name[0] != '\0')
112 if (!sm->SetName(name)) Standard_TypeMismatch::Raise ("StepData : SelectType, SetInteger");
114 else if (name && name[0] != '\0') {
115 Handle(StepData_SelectNamed) sn = new StepData_SelectNamed;
119 if (mode == 0) sm = new StepData_SelectInt;
120 if (mode == 1) sm = new StepData_SelectReal;
126 Standard_Integer StepData_SelectType::Integer () const
128 DeclareAndCast(StepData_SelectMember,sm,thevalue);
129 if (sm.IsNull()) return 0;
130 return sm->Integer();
133 void StepData_SelectType::SetInteger
134 (const Standard_Integer val, const Standard_CString name)
136 Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,0);
137 sm->SetInteger (val);
138 if (CaseMem (sm) == 0) Standard_TypeMismatch::Raise ("StepData : SelectType, SetInteger");
142 Standard_Boolean StepData_SelectType::Boolean () const
144 DeclareAndCast(StepData_SelectMember,sm,thevalue);
145 if (sm.IsNull()) return Standard_False;
146 return sm->Boolean();
149 void StepData_SelectType::SetBoolean
150 (const Standard_Boolean val, const Standard_CString name)
152 Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,0);
153 sm->SetBoolean (val);
154 if (CaseMem (sm) == 0) Standard_TypeMismatch::Raise ("StepData : SelectType, SetBoolean");
158 StepData_Logical StepData_SelectType::Logical () const
160 DeclareAndCast(StepData_SelectMember,sm,thevalue);
161 if (sm.IsNull()) return StepData_LUnknown;
162 return sm->Logical();
165 void StepData_SelectType::SetLogical
166 (const StepData_Logical val, const Standard_CString name)
168 Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,0);
169 sm->SetLogical (val);
170 if (CaseMem (sm) == 0) Standard_TypeMismatch::Raise ("StepData : SelectType, SetLogical");
174 Standard_Real StepData_SelectType::Real () const
176 DeclareAndCast(StepData_SelectMember,sm,thevalue);
177 if (sm.IsNull()) return 0.0;
181 void StepData_SelectType::SetReal
182 (const Standard_Real val, const Standard_CString name)
184 Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,1);
186 if (CaseMem (sm) == 0) Standard_TypeMismatch::Raise ("StepData : SelectType, SetReal");
190 void StepData_SelectType::Destroy(){}