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