0023996: Width 50 given in format string (no. 2) is larger than destination buffer...
[occt.git] / src / Interface / Interface_Static.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 <Interface_Static.ixx>
19
20#include <Dico_DictionaryOfInteger.hxx>
21#include <Dico_DictionaryOfTransient.hxx>
22#include <Dico_IteratorOfDictionaryOfTransient.hxx>
23#include <Dico_IteratorOfDictionaryOfInteger.hxx>
24
25#include <OSD_Path.hxx>
26#include <stdio.h>
27
d0e4e578 28static char defmess[31];
7fd59977 29
30// Fonctions Satisfies offertes en standard ...
31
32//svv #2
33//static Standard_Boolean StaticPath(const Handle(TCollection_HAsciiString)& val)
34//{
35// OSD_Path apath;
36// return apath.IsValid (TCollection_AsciiString(val->ToCString()));
37//}
38
39
40 Interface_Static::Interface_Static
41 (const Standard_CString family, const Standard_CString name,
42 const Interface_ParamType type, const Standard_CString init)
43 : Interface_TypedValue (name,type,init) ,
44 thefamily (family) ,
45 theupdate (Standard_True) { }
46
47 Interface_Static::Interface_Static
48 (const Standard_CString family, const Standard_CString name,
49 const Handle(Interface_Static)& other)
50 : Interface_TypedValue (name, other->Type(), "") ,
51 thefamily (family) ,
52 theupdate (Standard_True)
53{
54 switch (Type()) {
55 case Interface_ParamInteger : {
56 Standard_Integer lim;
57 if (other->IntegerLimit (Standard_True ,lim)) SetIntegerLimit (Standard_True ,lim);
58 if (other->IntegerLimit (Standard_False,lim)) SetIntegerLimit (Standard_False,lim);
59 }
60 break;
61 case Interface_ParamReal : {
62 Standard_Real lim;
63 if (other->RealLimit (Standard_True ,lim)) SetRealLimit (Standard_True ,lim);
64 if (other->RealLimit (Standard_False,lim)) SetRealLimit (Standard_False,lim);
65 SetUnitDef (other->UnitDef());
66 }
67 break;
68 case Interface_ParamEnum : {
69 Standard_Boolean match; Standard_Integer e0,e1,i;
70 other->EnumDef (e0,e1,match);
71 StartEnum (e0,match);
72// if (e1 >= e0) theenums = new TColStd_HArray1OfAsciiString(e0,e1);
73 for (i = e0; i <= e1; i ++)
74 AddEnum (other->EnumVal(i));
75 }
76 break;
77 case Interface_ParamIdent :
78 SetObjectType (other->ObjectType());
79 break;
80 default : break;
81 }
82
83 if (other->IsSetValue()) SetCStringValue (other->CStringValue());
84}
85
86
87// ## Print ##
88
89void Interface_Static::PrintStatic (const Handle(Message_Messenger)& S) const
90{
91 S<<"--- Static Value : "<<Name()<<" Family:"<<Family();
92 Print (S);
93 if (!thewild.IsNull())
94 S<<" -- Attached to wild-card : "<<thewild->Name()<<endl;
95 S<<"--- Actual status : "<<(theupdate ? "" : "original")<<" Value : ";
96
97 if (thesatisf) S<<" -- Specific Function for Satisfies : "<<thesatisn.ToCString()<<endl;
98}
99
100
101// ######### COMPLEMENTS ##########
102
103Standard_CString Interface_Static::Family () const
104{
105 return thefamily.ToCString();
106}
107
108
109Handle(Interface_Static) Interface_Static::Wild () const
110{
111 return thewild;
112}
113
114
115void Interface_Static::SetWild (const Handle(Interface_Static)& wild)
116{
117 thewild = wild;
118}
119
120
121// ######### UPDATE ##########
122
123void Interface_Static::SetUptodate ()
124{
125 theupdate = Standard_True;
126}
127
128
129Standard_Boolean Interface_Static::UpdatedStatus () const
130{
131 return theupdate;
132}
133
134
135
136// #######################################################################
137// ######### DICTIONNAIRE DES STATICS (static sur Static) ##########
138
139Standard_Boolean Interface_Static::Init
140 (const Standard_CString family, const Standard_CString name,
141 const Interface_ParamType type, const Standard_CString init)
142{
143 if (name[0] == '\0') return Standard_False;
144
145 if (MoniTool_TypedValue::Stats()->HasItem(name)) return Standard_False;
146 Handle(Interface_Static) item;
147 if (type == Interface_ParamMisc) {
148 Handle(Interface_Static) other = Interface_Static::Static(init);
149 if (other.IsNull()) return Standard_False;
150 item = new Interface_Static (family,name,other);
151 }
152 else item = new Interface_Static (family,name,type,init);
153
154 MoniTool_TypedValue::Stats()->SetItem (name,item);
155 return Standard_True;
156}
157
158
159Standard_Boolean Interface_Static::Init
160 (const Standard_CString family, const Standard_CString name,
161 const Standard_Character type, const Standard_CString init)
162{
163 Interface_ParamType epyt;
164 switch (type) {
165 case 'e' : epyt = Interface_ParamEnum; break;
166 case 'i' : epyt = Interface_ParamInteger; break;
167 case 'o' : epyt = Interface_ParamIdent; break;
168 case 'p' : epyt = Interface_ParamText; break;
169 case 'r' : epyt = Interface_ParamReal; break;
170 case 't' : epyt = Interface_ParamText; break;
171 case '=' : epyt = Interface_ParamMisc; break;
172 case '&' : {
173 Handle(Interface_Static) unstat = Interface_Static::Static(name);
174 if (unstat.IsNull()) return Standard_False;
175// Editions : init donne un petit texte d edition, en 2 termes "cmd var" :
176// imin <ival> imax <ival> rmin <rval> rmax <rval> unit <def>
177// enum <from> ematch <from> eval <cval>
178 Standard_Integer i,iblc = 0;
179 for (i = 0; init[i] != '\0'; i ++) if (init[i] == ' ') iblc = i+1;
180// Reconnaissance du sous-cas et aiguillage
181 if (init[0] == 'i' && init[2] == 'i')
182 unstat->SetIntegerLimit (Standard_False,atoi(&init[iblc]));
183 else if (init[0] == 'i' && init[2] == 'a')
184 unstat->SetIntegerLimit (Standard_True ,atoi(&init[iblc]));
185 else if (init[0] == 'r' && init[2] == 'i')
91322f44 186 unstat->SetRealLimit (Standard_False,Atof(&init[iblc]));
7fd59977 187 else if (init[0] == 'r' && init[2] == 'a')
91322f44 188 unstat->SetRealLimit (Standard_True ,Atof(&init[iblc]));
7fd59977 189 else if (init[0] == 'u')
190 unstat->SetUnitDef (&init[iblc]);
191 else if (init[0] == 'e' && init[1] == 'm')
192 unstat->StartEnum (atoi(&init[iblc]),Standard_True);
193 else if (init[0] == 'e' && init[1] == 'n')
194 unstat->StartEnum (atoi(&init[iblc]),Standard_False);
195 else if (init[0] == 'e' && init[1] == 'v')
196 unstat->AddEnum (&init[iblc]);
197 else return Standard_False;
198 return Standard_True;
199 }
200 default : return Standard_False;
201 }
202 if (!Interface_Static::Init (family,name,epyt,init)) return Standard_False;
203 if (type != 'p') return Standard_True;
204 Handle(Interface_Static) stat = Interface_Static::Static(name);
205//NT stat->SetSatisfies (StaticPath,"Path");
206 if (!stat->Satisfies(stat->HStringValue())) stat->SetCStringValue("");
207 return Standard_True;
208}
209
210
211Handle(Interface_Static) Interface_Static::Static
212 (const Standard_CString name)
213{
214 Handle(Interface_Static) result;
215 MoniTool_TypedValue::Stats()->GetItem (name,result);
216 return result;
217}
218
219
220Standard_Boolean Interface_Static::IsPresent (const Standard_CString name)
221{
222 return MoniTool_TypedValue::Stats()->HasItem (name);
223}
224
225
226Standard_CString Interface_Static::CDef
227 (const Standard_CString name, const Standard_CString part)
228{
229 if (!part || part[0] == '\0') return "";
230 Handle(Interface_Static) stat = Interface_Static::Static(name);
231 if (stat.IsNull()) return "";
232 if (part[0] == 'f' && part[1] == 'a') return stat->Family();
233 if (part[0] == 'l' && part[1] == 'a') return stat->Label();
234 if (part[0] == 's' && part[1] == 'a') return stat->SatisfiesName();
235 if (part[0] == 't' && part[1] == 'y') {
236 Interface_ParamType typ = stat->Type();
237 if (typ == Interface_ParamInteger) return "integer";
238 if (typ == Interface_ParamReal) return "real";
239 if (typ == Interface_ParamText) return "text";
240 if (typ == Interface_ParamEnum) return "enum";
241 return "?type?";
242 }
243 if (part[0] == 'e') {
244 Standard_Integer nume = 0;
d0e4e578 245 sscanf (part,"%30s %d",defmess,&nume);
7fd59977 246 return stat->EnumVal(nume);
247 }
248 if (part[0] == 'i') {
249 Standard_Integer ilim;
250 if (!stat->IntegerLimit((part[2] == 'a'),ilim)) return "";
d0e4e578 251 Sprintf(defmess,"%d",ilim); return defmess;
7fd59977 252 }
253 if (part[0] == 'r') {
254 Standard_Real rlim;
255 if (!stat->RealLimit((part[2] == 'a'),rlim)) return "";
d0e4e578 256 Sprintf(defmess,"%f",rlim); return defmess;
7fd59977 257 }
258 if (part[0] == 'u') return stat->UnitDef();
259 return "";
260}
261
262
263Standard_Integer Interface_Static::IDef
264 (const Standard_CString name, const Standard_CString part)
265{
266 if (!part || part[0] == '\0') return 0;
267 Handle(Interface_Static) stat = Interface_Static::Static(name);
268 if (stat.IsNull()) return 0;
269 if (part[0] == 'i') {
270 Standard_Integer ilim;
271 if (!stat->IntegerLimit((part[2] == 'a'),ilim)) return 0;
272 return ilim;
273 }
274 if (part[0] == 'e') {
275 Standard_Integer startcase,endcase; Standard_Boolean match;
276 stat->EnumDef (startcase,endcase,match);
277 if (part[1] == 's') return startcase;
278 if (part[1] == 'c') return (endcase - startcase + 1);
279 if (part[1] == 'm') return (match ? 1 : 0);
280 if (part[1] == 'v') {
20b1ae2c 281 char vale[51];
d0e4e578 282 sscanf (part,"%30s %50s",defmess,vale);
7fd59977 283 return stat->EnumCase (vale);
284 }
285 }
286 return 0;
287}
288
289
290// ########## VALEUR COURANTE ###########
291
292Standard_Boolean Interface_Static::IsSet
293 (const Standard_CString name, const Standard_Boolean proper)
294{
295 Handle(Interface_Static) item = Interface_Static::Static(name);
296 if (item.IsNull()) return Standard_False;
297 if (item->IsSetValue()) return Standard_True;
298 if (proper) return Standard_False;
299 item = item->Wild();
300 return item->IsSetValue();
301}
302
303
304Standard_CString Interface_Static::CVal (const Standard_CString name)
305{
306 Handle(Interface_Static) item = Interface_Static::Static(name);
307 if (item.IsNull()) {
308#ifdef DEB
309 cout << "Warning: Interface_Static::CVal: incorrect parameter " << name << endl;
310#endif
311 return "";
312 }
313 return item->CStringValue();
314}
315
316
317Standard_Integer Interface_Static::IVal (const Standard_CString name)
318{
319 Handle(Interface_Static) item = Interface_Static::Static(name);
320 if (item.IsNull()) {
321#ifdef DEB
322 cout << "Warning: Interface_Static::IVal: incorrect parameter " << name << endl;
323#endif
324 return 0;
325 }
326 return item->IntegerValue();
327}
328
329
330Standard_Real Interface_Static::RVal (const Standard_CString name)
331{
332 Handle(Interface_Static) item = Interface_Static::Static(name);
333 if (item.IsNull()) {
334#ifdef DEB
335 cout << "Warning: Interface_Static::RVal: incorrect parameter " << name << endl;
336#endif
337 return 0.0;
338 }
339 return item->RealValue();
340}
341
342
343Standard_Boolean Interface_Static::SetCVal
344 (const Standard_CString name, const Standard_CString val)
345{
346 Handle(Interface_Static) item = Interface_Static::Static(name);
347 if (item.IsNull()) return Standard_False;
348 return item->SetCStringValue(val);
349}
350
351
352Standard_Boolean Interface_Static::SetIVal
353 (const Standard_CString name, const Standard_Integer val)
354{
355 Handle(Interface_Static) item = Interface_Static::Static(name);
356 if (item.IsNull()) return Standard_False;
357 if (!item->SetIntegerValue(val)) return Standard_False;
358 return Standard_True;
359}
360
361
362Standard_Boolean Interface_Static::SetRVal
363 (const Standard_CString name, const Standard_Real val)
364{
365 Handle(Interface_Static) item = Interface_Static::Static(name);
366 if (item.IsNull()) return Standard_False;
367 return item->SetRealValue(val);
368}
369
370// UPDATE
371
372Standard_Boolean Interface_Static::Update (const Standard_CString name)
373{
374 Handle(Interface_Static) item = Interface_Static::Static(name);
375 if (item.IsNull()) return Standard_False;
376 item->SetUptodate();
377 return Standard_True;
378}
379
380Standard_Boolean Interface_Static::IsUpdated (const Standard_CString name)
381{
382 Handle(Interface_Static) item = Interface_Static::Static(name);
383 if (item.IsNull()) return Standard_False;
384 return item->UpdatedStatus();
385}
386
387Handle(TColStd_HSequenceOfHAsciiString) Interface_Static::Items
388 (const Standard_Integer mode, const Standard_CString criter)
389{
390 Standard_Integer modup = (mode / 100); // 0 any, 1 non-update, 2 update
391 Handle(TColStd_HSequenceOfHAsciiString) list =
392 new TColStd_HSequenceOfHAsciiString();
393 Dico_IteratorOfDictionaryOfTransient iter(MoniTool_TypedValue::Stats());
394 for (iter.Start(); iter.More(); iter.Next()) {
395 Handle(Interface_Static) item =
396 Handle(Interface_Static)::DownCast(iter.Value());
397 if (item.IsNull()) continue;
398 Standard_Boolean ok = Standard_True;
399 if (criter[0] == '$' && criter[1] == '\0') {
400 if ( (item->Family())[0] != '$') ok = Standard_False;
401 } else if (criter[0] != '\0') {
402 if (strcmp(criter, item->Family())) continue;
403 ok = Standard_True;
404 } else { // tous ... sauf famille a $
405 if (item->Family()[0] == '$') continue;
406 }
407 if (ok && (modup == 1)) ok = !item->UpdatedStatus();
408 if (ok && (modup == 2)) ok = item->UpdatedStatus();
409
410 if (ok) list->Append (new TCollection_HAsciiString (iter.Name()) );
411 }
412 return list;
413}