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