1 // Created on: 1992-06-24
2 // Created by: Gilles DEBARBOUILLE
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 // CRD : 15/04/97 : Passage WOK++ : Replace TYPE by STANDARD_TYPE
19 // CRD : 03/07/97 : Porting Windows NT.
21 #include <Standard_Stream.hxx>
23 #include <Dynamic_MethodDefinitionsDictionary.ixx>
24 #include <Dynamic.hxx>
25 #include <Dynamic_CompiledMethod.hxx>
26 #include <Dynamic_BooleanParameter.hxx>
27 #include <Dynamic_IntegerParameter.hxx>
28 #include <Dynamic_RealParameter.hxx>
29 #include <Dynamic_StringParameter.hxx>
30 #include <Dynamic_ObjectParameter.hxx>
31 #include <Dynamic_InstanceParameter.hxx>
32 #include <TCollection_AsciiString.hxx>
39 #ifdef HAVE_SYS_TYPES_H
40 # include <sys/types.h>
43 #if defined (HAVE_SYS_STAT_H) || defined (WNT)
44 # include <sys/stat.h>
52 //#define strcasecmp _stricoll
55 //=======================================================================
56 //function : Dynamic_MethodDefinitionsDictionary
58 //=======================================================================
60 Dynamic_MethodDefinitionsDictionary::Dynamic_MethodDefinitionsDictionary()
64 //=======================================================================
67 //=======================================================================
69 void Dynamic_MethodDefinitionsDictionary::Creates(const Standard_CString afilename)
71 Standard_Boolean group;
72 Standard_Integer fr,i,begin,end,endline;
77 char value[81],value1[81],value2[81],value3[81];
78 Handle(Dynamic_CompiledMethod) methoddefinition;
79 Handle(Dynamic_Parameter) parameter;
83 ifstream file(afilename);
86 cout<<"unable to open "<<afilename<<" for input"<<endl;
90 thefilename = new TCollection_HAsciiString(afilename);
92 if(!stat(afilename,&buf)) thetime = buf.st_ctime;
94 thesequenceofmethoddefinitions = new Dynamic_SequenceOfMethodDefinitions();
98 memset(line,0,sizeof(line));
100 file.getline(line,255);
104 while( i >= 0 && ( line[i] == ' ' || !line[i]))line[i--] = 0;
110 methoddefinition = new Dynamic_CompiledMethod(line,line);
111 thesequenceofmethoddefinitions->Append(methoddefinition);
132 memset(name,0,sizeof(name));
135 for(i=begin+1; i<=end-1; i++)name[endline++] = line[i];
137 memset(mode, 0x00,sizeof(mode));
138 memset(type, 0x00,sizeof(type));
139 memset(value, 0x00,sizeof(value));
140 memset(value1,0x00,sizeof(value1));
141 memset(value2,0x00,sizeof(value2));
142 memset(value3,0x00,sizeof(value3));
144 fr = sscanf(&line[end+1],"%80s%80s%80c",mode,type,value);
145 if(fr == -1) continue;
147 group = Standard_False;
150 group = Standard_True;
151 for(i=1; i<80; i++)type[i-1] = type[i];
163 for(i=begin; i<80; i++) value[i-begin] = value[i];
164 for(i=80-begin; i<80; i++) value[i] = 0;
166 if (!strcasecmp(type,"Standard_Boolean"))
167 methoddefinition->AddVariable(new Dynamic_BooleanParameter(name,value),Dynamic::Mode(mode),group);
169 else if(!strcasecmp(type,"Standard_Integer"))
170 methoddefinition->AddVariable(new Dynamic_IntegerParameter(name,atoi(value)),Dynamic::Mode(mode),group);
172 else if(!strcasecmp(type,"Standard_Real"))
173 methoddefinition->AddVariable(new Dynamic_RealParameter(name,Atof(value)),Dynamic::Mode(mode),group);
175 else if(!strcasecmp(type,"Standard_CString"))
176 methoddefinition->AddVariable(new Dynamic_StringParameter(name,value),Dynamic::Mode(mode),group);
180 parameter = Switch(name,type,value);
181 if(!parameter.IsNull())methoddefinition->AddVariable(parameter,Dynamic::Mode(mode),group);
189 //=======================================================================
190 //function : Definition
192 //=======================================================================
194 Standard_Boolean Dynamic_MethodDefinitionsDictionary::Definition(const Handle(Dynamic_Method)& adefinition)
196 Handle(Dynamic_MethodDefinition) methoddefinition;
197 if(adefinition->IsKind(STANDARD_TYPE(Dynamic_MethodDefinition)))
199 methoddefinition = *(Handle(Dynamic_MethodDefinition)*)&adefinition;
200 thesequenceofmethoddefinitions->Append(methoddefinition);
201 return Standard_True;
205 cout<<"the definition is not a method definition"<<endl;
206 return Standard_False;
210 //=======================================================================
211 //function : Definition
213 //=======================================================================
215 Standard_Boolean Dynamic_MethodDefinitionsDictionary::Definition
216 (const Standard_CString atype,
217 Handle(Dynamic_Method)& adefinition) const
219 Handle(Dynamic_Method) definition;
221 for(Standard_Integer index=1; index<=thesequenceofmethoddefinitions->Length(); index++)
223 definition = thesequenceofmethoddefinitions->Value(index);
224 if(definition->Type() == atype)
226 adefinition = definition;
227 return Standard_True;
230 return Standard_False;
233 //=======================================================================
236 //=======================================================================
238 Handle(Dynamic_Parameter) Dynamic_MethodDefinitionsDictionary::Switch(
239 const Standard_CString aname,
240 const Standard_CString atype,
241 const Standard_CString avalue) const
243 Handle(Dynamic_ObjectParameter) objectparameter;
244 cout<<"Parameter "<<aname<<" of type "<<atype<<" with "<<avalue<<" does not exist."<<endl;
245 return objectparameter;
248 //=======================================================================
249 //function : UpToDate
251 //=======================================================================
253 Standard_Boolean Dynamic_MethodDefinitionsDictionary::UpToDate() const
257 TCollection_AsciiString string = thefilename->String();
258 if(!stat(string.ToCString(),&buf))
260 if(thetime == buf.st_ctime) return Standard_True;
263 return Standard_False;
266 //=======================================================================
267 //function : NumberOfDefinitions
269 //=======================================================================
271 Standard_Integer Dynamic_MethodDefinitionsDictionary::NumberOfDefinitions() const
273 return thesequenceofmethoddefinitions->Length();
276 //=======================================================================
277 //function : Definition
279 //=======================================================================
281 Handle(Dynamic_Method) Dynamic_MethodDefinitionsDictionary::Definition
282 (const Standard_Integer anindex) const
284 return thesequenceofmethoddefinitions->Value(anindex);
287 //=======================================================================
290 //=======================================================================
292 void Dynamic_MethodDefinitionsDictionary::Dump(Standard_OStream& astream) const
294 Standard_Integer index;
295 astream<<" DICTIONARY : \n\n";
296 for(index=1;index<=thesequenceofmethoddefinitions->Length();index++)
297 thesequenceofmethoddefinitions->Value(index)->Dump(astream);