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