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 | |
7fd59977 |
15 | #include <Message_Messenger.hxx> |
42cf5bc1 |
16 | #include <MoniTool_Element.hxx> |
17 | #include <MoniTool_TypedValue.hxx> |
7fd59977 |
18 | #include <OSD_Path.hxx> |
42cf5bc1 |
19 | #include <Standard_ConstructionError.hxx> |
ec357c5c |
20 | #include <Standard_Transient.hxx> |
42cf5bc1 |
21 | #include <Standard_Type.hxx> |
22 | #include <TCollection_AsciiString.hxx> |
23 | #include <TCollection_HAsciiString.hxx> |
7fd59977 |
24 | |
42cf5bc1 |
25 | #include <stdio.h> |
92efcf78 |
26 | IMPLEMENT_STANDARD_RTTIEXT(MoniTool_TypedValue,MMgt_TShared) |
27 | |
7fd59977 |
28 | // Not Used : |
29 | //static char defmess[30]; |
997e128f |
30 | static NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)> thelibtv; |
31 | static NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)> astats; |
32 | |
33 | static NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)>& libtv() |
7fd59977 |
34 | { |
997e128f |
35 | if (thelibtv.IsEmpty()) { |
7fd59977 |
36 | Handle(MoniTool_TypedValue) tv; |
37 | tv = new MoniTool_TypedValue("Integer",MoniTool_ValueInteger); |
997e128f |
38 | thelibtv.Bind ("Integer",tv); |
7fd59977 |
39 | tv = new MoniTool_TypedValue("Real",MoniTool_ValueReal); |
997e128f |
40 | thelibtv.Bind ("Real",tv); |
7fd59977 |
41 | tv = new MoniTool_TypedValue("Text",MoniTool_ValueText); |
997e128f |
42 | thelibtv.Bind ("Text",tv); |
7fd59977 |
43 | tv = new MoniTool_TypedValue("Transient",MoniTool_ValueIdent); |
997e128f |
44 | thelibtv.Bind ("Transient",tv); |
7fd59977 |
45 | tv = new MoniTool_TypedValue("Boolean",MoniTool_ValueEnum); |
46 | tv->AddDef ("enum 0"); // = 0 False , > 0 True |
47 | tv->AddDef ("eval False"); |
48 | tv->AddDef ("eval True"); |
997e128f |
49 | thelibtv.Bind ("Boolean",tv); |
7fd59977 |
50 | tv = new MoniTool_TypedValue("Logical",MoniTool_ValueEnum); |
51 | tv->AddDef ("enum -1"); // < 0 False , = 0 Unk , > 0 True |
52 | tv->AddDef ("eval False"); |
53 | tv->AddDef ("eval Unknown"); |
54 | tv->AddDef ("eval True"); |
997e128f |
55 | thelibtv.Bind ("Logical",tv); |
7fd59977 |
56 | } |
57 | return thelibtv; |
58 | } |
59 | |
60 | |
61 | // Fonctions Satisfies offertes en standard ... |
62 | /* Not Used |
63 | |
64 | static Standard_Boolean StaticPath(const Handle(TCollection_HAsciiString)& val) |
65 | { |
66 | OSD_Path apath; |
67 | return apath.IsValid (TCollection_AsciiString(val->ToCString())); |
68 | } |
69 | */ |
70 | |
71 | MoniTool_TypedValue::MoniTool_TypedValue |
72 | (const Standard_CString name, |
73 | const MoniTool_ValueType type, const Standard_CString init) |
74 | : thename (name) , thetype (type) , |
75 | thelims (0), themaxlen (0) , theintlow (0) , theintup (-1) , |
76 | theinterp (NULL) , thesatisf (NULL) , |
77 | theival (0), |
78 | thehval (new TCollection_HAsciiString("")) |
79 | { |
80 | if (type != MoniTool_ValueInteger && type != MoniTool_ValueReal && |
81 | type != MoniTool_ValueEnum && type != MoniTool_ValueText && |
82 | type != MoniTool_ValueIdent) |
83 | Standard_ConstructionError::Raise("MoniTool_TypedValue : Type not supported"); |
84 | if (init[0] != '\0') |
85 | if (Satisfies(new TCollection_HAsciiString(init))) SetCStringValue (init); |
86 | |
87 | } |
88 | |
89 | |
90 | MoniTool_TypedValue::MoniTool_TypedValue |
91 | (const Handle(MoniTool_TypedValue)& other) |
92 | : thename (other->Name()) , thedef (other->Definition()) , |
93 | thelabel (other->Label()) , thetype (other->ValueType()) , |
94 | theotyp (other->ObjectType()) , |
95 | thelims (0) , themaxlen (other->MaxLength()) , |
96 | theintlow (0) , theintup (0) , therealow (0) , therealup (0) , |
97 | theunidef (other->UnitDef()) , |
98 | theival (other->IntegerValue()) , thehval (other->HStringValue()) , |
99 | theoval (other->ObjectValue()) |
100 | { |
997e128f |
101 | NCollection_DataMap<TCollection_AsciiString, Standard_Integer> eadds; |
7fd59977 |
102 | Standard_CString satisname; |
103 | other->Internals (theinterp,thesatisf,satisname, eadds); |
104 | thesatisn.AssignCat (satisname); |
105 | |
106 | if (other->IntegerLimit (Standard_False,theintlow)) thelims |= 1; |
107 | if (other->IntegerLimit (Standard_True ,theintup )) thelims |= 2; |
108 | if (other->RealLimit (Standard_False,therealow)) thelims |= 1; |
109 | if (other->RealLimit (Standard_True ,therealup)) thelims |= 2; |
110 | |
111 | Standard_Integer startcase, endcase; Standard_Boolean match; |
112 | if (other->EnumDef (startcase,endcase,match)) { |
113 | theintlow = startcase; theintup = endcase; |
114 | if (match) thelims |= 4; |
115 | if (theintup >= theintlow) theenums = new TColStd_HArray1OfAsciiString (theintlow,theintup); |
116 | for (startcase = theintlow; startcase <= theintup; startcase ++) { |
117 | theenums->SetValue (startcase,other->EnumVal (startcase)); |
118 | } |
119 | } |
120 | // dupliquer theeadds |
997e128f |
121 | if (!eadds.IsEmpty()) { |
122 | NCollection_DataMap<TCollection_AsciiString, Standard_Integer>::Iterator itad(eadds); |
123 | for (; itad.More(); itad.Next()) theeadds.Bind (itad.Key(),itad.Value()); |
7fd59977 |
124 | } |
125 | |
126 | // on duplique la string |
127 | if (!thehval.IsNull()) thehval = new TCollection_HAsciiString (other->CStringValue()); |
128 | } |
129 | |
130 | |
131 | void MoniTool_TypedValue::Internals |
132 | (MoniTool_ValueInterpret& interp, MoniTool_ValueSatisfies& satisf, |
133 | Standard_CString& satisname, |
997e128f |
134 | NCollection_DataMap<TCollection_AsciiString, Standard_Integer>& enums) const |
7fd59977 |
135 | { interp = theinterp; satisf = thesatisf; satisname = thesatisn.ToCString(); |
136 | enums = theeadds; } |
137 | |
138 | Standard_CString MoniTool_TypedValue::Name () const |
139 | { return thename.ToCString(); } |
140 | |
141 | MoniTool_ValueType MoniTool_TypedValue::ValueType () const |
142 | { return thetype; } |
143 | |
144 | TCollection_AsciiString MoniTool_TypedValue::Definition () const |
145 | { |
146 | if (thedef.Length() > 0) return thedef; |
147 | TCollection_AsciiString def; |
148 | char mess[50]; |
149 | switch (thetype) { |
150 | case MoniTool_ValueInteger : { |
151 | def.AssignCat("Integer"); |
152 | Standard_Integer ilim; |
153 | if (IntegerLimit(Standard_False, ilim)) { |
91322f44 |
154 | Sprintf(mess," >= %d",ilim); |
7fd59977 |
155 | def.AssignCat(mess); |
156 | } |
157 | if (IntegerLimit(Standard_True, ilim)) { |
91322f44 |
158 | Sprintf(mess," <= %d",ilim); |
7fd59977 |
159 | def.AssignCat(mess); |
160 | } |
161 | } |
162 | break; |
163 | case MoniTool_ValueReal : { |
164 | def.AssignCat("Real"); |
165 | Standard_Real rlim; |
166 | if (RealLimit(Standard_False, rlim)) { |
91322f44 |
167 | Sprintf(mess," >= %f",rlim); |
7fd59977 |
168 | def.AssignCat(mess); |
169 | } |
170 | if (RealLimit(Standard_True, rlim)) { |
91322f44 |
171 | Sprintf(mess," <= %f",rlim); |
7fd59977 |
172 | def.AssignCat(mess); |
173 | } |
174 | if (theunidef.Length() > 0) |
175 | { def.AssignCat(" Unit:"); def.AssignCat(UnitDef()); } |
176 | } |
177 | break; |
178 | case MoniTool_ValueEnum : { |
179 | def.AssignCat("Enum"); |
7c65581d |
180 | Standard_Integer startcase=0, endcase=0; |
181 | Standard_Boolean match=0; |
7fd59977 |
182 | EnumDef (startcase,endcase,match); |
91322f44 |
183 | Sprintf(mess," [%s%d-%d]",(match ? "in " : ""),startcase,endcase); |
7fd59977 |
184 | def.AssignCat(mess); |
185 | for (Standard_Integer i = startcase; i <= endcase; i ++) { |
186 | Standard_CString enva = EnumVal(i); |
187 | if (enva[0] == '?' || enva[0] == '\0') continue; |
91322f44 |
188 | Sprintf(mess," %d:%s",i,enva); |
7fd59977 |
189 | def.AssignCat (mess); |
190 | } |
997e128f |
191 | if (!theeadds.IsEmpty()) { |
192 | def.AssignCat(" , alpha: "); |
193 | NCollection_DataMap<TCollection_AsciiString, Standard_Integer>::Iterator listadd(theeadds); |
194 | for (; listadd.More(); listadd.Next()) { |
195 | TCollection_AsciiString aName = listadd.Key(); |
196 | Standard_CString enva = aName.ToCString(); |
197 | if (enva[0] == '?') continue; |
198 | Sprintf(mess,":%d ",listadd.Value()); |
199 | def.AssignCat (enva); |
200 | def.AssignCat (mess); |
201 | } |
7fd59977 |
202 | } |
203 | } |
204 | break; |
205 | case MoniTool_ValueIdent : { |
206 | def.AssignCat("Object(Entity)"); |
207 | if (!theotyp.IsNull()) { |
208 | def.AssignCat(":"); |
209 | def.AssignCat(theotyp->Name()); |
210 | } |
211 | } |
212 | break; |
213 | case MoniTool_ValueText : { |
214 | def.AssignCat("Text"); |
215 | if (themaxlen > 0) { |
91322f44 |
216 | Sprintf (mess," <= %d C.",themaxlen); |
7fd59977 |
217 | def.AssignCat (mess); |
218 | } |
219 | break; |
220 | } |
221 | default : def.AssignCat("(undefined)"); break; |
222 | } |
223 | return def; |
224 | } |
225 | |
226 | void MoniTool_TypedValue::SetDefinition (const Standard_CString deftext) |
227 | { thedef.Clear(); thedef.AssignCat(deftext); } |
228 | |
229 | // ## Print ## |
230 | |
231 | void MoniTool_TypedValue::Print (const Handle(Message_Messenger)& S) const |
232 | { |
233 | S<<"--- Typed Value : "<<Name(); |
234 | if (thelabel.Length() > 0) S<<" Label : "<<Label(); |
235 | S<<endl<<"--- Type : "<<Definition()<<endl<<"--- Value : "; |
236 | |
237 | PrintValue (S); |
238 | S<<endl; |
239 | |
240 | if (thesatisf) S<<" -- Specific Function for Satisfies : "<<thesatisn.ToCString()<<endl; |
241 | } |
242 | |
243 | |
244 | void MoniTool_TypedValue::PrintValue (const Handle(Message_Messenger)& S) const |
245 | { |
246 | if (IsSetValue()) { |
247 | if (thetype == MoniTool_ValueIdent) |
248 | S<<" (type) "<<theoval->DynamicType()->Name(); |
249 | if (!thehval.IsNull()) |
250 | S<<(thetype == MoniTool_ValueIdent ? " : " : "")<<thehval->ToCString(); |
251 | |
252 | if (HasInterpret()) { |
253 | S<<" ("; |
254 | Handle(TCollection_HAsciiString) str = Interpret (thehval,Standard_True); |
255 | if (!str.IsNull() && str != thehval) S<<"Native:"<<str->ToCString(); |
256 | str = Interpret (thehval,Standard_False); |
257 | if (!str.IsNull() && str != thehval) S<<" Coded:"<<str->ToCString(); |
258 | S<<")"; |
259 | } |
260 | } |
261 | else S<<"(not set)"; |
262 | } |
263 | |
264 | |
265 | // ######### COMPLEMENTS ########## |
266 | |
267 | Standard_Boolean MoniTool_TypedValue::AddDef |
268 | (const Standard_CString init) |
269 | { |
270 | // Editions : init donne un petit texte d edition, en 2 termes "cmd var" : |
271 | Standard_Integer i,iblc = 0; |
272 | for (i = 0; init[i] != '\0'; i ++) if (init[i] == ' ') iblc = i+1; |
273 | if (iblc == 0) return Standard_False; |
274 | // Reconnaissance du sous-cas et aiguillage |
275 | if (init[0] == 'i' && init[2] == 'i') // imin ival |
276 | SetIntegerLimit (Standard_False,atoi(&init[iblc])); |
277 | else if (init[0] == 'i' && init[2] == 'a') // imax ival |
278 | SetIntegerLimit (Standard_True ,atoi(&init[iblc])); |
279 | else if (init[0] == 'r' && init[2] == 'i') // rmin rval |
91322f44 |
280 | SetRealLimit (Standard_False,Atof(&init[iblc])); |
7fd59977 |
281 | else if (init[0] == 'r' && init[2] == 'a') // rmax rval |
91322f44 |
282 | SetRealLimit (Standard_True ,Atof(&init[iblc])); |
7fd59977 |
283 | else if (init[0] == 'u') // unit name |
284 | SetUnitDef (&init[iblc]); |
285 | else if (init[0] == 'e' && init[1] == 'm') // ematch istart |
286 | StartEnum (atoi(&init[iblc]),Standard_True); |
287 | else if (init[0] == 'e' && init[1] == 'n') // enum istart |
288 | StartEnum (atoi(&init[iblc]),Standard_False); |
289 | else if (init[0] == 'e' && init[1] == 'v') // eval text |
290 | AddEnum (&init[iblc]); |
291 | else if (init[0] == 't' && init[1] == 'm') // tmax length |
292 | SetMaxLength (atoi(&init[iblc])); |
293 | |
294 | else return Standard_False; |
295 | |
296 | return Standard_True; |
297 | } |
298 | |
299 | |
300 | void MoniTool_TypedValue::SetLabel (const Standard_CString label) |
301 | { thelabel.Clear(); thelabel.AssignCat (label); } |
302 | |
303 | Standard_CString MoniTool_TypedValue::Label () const |
304 | { return thelabel.ToCString(); } |
305 | |
306 | |
307 | |
308 | void MoniTool_TypedValue::SetMaxLength |
309 | (const Standard_Integer max) |
310 | { themaxlen = max; if (max < 0) themaxlen = 0; } |
311 | |
312 | Standard_Integer MoniTool_TypedValue::MaxLength () const |
313 | { return themaxlen; } |
314 | |
315 | void MoniTool_TypedValue::SetIntegerLimit |
316 | (const Standard_Boolean max, const Standard_Integer val) |
317 | { |
318 | if (thetype != MoniTool_ValueInteger) Standard_ConstructionError::Raise |
319 | ("MoniTool_TypedValue : SetIntegerLimit, not an Integer"); |
320 | |
321 | if (max) { thelims |= 2; theintup = val; } |
322 | else { thelims |= 1; theintlow = val; } |
323 | } |
324 | |
325 | Standard_Boolean MoniTool_TypedValue::IntegerLimit |
326 | (const Standard_Boolean max, Standard_Integer& val) const |
327 | { |
328 | Standard_Boolean res = Standard_False; |
329 | if (max) { res = (thelims & 2) != 0; val = (res ? theintup : IntegerLast()); } |
330 | else { res = (thelims & 1) != 0; val = (res ? theintlow : IntegerFirst()); } |
331 | return res; |
332 | } |
333 | |
334 | |
335 | void MoniTool_TypedValue::SetRealLimit |
336 | (const Standard_Boolean max, const Standard_Real val) |
337 | { |
338 | if (thetype != MoniTool_ValueReal) Standard_ConstructionError::Raise |
339 | ("MoniTool_TypedValue : SetRealLimit, not a Real"); |
340 | |
341 | if (max) { thelims |= 2; therealup = val; } |
342 | else { thelims |= 1; therealow = val; } |
343 | } |
344 | |
345 | Standard_Boolean MoniTool_TypedValue::RealLimit |
346 | (const Standard_Boolean max, Standard_Real& val) const |
347 | { |
348 | Standard_Boolean res = Standard_False; |
349 | if (max) { res = (thelims & 2) != 0; val = (res ? therealup : RealLast()); } |
350 | else { res = (thelims & 1) != 0; val = (res ? therealow : RealFirst()); } |
351 | return res; |
352 | } |
353 | |
354 | void MoniTool_TypedValue::SetUnitDef (const Standard_CString def) |
355 | { theunidef.Clear(); theunidef.AssignCat(def); } |
356 | |
357 | Standard_CString MoniTool_TypedValue::UnitDef () const |
358 | { return theunidef.ToCString(); } |
359 | |
360 | // ****** les enums ****** |
361 | |
362 | void MoniTool_TypedValue::StartEnum |
363 | (const Standard_Integer start, const Standard_Boolean match) |
364 | { |
365 | if (thetype != MoniTool_ValueEnum) Standard_ConstructionError::Raise |
366 | ("MoniTool_TypedValue : StartEnum, Not an Enum"); |
367 | |
368 | thelims |= 4; if (!match) thelims -= 4; |
369 | theintlow = start; theintup = start -1; |
370 | } |
371 | |
372 | void MoniTool_TypedValue::AddEnum |
373 | (const Standard_CString v1, const Standard_CString v2, |
374 | const Standard_CString v3, const Standard_CString v4, |
375 | const Standard_CString v5, const Standard_CString v6, |
376 | const Standard_CString v7, const Standard_CString v8, |
377 | const Standard_CString v9, const Standard_CString v10) |
378 | { |
379 | if (thetype != MoniTool_ValueEnum) Standard_ConstructionError::Raise |
380 | ("MoniTool_TypedValue : AddEnum, Not an Enum"); |
381 | if (theenums.IsNull()) theenums = |
382 | new TColStd_HArray1OfAsciiString(theintlow,theintlow+10); |
383 | else if (theenums->Upper() < theintup + 10) { |
384 | Handle(TColStd_HArray1OfAsciiString) enums = |
385 | new TColStd_HArray1OfAsciiString(theintlow,theintup+10); |
386 | for (Standard_Integer i = theintlow; i <= theintup; i ++) |
387 | enums->SetValue(i,theenums->Value(i)); |
388 | theenums = enums; |
389 | } |
390 | |
7fd59977 |
391 | if (v1[0] != '\0') { |
392 | theintup ++; theenums->SetValue(theintup,TCollection_AsciiString(v1)); |
997e128f |
393 | theeadds.Bind (v1,theintup); |
7fd59977 |
394 | } |
395 | if (v2[0] != '\0') { |
396 | theintup ++; theenums->SetValue(theintup,TCollection_AsciiString(v2)); |
997e128f |
397 | theeadds.Bind (v2,theintup); |
7fd59977 |
398 | } |
399 | if (v3[0] != '\0') { |
400 | theintup ++; theenums->SetValue(theintup,TCollection_AsciiString(v3)); |
997e128f |
401 | theeadds.Bind (v3,theintup); |
7fd59977 |
402 | } |
403 | if (v4[0] != '\0') { |
404 | theintup ++; theenums->SetValue(theintup,TCollection_AsciiString(v4)); |
997e128f |
405 | theeadds.Bind (v4,theintup); |
7fd59977 |
406 | } |
407 | if (v5[0] != '\0') { |
408 | theintup ++; theenums->SetValue(theintup,TCollection_AsciiString(v5)); |
997e128f |
409 | theeadds.Bind (v5,theintup); |
7fd59977 |
410 | } |
411 | if (v6[0] != '\0') { |
412 | theintup ++; theenums->SetValue(theintup,TCollection_AsciiString(v6)); |
997e128f |
413 | theeadds.Bind (v6,theintup); |
7fd59977 |
414 | } |
415 | if (v7[0] != '\0') { |
416 | theintup ++; theenums->SetValue(theintup,TCollection_AsciiString(v7)); |
997e128f |
417 | theeadds.Bind (v7,theintup); |
7fd59977 |
418 | } |
419 | if (v8[0] != '\0') { |
420 | theintup ++; theenums->SetValue(theintup,TCollection_AsciiString(v8)); |
997e128f |
421 | theeadds.Bind (v8,theintup); |
7fd59977 |
422 | } |
423 | if (v9[0] != '\0') { |
424 | theintup ++; theenums->SetValue(theintup,TCollection_AsciiString(v9)); |
997e128f |
425 | theeadds.Bind (v9,theintup); |
7fd59977 |
426 | } |
427 | if (v10[0] != '\0') { |
428 | theintup ++; theenums->SetValue(theintup,TCollection_AsciiString(v10)); |
997e128f |
429 | theeadds.Bind (v10,theintup); |
7fd59977 |
430 | } |
431 | } |
432 | |
433 | void MoniTool_TypedValue::AddEnumValue |
434 | (const Standard_CString val, const Standard_Integer num) |
435 | { |
436 | if (thetype != MoniTool_ValueEnum) Standard_ConstructionError::Raise |
437 | ("MoniTool_TypedValue : AddEnum, Not an Enum"); |
438 | if (num < theintlow) Standard_ConstructionError::Raise |
439 | ("MoniTool_TypedValue : AddEnum, out of range"); |
440 | if (val[0] == '\0') return; |
441 | if (theenums.IsNull()) theenums = |
442 | new TColStd_HArray1OfAsciiString(theintlow,num+1); |
443 | else if (theenums->Upper() < num) { |
444 | Handle(TColStd_HArray1OfAsciiString) enums = |
445 | new TColStd_HArray1OfAsciiString(theintlow,num+1); |
446 | for (Standard_Integer i = theintlow; i <= theintup; i ++) |
447 | enums->SetValue(i,theenums->Value(i)); |
448 | theenums = enums; |
449 | } |
450 | |
451 | if (theintup < num) theintup = num; |
452 | if (theenums->Value(num).Length() == 0) |
453 | theenums->SetValue(num,TCollection_AsciiString(val)); |
454 | // On met AUSSI dans le dictionnaire |
455 | // else { |
997e128f |
456 | theeadds.Bind (val,num); |
7fd59977 |
457 | // } |
458 | } |
459 | |
460 | Standard_Boolean MoniTool_TypedValue::EnumDef |
461 | (Standard_Integer& startcase, Standard_Integer& endcase, |
462 | Standard_Boolean& match) const |
463 | { |
464 | if (thetype != MoniTool_ValueEnum) return Standard_False; |
465 | startcase = theintlow; endcase = theintup; |
466 | match = ((thelims & 4) != 0); |
467 | return Standard_True; |
468 | } |
469 | |
470 | Standard_CString MoniTool_TypedValue::EnumVal |
471 | (const Standard_Integer num) const |
472 | { |
473 | if (thetype != MoniTool_ValueEnum) return ""; |
474 | if (num < theintlow || num > theintup) return ""; |
475 | return theenums->Value(num).ToCString(); |
476 | } |
477 | |
478 | Standard_Integer MoniTool_TypedValue::EnumCase |
479 | (const Standard_CString val) const |
480 | { |
481 | if (thetype != MoniTool_ValueEnum) return (theintlow - 1); |
482 | Standard_Integer i; // svv Jan 10 2000 : porting on DEC |
483 | for (i = theintlow; i <= theintup; i ++) |
484 | if (theenums->Value(i).IsEqual(val)) return i; |
485 | // cas additionnel ? |
997e128f |
486 | if (!theeadds.IsEmpty()) { |
487 | if (theeadds.Find(val,i)) return i; |
7fd59977 |
488 | } |
489 | // entier possible |
490 | //gka S4054 |
491 | for (i = 0; val[i] != '\0'; i ++) |
492 | if (val[i] != ' ' && val[i] != '-' && (val[i] < '0' || val[i] > '9' )) return (theintlow -1); |
493 | return atoi(val); |
494 | } |
495 | |
496 | // ****** object/entity ****** |
497 | |
498 | void MoniTool_TypedValue::SetObjectType |
499 | (const Handle(Standard_Type)& typ) |
500 | { |
501 | if (thetype != MoniTool_ValueIdent) Standard_ConstructionError::Raise |
502 | ("MoniTool_TypedValue : AddEnum, Not an Entity/Object"); |
503 | theotyp = typ; |
504 | } |
505 | |
506 | Handle(Standard_Type) MoniTool_TypedValue::ObjectType () const |
507 | { |
508 | if (!theotyp.IsNull()) return theotyp; |
509 | return STANDARD_TYPE(Standard_Transient); |
510 | } |
511 | |
512 | // ****** Specific Interpret/Satisfy ****** |
513 | |
514 | void MoniTool_TypedValue::SetInterpret |
515 | (const MoniTool_ValueInterpret func) |
516 | { theinterp = func; } |
517 | |
518 | Standard_Boolean MoniTool_TypedValue::HasInterpret () const |
519 | { |
520 | if (theinterp) return Standard_True; |
521 | if (thetype == MoniTool_ValueEnum) return Standard_True; |
522 | return Standard_False; |
523 | } |
524 | |
525 | void MoniTool_TypedValue::SetSatisfies |
526 | (const MoniTool_ValueSatisfies func, const Standard_CString name) |
527 | { |
528 | thesatisn.Clear(); |
529 | thesatisf = func; |
530 | if (thesatisf) thesatisn.AssignCat (name); |
531 | } |
532 | |
533 | Standard_CString MoniTool_TypedValue::SatisfiesName () const |
534 | { return thesatisn.ToCString(); } |
535 | |
536 | // ########### VALEUR DU STATIC ############ |
537 | |
538 | Standard_Boolean MoniTool_TypedValue::IsSetValue () const |
539 | { |
540 | if (thetype == MoniTool_ValueIdent) return (!theoval.IsNull()); |
541 | if (thehval->Length() > 0) return Standard_True; |
542 | if (!theoval.IsNull()) return Standard_True; |
543 | return Standard_False; |
544 | } |
545 | |
546 | Standard_CString MoniTool_TypedValue::CStringValue () const |
547 | { if (thehval.IsNull()) return ""; return thehval->ToCString(); } |
548 | |
549 | Handle(TCollection_HAsciiString) MoniTool_TypedValue::HStringValue () const |
550 | { return thehval; } |
551 | |
552 | Handle(TCollection_HAsciiString) MoniTool_TypedValue::Interpret |
553 | (const Handle(TCollection_HAsciiString)& hval, |
554 | const Standard_Boolean native) const |
555 | { |
556 | Handle(TCollection_HAsciiString) inter = hval; |
557 | if (hval.IsNull()) return hval; |
558 | if (theinterp) return theinterp (this,hval,native); |
559 | if (thetype == MoniTool_ValueEnum) { |
560 | // On admet les deux formes : Enum de preference, sinon Integer |
561 | Standard_Integer startcase, endcase; Standard_Boolean match; |
562 | EnumDef (startcase,endcase,match); |
563 | Standard_Integer encas = EnumCase (hval->ToCString()); |
564 | if (encas < startcase) return hval; // loupe |
565 | if (native) inter = new TCollection_HAsciiString (EnumVal(encas)); |
566 | else inter = new TCollection_HAsciiString (encas); |
567 | } |
568 | return inter; |
569 | } |
570 | |
571 | Standard_Boolean MoniTool_TypedValue::Satisfies |
572 | (const Handle(TCollection_HAsciiString)& val) const |
573 | { |
574 | if (val.IsNull()) return Standard_False; |
575 | if (thesatisf) |
576 | if (!thesatisf (val) ) return Standard_False; |
577 | if (val->Length() == 0) return Standard_True; |
578 | switch (thetype) { |
579 | case MoniTool_ValueInteger : { |
580 | if (!val->IsIntegerValue()) return Standard_False; |
581 | Standard_Integer ival, ilim; ival = atoi(val->ToCString()); |
582 | if (IntegerLimit(Standard_False, ilim)) |
583 | if (ilim > ival) return Standard_False; |
584 | if (IntegerLimit(Standard_True, ilim)) |
585 | if (ilim < ival) return Standard_False; |
586 | return Standard_True; |
587 | } |
588 | case MoniTool_ValueReal : { |
589 | if (!val->IsRealValue()) return Standard_False; |
590 | Standard_Real rval, rlim; rval = val->RealValue(); |
591 | if (RealLimit(Standard_False, rlim)) |
592 | if (rlim > rval) return Standard_False; |
593 | if (RealLimit(Standard_True, rlim)) |
594 | if (rlim < rval) return Standard_False; |
595 | return Standard_True; |
596 | } |
597 | case MoniTool_ValueEnum : { |
598 | // On admet les deux formes : Enum de preference, sinon Integer |
599 | Standard_Integer startcase, endcase;// unused ival; |
600 | Standard_Boolean match; |
601 | EnumDef (startcase,endcase,match); |
602 | if (!match) return Standard_True; |
603 | if (EnumCase (val->ToCString()) >= startcase) return Standard_True; |
604 | // Ici, on admet un entier dans la fourchette |
605 | //// if (val->IsIntegerValue()) ival = atoi (val->ToCString()); |
606 | |
607 | // PTV 16.09.2000 The if is comment, cause this check is never been done (You can see the logic) |
608 | // if (ival >= startcase && ival <= endcase) return Standard_True; |
609 | return Standard_False; |
610 | } |
611 | case MoniTool_ValueText : { |
612 | if (themaxlen > 0 && val->Length() > themaxlen) return Standard_False; |
613 | break; |
614 | } |
615 | default : break; |
616 | } |
617 | return Standard_True; |
618 | } |
619 | |
620 | void MoniTool_TypedValue::ClearValue () |
621 | { |
622 | thehval.Nullify(); |
623 | theoval.Nullify(); |
624 | theival = 0; |
625 | } |
626 | |
627 | Standard_Boolean MoniTool_TypedValue::SetCStringValue |
628 | (const Standard_CString val) |
629 | { |
630 | Handle(TCollection_HAsciiString) hval = new TCollection_HAsciiString(val); |
631 | if (hval->IsSameString (thehval)) return Standard_True; |
632 | if (!Satisfies(hval)) return Standard_False; |
633 | if (thetype == MoniTool_ValueInteger) { |
634 | thehval->Clear(); |
635 | theival = atoi(val); |
636 | thehval->AssignCat(val); |
637 | } |
638 | else if (thetype == MoniTool_ValueEnum) { |
639 | Standard_Integer ival = EnumCase(val); |
640 | Standard_CString cval = EnumVal(ival); |
641 | if (!cval || cval[0] == '\0') return Standard_False; |
642 | theival = ival; |
643 | thehval->Clear(); |
644 | thehval->AssignCat(cval); |
645 | } else { |
646 | thehval->Clear(); |
647 | thehval->AssignCat(val); |
648 | return Standard_True; |
649 | } |
650 | return Standard_True; |
651 | } |
652 | |
653 | Standard_Boolean MoniTool_TypedValue::SetHStringValue |
654 | (const Handle(TCollection_HAsciiString)& hval) |
655 | { |
656 | if (hval.IsNull()) return Standard_False; |
657 | if (!Satisfies(hval)) return Standard_False; |
658 | thehval = hval; |
659 | if (thetype == MoniTool_ValueInteger) theival = atoi(hval->ToCString()); |
660 | else if (thetype == MoniTool_ValueEnum) theival = EnumCase(hval->ToCString()); |
661 | // else return Standard_True; |
662 | return Standard_True; |
663 | } |
664 | |
665 | Standard_Integer MoniTool_TypedValue::IntegerValue () const |
666 | { return theival; } |
667 | |
668 | Standard_Boolean MoniTool_TypedValue::SetIntegerValue |
669 | (const Standard_Integer ival) |
670 | { |
671 | Handle(TCollection_HAsciiString) hval = new TCollection_HAsciiString(ival); |
672 | if (hval->IsSameString (thehval)) return Standard_True; |
673 | if (!Satisfies(hval)) return Standard_False; |
674 | thehval->Clear(); |
675 | if (thetype == MoniTool_ValueEnum) thehval->AssignCat (EnumVal(ival)); |
676 | else thehval->AssignCat (hval->ToCString()); |
677 | theival = ival; |
678 | return Standard_True; |
679 | } |
680 | |
681 | Standard_Real MoniTool_TypedValue::RealValue () const |
682 | { |
683 | if (thehval->Length() == 0) return 0.0; |
684 | if (!thehval->IsRealValue()) return 0.0; |
685 | return thehval->RealValue(); |
686 | } |
687 | |
688 | Standard_Boolean MoniTool_TypedValue::SetRealValue (const Standard_Real rval) |
689 | { |
690 | Handle(TCollection_HAsciiString) hval = new TCollection_HAsciiString(rval); |
691 | if (hval->IsSameString (thehval)) return Standard_True; |
692 | if (!Satisfies(hval)) return Standard_False; |
693 | thehval->Clear(); thehval->AssignCat (hval->ToCString()); |
694 | return Standard_True; |
695 | } |
696 | |
697 | Handle(Standard_Transient) MoniTool_TypedValue::ObjectValue () const |
698 | { return theoval; } |
699 | |
700 | void MoniTool_TypedValue::GetObjectValue (Handle(Standard_Transient)& val) const |
701 | { val = theoval; } |
702 | |
703 | Standard_Boolean MoniTool_TypedValue::SetObjectValue |
704 | (const Handle(Standard_Transient)& obj) |
705 | { |
706 | if (thetype != MoniTool_ValueIdent) return Standard_False; |
707 | if (obj.IsNull()) { theoval.Nullify(); return Standard_True; } |
708 | if (!theotyp.IsNull()) |
709 | if (!obj->IsKind(theotyp)) return Standard_False; |
710 | theoval = obj; |
711 | return Standard_True; |
712 | } |
713 | |
714 | |
715 | Standard_CString MoniTool_TypedValue::ObjectTypeName () const |
716 | { |
717 | if (theoval.IsNull()) return ""; |
718 | Handle(MoniTool_Element) elm = Handle(MoniTool_Element)::DownCast(theoval); |
719 | if (!elm.IsNull()) return elm->ValueTypeName(); |
720 | return theoval->DynamicType()->Name(); |
721 | } |
722 | |
723 | |
724 | // ######## LIBRARY ######## |
725 | |
726 | Standard_Boolean MoniTool_TypedValue::AddLib |
727 | (const Handle(MoniTool_TypedValue)& tv, const Standard_CString defin) |
728 | { |
729 | if (tv.IsNull()) return Standard_False; |
730 | if (defin[0] != '\0') tv->SetDefinition(defin); |
731 | // else if (tv->Definition() == '\0') return Standard_False; |
997e128f |
732 | libtv().Bind(tv->Name(),tv); |
7fd59977 |
733 | return Standard_True; |
734 | } |
735 | |
736 | Handle(MoniTool_TypedValue) MoniTool_TypedValue::Lib |
737 | (const Standard_CString defin) |
738 | { |
739 | Handle(MoniTool_TypedValue) val; |
997e128f |
740 | Handle(Standard_Transient) aTVal; |
741 | if (libtv().Find(defin, aTVal)) |
742 | val = Handle(MoniTool_TypedValue)::DownCast(aTVal); |
743 | else |
744 | val.Nullify(); |
7fd59977 |
745 | return val; |
746 | } |
747 | |
748 | Handle(MoniTool_TypedValue) MoniTool_TypedValue::FromLib |
749 | (const Standard_CString defin) |
750 | { |
751 | Handle(MoniTool_TypedValue) val = MoniTool_TypedValue::Lib(defin); |
752 | if (!val.IsNull()) val = new MoniTool_TypedValue (val); |
753 | return val; |
754 | } |
755 | |
756 | Handle(TColStd_HSequenceOfAsciiString) MoniTool_TypedValue::LibList () |
757 | { |
758 | Handle(TColStd_HSequenceOfAsciiString) list = new TColStd_HSequenceOfAsciiString(); |
997e128f |
759 | if (libtv().IsEmpty()) return list; |
760 | NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)>::Iterator it(libtv()); |
761 | for (; it.More();it.Next()) { |
762 | list->Append (it.Key()); |
7fd59977 |
763 | } |
764 | return list; |
765 | } |
766 | |
997e128f |
767 | NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)>& MoniTool_TypedValue::Stats () |
7fd59977 |
768 | { |
7fd59977 |
769 | return astats; |
770 | } |
771 | |
772 | Handle(MoniTool_TypedValue) MoniTool_TypedValue::StaticValue |
773 | (const Standard_CString name) |
774 | { |
775 | Handle(MoniTool_TypedValue) result; |
997e128f |
776 | Handle(Standard_Transient) aTResult; |
777 | if (Stats().Find(name, aTResult)) |
778 | result = Handle(MoniTool_TypedValue)::DownCast(aTResult); |
779 | else |
780 | result.Nullify(); |
7fd59977 |
781 | return result; |
782 | } |