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.
15 #include <Interface_Macros.hxx>
16 #include <Standard_Transient.hxx>
17 #include <Standard_TypeMismatch.hxx>
18 #include <StepData_PDescr.hxx>
19 #include <StepData_SelectInt.hxx>
20 #include <StepData_SelectMember.hxx>
21 #include <StepData_SelectNamed.hxx>
22 #include <StepData_SelectReal.hxx>
23 #include <StepData_SelectType.hxx>
25 Standard_Boolean StepData_SelectType::Matches
26 (const Handle(Standard_Transient)& ent) const
28 if (CaseNum(ent) > 0) return Standard_True;
29 DeclareAndCast(StepData_SelectMember,sm,ent);
30 if (sm.IsNull()) return Standard_False;
31 if (CaseMem(sm) > 0) return Standard_True;
32 return Standard_False;
35 void StepData_SelectType::SetValue (const Handle(Standard_Transient)& ent)
37 if (ent.IsNull()) thevalue.Nullify();
38 else if (!Matches(ent))
39 Standard_TypeMismatch::Raise ("StepData : SelectType, SetValue");
43 void StepData_SelectType::Nullify ()
44 { thevalue.Nullify(); }
46 const Handle(Standard_Transient)& StepData_SelectType::Value () const
49 Standard_Boolean StepData_SelectType::IsNull () const
50 { return thevalue.IsNull(); }
52 Handle(Standard_Type) StepData_SelectType::Type () const
54 if (thevalue.IsNull()) return STANDARD_TYPE(Standard_Transient);
55 return thevalue->DynamicType();
58 Standard_Integer StepData_SelectType::CaseNumber () const
59 { if (thevalue.IsNull()) return 0; return CaseNum(thevalue); }
62 // ********** Types Immediats ***********
64 Handle(StepData_PDescr) StepData_SelectType::Description () const
65 { Handle(StepData_PDescr) nuldescr; return nuldescr; }
67 Handle(StepData_SelectMember) StepData_SelectType::NewMember () const
68 { Handle(StepData_SelectMember) nulmem; return nulmem; }
70 Standard_Integer StepData_SelectType::CaseMem (const Handle(StepData_SelectMember)& /*ent*/) const
73 Standard_Integer StepData_SelectType::CaseMember () const
75 DeclareAndCast(StepData_SelectMember,sm,thevalue);
76 if (sm.IsNull()) return 0;
80 Handle(StepData_SelectMember) StepData_SelectType::Member () const
81 { return GetCasted(StepData_SelectMember,thevalue); }
83 Standard_CString StepData_SelectType::SelectName () const
85 DeclareAndCast(StepData_SelectMember,sm,thevalue);
86 if (sm.IsNull()) return "";
90 Standard_Integer StepData_SelectType::Int () const
92 DeclareAndCast(StepData_SelectMember,sm,thevalue);
93 if (sm.IsNull()) return 0;
97 void StepData_SelectType::SetInt (const Standard_Integer val)
99 DeclareAndCast(StepData_SelectMember,sm,thevalue);
100 if (sm.IsNull()) Standard_TypeMismatch::Raise ("StepData : SelectType, SetInt");
104 // ********** Types Immediats : Differents Cas ***********
106 static Handle(StepData_SelectMember) SelectVal
107 (const Handle(Standard_Transient)& thevalue, const Standard_CString name,
110 DeclareAndCast(StepData_SelectMember,sm,thevalue);
112 if (name && name[0] != '\0')
113 if (!sm->SetName(name)) Standard_TypeMismatch::Raise ("StepData : SelectType, SetInteger");
115 else if (name && name[0] != '\0') {
116 Handle(StepData_SelectNamed) sn = new StepData_SelectNamed;
120 if (mode == 0) sm = new StepData_SelectInt;
121 if (mode == 1) sm = new StepData_SelectReal;
127 Standard_Integer StepData_SelectType::Integer () const
129 DeclareAndCast(StepData_SelectMember,sm,thevalue);
130 if (sm.IsNull()) return 0;
131 return sm->Integer();
134 void StepData_SelectType::SetInteger
135 (const Standard_Integer val, const Standard_CString name)
137 Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,0);
138 sm->SetInteger (val);
139 if (CaseMem (sm) == 0) Standard_TypeMismatch::Raise ("StepData : SelectType, SetInteger");
143 Standard_Boolean StepData_SelectType::Boolean () const
145 DeclareAndCast(StepData_SelectMember,sm,thevalue);
146 if (sm.IsNull()) return Standard_False;
147 return sm->Boolean();
150 void StepData_SelectType::SetBoolean
151 (const Standard_Boolean val, const Standard_CString name)
153 Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,0);
154 sm->SetBoolean (val);
155 if (CaseMem (sm) == 0) Standard_TypeMismatch::Raise ("StepData : SelectType, SetBoolean");
159 StepData_Logical StepData_SelectType::Logical () const
161 DeclareAndCast(StepData_SelectMember,sm,thevalue);
162 if (sm.IsNull()) return StepData_LUnknown;
163 return sm->Logical();
166 void StepData_SelectType::SetLogical
167 (const StepData_Logical val, const Standard_CString name)
169 Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,0);
170 sm->SetLogical (val);
171 if (CaseMem (sm) == 0) Standard_TypeMismatch::Raise ("StepData : SelectType, SetLogical");
175 Standard_Real StepData_SelectType::Real () const
177 DeclareAndCast(StepData_SelectMember,sm,thevalue);
178 if (sm.IsNull()) return 0.0;
182 void StepData_SelectType::SetReal
183 (const Standard_Real val, const Standard_CString name)
185 Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,1);
187 if (CaseMem (sm) == 0) Standard_TypeMismatch::Raise ("StepData : SelectType, SetReal");
191 StepData_SelectType::~StepData_SelectType()