0027532: Errors on reading stp-file
[occt.git] / src / StepData / StepData_SelectType.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14
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>
24
25 Standard_Boolean  StepData_SelectType::Matches
26   (const Handle(Standard_Transient)& ent) const
27 {
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;
33 }
34
35     void  StepData_SelectType::SetValue (const Handle(Standard_Transient)& ent)
36 {
37   if (ent.IsNull())  thevalue.Nullify();
38   else if (!Matches(ent))
39     Standard_TypeMismatch::Raise ("StepData : SelectType, SetValue");
40   else thevalue = ent;
41 }
42
43     void  StepData_SelectType::Nullify ()
44       {  thevalue.Nullify();  }
45
46     const Handle(Standard_Transient)&  StepData_SelectType::Value () const
47       {  return thevalue;  }
48
49     Standard_Boolean  StepData_SelectType::IsNull () const
50       {  return thevalue.IsNull();  }
51
52     Handle(Standard_Type) StepData_SelectType::Type () const
53 {
54   if (thevalue.IsNull()) return STANDARD_TYPE(Standard_Transient);
55   return thevalue->DynamicType();
56 }
57
58     Standard_Integer  StepData_SelectType::CaseNumber () const
59       {  if (thevalue.IsNull()) return 0;  return CaseNum(thevalue);  }
60
61
62 //  **********   Types Immediats   ***********
63
64     Handle(StepData_PDescr)  StepData_SelectType::Description () const
65       {  Handle(StepData_PDescr) nuldescr;  return nuldescr;  }
66
67     Handle(StepData_SelectMember)   StepData_SelectType::NewMember () const
68       {  Handle(StepData_SelectMember) nulmem;  return nulmem;  }
69
70     Standard_Integer  StepData_SelectType::CaseMem (const Handle(StepData_SelectMember)& /*ent*/) const
71       {  return 0;  }
72
73     Standard_Integer  StepData_SelectType::CaseMember () const
74 {
75   DeclareAndCast(StepData_SelectMember,sm,thevalue);
76   if (sm.IsNull()) return 0;
77   return CaseMem (sm);
78 }
79
80     Handle(StepData_SelectMember)  StepData_SelectType::Member () const
81       {  return GetCasted(StepData_SelectMember,thevalue);  }
82
83     Standard_CString  StepData_SelectType::SelectName () const
84 {
85   DeclareAndCast(StepData_SelectMember,sm,thevalue);
86   if (sm.IsNull()) return "";
87   return sm->Name();
88 }
89
90     Standard_Integer  StepData_SelectType::Int () const
91 {
92   DeclareAndCast(StepData_SelectMember,sm,thevalue);
93   if (sm.IsNull()) return 0;
94   return sm->Int();
95 }
96
97     void  StepData_SelectType::SetInt (const Standard_Integer val)
98 {
99   DeclareAndCast(StepData_SelectMember,sm,thevalue);
100   if (sm.IsNull()) Standard_TypeMismatch::Raise ("StepData : SelectType, SetInt");
101   sm->SetInt (val);
102 }
103
104 //  **********   Types Immediats : Differents Cas  ***********
105
106 static Handle(StepData_SelectMember) SelectVal
107   (const Handle(Standard_Transient)& thevalue, const Standard_CString name,
108    const int mode)
109 {
110   DeclareAndCast(StepData_SelectMember,sm,thevalue);
111   if (!sm.IsNull()) {
112     if (name && name[0] != '\0')
113       if (!sm->SetName(name)) Standard_TypeMismatch::Raise ("StepData : SelectType, SetInteger");
114   }
115   else if (name && name[0] != '\0') {
116     Handle(StepData_SelectNamed) sn = new StepData_SelectNamed;
117     sn->SetName (name);
118     sm = sn;
119   } else {
120     if (mode == 0) sm = new StepData_SelectInt;
121     if (mode == 1) sm = new StepData_SelectReal;
122   }
123   return sm;
124 }
125
126
127     Standard_Integer  StepData_SelectType::Integer () const
128 {
129   DeclareAndCast(StepData_SelectMember,sm,thevalue);
130   if (sm.IsNull()) return 0;
131   return sm->Integer();
132 }
133
134     void  StepData_SelectType::SetInteger
135   (const Standard_Integer val, const Standard_CString name)
136 {
137   Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,0);
138   sm->SetInteger (val);
139   if (CaseMem (sm) == 0) Standard_TypeMismatch::Raise ("StepData : SelectType, SetInteger");
140   thevalue = sm;
141 }
142
143     Standard_Boolean  StepData_SelectType::Boolean () const
144 {
145   DeclareAndCast(StepData_SelectMember,sm,thevalue);
146   if (sm.IsNull()) return Standard_False;
147   return sm->Boolean();
148 }
149
150     void  StepData_SelectType::SetBoolean
151   (const Standard_Boolean val, const Standard_CString name)
152 {
153   Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,0);
154   sm->SetBoolean (val);
155   if (CaseMem (sm) == 0) Standard_TypeMismatch::Raise ("StepData : SelectType, SetBoolean");
156   thevalue = sm;
157 }
158
159     StepData_Logical  StepData_SelectType::Logical () const
160 {
161   DeclareAndCast(StepData_SelectMember,sm,thevalue);
162   if (sm.IsNull()) return StepData_LUnknown;
163   return sm->Logical();
164 }
165
166     void  StepData_SelectType::SetLogical
167   (const StepData_Logical val, const Standard_CString name)
168 {
169   Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,0);
170   sm->SetLogical (val);
171   if (CaseMem (sm) == 0) Standard_TypeMismatch::Raise ("StepData : SelectType, SetLogical");
172   thevalue = sm;
173 }
174
175 Standard_Real  StepData_SelectType::Real () const
176 {
177   DeclareAndCast(StepData_SelectMember,sm,thevalue);
178   if (sm.IsNull()) return 0.0;
179   return sm->Real();
180 }
181
182     void  StepData_SelectType::SetReal
183   (const Standard_Real val, const Standard_CString name)
184 {
185   Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,1);
186   sm->SetReal (val);
187   if (CaseMem (sm) == 0) Standard_TypeMismatch::Raise ("StepData : SelectType, SetReal");
188   thevalue = sm;
189 }
190
191 StepData_SelectType::~StepData_SelectType()
192 {}