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