1 // Created on: 1992-06-24
2 // Created by: Gilles DEBARBOUILLE
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
21 // CRD : 03/07/97 : Porting Windows NT.
23 #include <Standard_Stream.hxx>
25 #include <Dynamic_FuzzyDefinitionsDictionary.ixx>
26 #include <Dynamic_FuzzyDefinition.hxx>
27 #include <Dynamic_BooleanParameter.hxx>
28 #include <Dynamic_IntegerParameter.hxx>
29 #include <Dynamic_RealParameter.hxx>
30 #include <Dynamic_StringParameter.hxx>
31 #include <Dynamic_ObjectParameter.hxx>
32 #include <Dynamic_InstanceParameter.hxx>
33 #include <TCollection_AsciiString.hxx>
41 #ifdef HAVE_SYS_TYPES_H
42 # include <sys/types.h>
45 #if defined (HAVE_SYS_STAT_H) || defined (WNT)
46 # include <sys/stat.h>
54 //#define strcasecmp _stricoll
58 //=======================================================================
59 //function : Dynamic_FuzzyDefinitionsDictionary
61 //=======================================================================
63 Dynamic_FuzzyDefinitionsDictionary::Dynamic_FuzzyDefinitionsDictionary()
67 //=======================================================================
70 //=======================================================================
72 void Dynamic_FuzzyDefinitionsDictionary::Creates(const Standard_CString afilename)
74 Standard_Integer fr,i,begin,end,endline;
78 char value[80],value1[80],value2[80],value3[80];
79 Handle(Dynamic_FuzzyDefinition) fuzzydefinition;
80 Handle(Dynamic_Parameter) parameter;
84 ifstream file(afilename);
87 cout<<"unable to open "<<afilename<<" for input"<<endl;
91 thefilename = new TCollection_HAsciiString(afilename);
93 if(!stat(afilename,&buf)) thetime = buf.st_ctime;
95 thesequenceoffuzzydefinitions = new Dynamic_SequenceOfFuzzyDefinitions();
99 for(i=0; i<255; i++) line[i] = 0;
101 file.getline(line,255);
105 while( i >= 0 && ( line[i] == ' ' || !line[i]))line[i--] = 0;
111 fuzzydefinition = new Dynamic_FuzzyDefinition(line);
112 thesequenceoffuzzydefinitions->Append(fuzzydefinition);
133 for(i=0; i<80; i++)name[i]=0;
136 for(i=begin+1; i<=end-1; i++)name[endline++] = line[i];
138 for(i=0; i<80; i++)type [i] = 0;
139 for(i=0; i<80; i++)value [i] = 0;
140 for(i=0; i<80; i++)value1 [i] = 0;
141 for(i=0; i<80; i++)value2 [i] = 0;
142 for(i=0; i<80; i++)value3 [i] = 0;
144 // fr = sscanf(&line[end+1],"%s%80c",&type,&value);
145 fr = sscanf(&line[end+1],"%s%80c",type,value);
146 if(fr == -1) continue;
157 for(i=begin; i<80; i++) value[i-begin] = value[i];
158 for(i=80-begin; i<80; i++) value[i] = 0;
160 if (!strcasecmp(type,"Standard_Boolean"))
161 fuzzydefinition->Parameter(new Dynamic_BooleanParameter(name,value));
163 else if(!strcasecmp(type,"Standard_Integer"))
164 fuzzydefinition->Parameter(new Dynamic_IntegerParameter(name,atoi(value)));
166 else if(!strcasecmp(type,"Standard_Real"))
167 fuzzydefinition->Parameter(new Dynamic_RealParameter(name,Atof(value)));
169 else if(!strcasecmp(type,"Standard_CString"))
170 fuzzydefinition->Parameter(new Dynamic_StringParameter(name,value));
174 parameter = Switch(name,type,value);
175 if(!parameter.IsNull())fuzzydefinition->Parameter(parameter);
183 //=======================================================================
184 //function : Definition
186 //=======================================================================
188 Standard_Boolean Dynamic_FuzzyDefinitionsDictionary::Definition
189 (const Standard_CString atype,
190 Handle(Dynamic_FuzzyClass)& adefinition) const
192 Handle(Dynamic_FuzzyClass) definition;
194 for(Standard_Integer index=1; index<=thesequenceoffuzzydefinitions->Length(); index++)
196 definition = thesequenceoffuzzydefinitions->Value(index);
197 if(definition->Type() == atype)
199 adefinition = definition;
200 return Standard_True;
203 return Standard_False;
206 //=======================================================================
209 //=======================================================================
211 Handle(Dynamic_Parameter) Dynamic_FuzzyDefinitionsDictionary::Switch(
212 const Standard_CString aname,
213 const Standard_CString atype,
214 const Standard_CString avalue) const
216 Handle(Dynamic_ObjectParameter) objectparameter;
217 cout<<"Parameter "<<aname<<" of type "<<atype<<" with "<<avalue<<" does not exist."<<endl;
218 return objectparameter;
221 //=======================================================================
222 //function : UpToDate
224 //=======================================================================
226 Standard_Boolean Dynamic_FuzzyDefinitionsDictionary::UpToDate() const
230 TCollection_AsciiString string = thefilename->String();
231 if(!stat(string.ToCString(),&buf))
233 if(thetime == buf.st_ctime) return Standard_True;
236 return Standard_False;
239 //=======================================================================
240 //function : NumberOfDefinitions
242 //=======================================================================
244 Standard_Integer Dynamic_FuzzyDefinitionsDictionary::NumberOfDefinitions() const
246 return thesequenceoffuzzydefinitions->Length();
249 //=======================================================================
250 //function : Definition
252 //=======================================================================
254 Handle(Dynamic_FuzzyClass) Dynamic_FuzzyDefinitionsDictionary::Definition
255 (const Standard_Integer anindex) const
257 return thesequenceoffuzzydefinitions->Value(anindex);
260 //=======================================================================
263 //=======================================================================
265 void Dynamic_FuzzyDefinitionsDictionary::Dump(Standard_OStream& astream) const
267 Standard_Integer index;
268 astream<<" DICTIONARY : /n";
269 for(index=1;index<=thesequenceoffuzzydefinitions->Length();index++)
270 thesequenceoffuzzydefinitions->Value(index)->Dump(astream);