1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 #include <StepData_SelectType.ixx>
19 #include <Standard_TypeMismatch.hxx>
20 #include <StepData_SelectNamed.hxx>
21 #include <StepData_SelectReal.hxx>
22 #include <StepData_SelectInt.hxx>
23 #include <Interface_Macros.hxx>
27 Standard_Boolean StepData_SelectType::Matches
28 (const Handle(Standard_Transient)& ent) const
30 if (CaseNum(ent) > 0) return Standard_True;
31 DeclareAndCast(StepData_SelectMember,sm,ent);
32 if (sm.IsNull()) return Standard_False;
33 if (CaseMem(sm) > 0) return Standard_True;
34 return Standard_False;
37 void StepData_SelectType::SetValue (const Handle(Standard_Transient)& ent)
39 if (ent.IsNull()) thevalue.Nullify();
40 else if (!Matches(ent))
41 Standard_TypeMismatch::Raise ("StepData : SelectType, SetValue");
45 void StepData_SelectType::Nullify ()
46 { thevalue.Nullify(); }
48 const Handle(Standard_Transient)& StepData_SelectType::Value () const
51 Standard_Boolean StepData_SelectType::IsNull () const
52 { return thevalue.IsNull(); }
54 Handle(Standard_Type) StepData_SelectType::Type () const
56 if (thevalue.IsNull()) return STANDARD_TYPE(Standard_Transient);
57 return thevalue->DynamicType();
60 Standard_Integer StepData_SelectType::CaseNumber () const
61 { if (thevalue.IsNull()) return 0; return CaseNum(thevalue); }
64 // ********** Types Immediats ***********
66 Handle(StepData_PDescr) StepData_SelectType::Description () const
67 { Handle(StepData_PDescr) nuldescr; return nuldescr; }
69 Handle(StepData_SelectMember) StepData_SelectType::NewMember () const
70 { Handle(StepData_SelectMember) nulmem; return nulmem; }
72 Standard_Integer StepData_SelectType::CaseMem (const Handle(StepData_SelectMember)& /*ent*/) const
75 Standard_Integer StepData_SelectType::CaseMember () const
77 DeclareAndCast(StepData_SelectMember,sm,thevalue);
78 if (sm.IsNull()) return 0;
82 Handle(StepData_SelectMember) StepData_SelectType::Member () const
83 { return GetCasted(StepData_SelectMember,thevalue); }
85 Standard_CString StepData_SelectType::SelectName () const
87 DeclareAndCast(StepData_SelectMember,sm,thevalue);
88 if (sm.IsNull()) return "";
92 Standard_Integer StepData_SelectType::Int () const
94 DeclareAndCast(StepData_SelectMember,sm,thevalue);
95 if (sm.IsNull()) return 0;
99 void StepData_SelectType::SetInt (const Standard_Integer val)
101 DeclareAndCast(StepData_SelectMember,sm,thevalue);
102 if (sm.IsNull()) Standard_TypeMismatch::Raise ("StepData : SelectType, SetInt");
106 // ********** Types Immediats : Differents Cas ***********
108 static Handle(StepData_SelectMember) SelectVal
109 (const Handle(Standard_Transient)& thevalue, const Standard_CString name,
112 DeclareAndCast(StepData_SelectMember,sm,thevalue);
114 if (name && name[0] != '\0')
115 if (!sm->SetName(name)) Standard_TypeMismatch::Raise ("StepData : SelectType, SetInteger");
117 else if (name && name[0] != '\0') {
118 Handle(StepData_SelectNamed) sn = new StepData_SelectNamed;
122 if (mode == 0) sm = new StepData_SelectInt;
123 if (mode == 1) sm = new StepData_SelectReal;
129 Standard_Integer StepData_SelectType::Integer () const
131 DeclareAndCast(StepData_SelectMember,sm,thevalue);
132 if (sm.IsNull()) return 0;
133 return sm->Integer();
136 void StepData_SelectType::SetInteger
137 (const Standard_Integer val, const Standard_CString name)
139 Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,0);
140 sm->SetInteger (val);
141 if (CaseMem (sm) == 0) Standard_TypeMismatch::Raise ("StepData : SelectType, SetInteger");
145 Standard_Boolean StepData_SelectType::Boolean () const
147 DeclareAndCast(StepData_SelectMember,sm,thevalue);
148 if (sm.IsNull()) return Standard_False;
149 return sm->Boolean();
152 void StepData_SelectType::SetBoolean
153 (const Standard_Boolean val, const Standard_CString name)
155 Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,0);
156 sm->SetBoolean (val);
157 if (CaseMem (sm) == 0) Standard_TypeMismatch::Raise ("StepData : SelectType, SetBoolean");
161 StepData_Logical StepData_SelectType::Logical () const
163 DeclareAndCast(StepData_SelectMember,sm,thevalue);
164 if (sm.IsNull()) return StepData_LUnknown;
165 return sm->Logical();
168 void StepData_SelectType::SetLogical
169 (const StepData_Logical val, const Standard_CString name)
171 Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,0);
172 sm->SetLogical (val);
173 if (CaseMem (sm) == 0) Standard_TypeMismatch::Raise ("StepData : SelectType, SetLogical");
177 Standard_Real StepData_SelectType::Real () const
179 DeclareAndCast(StepData_SelectMember,sm,thevalue);
180 if (sm.IsNull()) return 0.0;
184 void StepData_SelectType::SetReal
185 (const Standard_Real val, const Standard_CString name)
187 Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,1);
189 if (CaseMem (sm) == 0) Standard_TypeMismatch::Raise ("StepData : SelectType, SetReal");
193 void StepData_SelectType::Destroy(){}