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