a53d4c68db0ef51d97d2c35a12b930982c100e58
[occt.git] / src / Units / Units_UnitsLexicon.cxx
1 // Created on: 1993-10-08
2 // Created by: Gilles DEBARBOUILLE
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <Units_UnitsLexicon.ixx>
18 #include <Units.hxx>
19 #include <Units_UnitsDictionary.hxx>
20 #include <Units_Token.hxx>
21 #include <TCollection_AsciiString.hxx>
22
23 #include <sys/types.h>
24 #include <sys/stat.h>
25
26 //=======================================================================
27 //function : Units_UnitsLexicon
28 //purpose  : 
29 //=======================================================================
30
31 Units_UnitsLexicon::Units_UnitsLexicon() : Units_Lexicon()
32 {}
33
34 //=======================================================================
35 //function : Creates
36 //purpose  : 
37 //=======================================================================
38
39 void Units_UnitsLexicon::Creates(const Standard_CString afilename1,
40                                  const Standard_CString afilename2,
41                                  const Standard_Boolean amode)
42 {
43   Handle(Units_UnitsDictionary) unitsdictionary;
44   struct stat buf;
45
46   thefilename = new TCollection_HAsciiString(afilename2);
47
48   if(!stat(afilename2,&buf)) thetime = buf.st_ctime;
49
50   Units_Lexicon::Creates(afilename1);
51
52   if(amode)unitsdictionary = Units::DictionaryOfUnits(amode);
53
54 }
55
56 //=======================================================================
57 //function : UpToDate
58 //purpose  : 
59 //=======================================================================
60
61 Standard_Boolean Units_UnitsLexicon::UpToDate() const
62 {
63   struct stat buf;
64   TCollection_AsciiString string = FileName2();
65
66   if(Units_Lexicon::UpToDate())
67     {
68       if(!stat(string.ToCString(),&buf))
69         {
70           if(thetime >= buf.st_ctime) return Standard_True;
71         }
72     }
73
74   return Standard_False;
75 }
76
77 //=======================================================================
78 //function : FileName2
79 //purpose  : 
80 //=======================================================================
81
82 TCollection_AsciiString Units_UnitsLexicon::FileName2() const
83 {
84   return thefilename->String();
85 }