Integration of OCCT 6.5.0 from SVN
[occt.git] / src / StepData / StepData_SelectType.cxx
CommitLineData
7fd59977 1#include <StepData_SelectType.ixx>
2#include <Standard_TypeMismatch.hxx>
3#include <StepData_SelectNamed.hxx>
4#include <StepData_SelectReal.hxx>
5#include <StepData_SelectInt.hxx>
6#include <Interface_Macros.hxx>
7
8
9
10 Standard_Boolean StepData_SelectType::Matches
11 (const Handle(Standard_Transient)& ent) const
12{
13 if (CaseNum(ent) > 0) return Standard_True;
14 DeclareAndCast(StepData_SelectMember,sm,ent);
15 if (sm.IsNull()) return Standard_False;
16 if (CaseMem(sm) > 0) return Standard_True;
17 return Standard_False;
18}
19
20 void StepData_SelectType::SetValue (const Handle(Standard_Transient)& ent)
21{
22 if (ent.IsNull()) thevalue.Nullify();
23 else if (!Matches(ent))
24 Standard_TypeMismatch::Raise ("StepData : SelectType, SetValue");
25 else thevalue = ent;
26}
27
28 void StepData_SelectType::Nullify ()
29 { thevalue.Nullify(); }
30
31 const Handle(Standard_Transient)& StepData_SelectType::Value () const
32 { return thevalue; }
33
34 Standard_Boolean StepData_SelectType::IsNull () const
35 { return thevalue.IsNull(); }
36
37 Handle(Standard_Type) StepData_SelectType::Type () const
38{
39 if (thevalue.IsNull()) return STANDARD_TYPE(Standard_Transient);
40 return thevalue->DynamicType();
41}
42
43 Standard_Integer StepData_SelectType::CaseNumber () const
44 { if (thevalue.IsNull()) return 0; return CaseNum(thevalue); }
45
46
47// ********** Types Immediats ***********
48
49 Handle(StepData_PDescr) StepData_SelectType::Description () const
50 { Handle(StepData_PDescr) nuldescr; return nuldescr; }
51
52 Handle(StepData_SelectMember) StepData_SelectType::NewMember () const
53 { Handle(StepData_SelectMember) nulmem; return nulmem; }
54
55 Standard_Integer StepData_SelectType::CaseMem (const Handle(StepData_SelectMember)& ent) const
56 { return 0; }
57
58 Standard_Integer StepData_SelectType::CaseMember () const
59{
60 DeclareAndCast(StepData_SelectMember,sm,thevalue);
61 if (sm.IsNull()) return 0;
62 return CaseMem (sm);
63}
64
65 Handle(StepData_SelectMember) StepData_SelectType::Member () const
66 { return GetCasted(StepData_SelectMember,thevalue); }
67
68 Standard_CString StepData_SelectType::SelectName () const
69{
70 DeclareAndCast(StepData_SelectMember,sm,thevalue);
71 if (sm.IsNull()) return "";
72 return sm->Name();
73}
74
75 Standard_Integer StepData_SelectType::Int () const
76{
77 DeclareAndCast(StepData_SelectMember,sm,thevalue);
78 if (sm.IsNull()) return 0;
79 return sm->Int();
80}
81
82 void StepData_SelectType::SetInt (const Standard_Integer val)
83{
84 DeclareAndCast(StepData_SelectMember,sm,thevalue);
85 if (sm.IsNull()) Standard_TypeMismatch::Raise ("StepData : SelectType, SetInt");
86 sm->SetInt (val);
87}
88
89// ********** Types Immediats : Differents Cas ***********
90
91static Handle(StepData_SelectMember) SelectVal
92 (const Handle(Standard_Transient)& thevalue, const Standard_CString name,
93 const int mode)
94{
95 DeclareAndCast(StepData_SelectMember,sm,thevalue);
96 if (!sm.IsNull()) {
97 if (name && name[0] != '\0')
98 if (!sm->SetName(name)) Standard_TypeMismatch::Raise ("StepData : SelectType, SetInteger");
99 }
100 else if (name && name[0] != '\0') {
101 Handle(StepData_SelectNamed) sn = new StepData_SelectNamed;
102 sn->SetName (name);
103 sm = sn;
104 } else {
105 if (mode == 0) sm = new StepData_SelectInt;
106 if (mode == 1) sm = new StepData_SelectReal;
107 }
108 return sm;
109}
110
111
112 Standard_Integer StepData_SelectType::Integer () const
113{
114 DeclareAndCast(StepData_SelectMember,sm,thevalue);
115 if (sm.IsNull()) return 0;
116 return sm->Integer();
117}
118
119 void StepData_SelectType::SetInteger
120 (const Standard_Integer val, const Standard_CString name)
121{
122 Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,0);
123 sm->SetInteger (val);
124 if (CaseMem (sm) == 0) Standard_TypeMismatch::Raise ("StepData : SelectType, SetInteger");
125 thevalue = sm;
126}
127
128 Standard_Boolean StepData_SelectType::Boolean () const
129{
130 DeclareAndCast(StepData_SelectMember,sm,thevalue);
131 if (sm.IsNull()) return Standard_False;
132 return sm->Boolean();
133}
134
135 void StepData_SelectType::SetBoolean
136 (const Standard_Boolean val, const Standard_CString name)
137{
138 Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,0);
139 sm->SetBoolean (val);
140 if (CaseMem (sm) == 0) Standard_TypeMismatch::Raise ("StepData : SelectType, SetBoolean");
141 thevalue = sm;
142}
143
144 StepData_Logical StepData_SelectType::Logical () const
145{
146 DeclareAndCast(StepData_SelectMember,sm,thevalue);
147 if (sm.IsNull()) return StepData_LUnknown;
148 return sm->Logical();
149}
150
151 void StepData_SelectType::SetLogical
152 (const StepData_Logical val, const Standard_CString name)
153{
154 Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,0);
155 sm->SetLogical (val);
156 if (CaseMem (sm) == 0) Standard_TypeMismatch::Raise ("StepData : SelectType, SetLogical");
157 thevalue = sm;
158}
159
160Standard_Real StepData_SelectType::Real () const
161{
162 DeclareAndCast(StepData_SelectMember,sm,thevalue);
163 if (sm.IsNull()) return 0.0;
164 return sm->Real();
165}
166
167 void StepData_SelectType::SetReal
168 (const Standard_Real val, const Standard_CString name)
169{
170 Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,1);
171 sm->SetReal (val);
172 if (CaseMem (sm) == 0) Standard_TypeMismatch::Raise ("StepData : SelectType, SetReal");
173 thevalue = sm;
174}
175
176void StepData_SelectType::Destroy(){}