]> git.lyx.org Git - lyx.git/blob - src/DepTable.C
95978313517968c4332b5b4cb04a0186e66f57ea
[lyx.git] / src / DepTable.C
1 /* This file is part of
2  * ====================================================== 
3  * 
4  *           LyX, The Document Processor
5  *           Copyright (C) 1995 Matthias Ettrich
6  *           Copyright (C) 1995-1998 The LyX Team.
7  *
8  *           This file is Copyright (C) 1996-1998
9  *           Lars Gullik Bjønnes
10  *
11  * ====================================================== 
12  */
13
14 #include <config.h>
15
16 #ifdef __GNUG__
17 #pragma implementation
18 #endif
19
20 #include "DepTable.h"
21 #include "support/lyxlib.h"
22 #include "support/filetools.h"
23 #include <fstream>
24 using std::make_pair;
25 using std::ofstream;
26 using std::ifstream;
27
28 void DepTable::insert(string const & fi,
29                       bool upd,
30                       unsigned long one,
31                       unsigned long two)
32 {
33         // not quite sure if this is the correct place for MakeAbsPath
34         string f = MakeAbsPath(fi);
35         if (deplist.find(f) == deplist.end()) {
36                 if (upd) {
37                         one = two;
38                         two = lyx::sum(f.c_str());
39                 }
40                 deplist[f] = make_pair(one, two);
41         }
42 }
43                 
44
45 void DepTable::update()
46 {
47         for(DepList::iterator itr = deplist.begin();
48             itr != deplist.end();
49             ++itr) {
50                 unsigned long one = (*itr).second.second;
51                 unsigned long two = lyx::sum((*itr).first.c_str());
52                 (*itr).second = make_pair(one, two);
53                 if (lyxerr.debugging()) {
54                         lyxerr << "update: " << (*itr).first << " "
55                                << one << " " << two << endl;
56                 }
57         }
58 }
59
60
61 bool DepTable::sumchange() const
62 {
63         for (DepList::const_iterator cit = deplist.begin();
64              cit != deplist.end();
65              ++cit) {
66                 if ((*cit).second.first != (*cit).second.second) return true;
67         }
68         return false;
69 }
70
71
72 bool DepTable::haschanged(string const & f) const
73 {
74         // not quite sure if this is the correct place for MakeAbsPath
75         string fil = MakeAbsPath(f);
76         DepList::const_iterator cit = deplist.find(fil);
77         if (cit != deplist.end()) {
78                 if ((*cit).second.first != (*cit).second.second
79                     && (*cit).second.second != 0)
80                         return true;
81         }
82         return false;
83 }
84
85
86 bool DepTable::extchanged(string const & ext) const
87 {
88         for (DepList::const_iterator cit = deplist.begin();
89              cit != deplist.end();
90              ++cit) {
91                 if (suffixIs((*cit).first, ext.c_str())) {
92                         if ((*cit).second.first != (*cit).second.second)
93                                 return true;
94                 }
95         }
96                      
97         return false;
98 }
99
100
101 bool DepTable::exist(string const & fil) const
102 {
103         DepList::const_iterator cit = deplist.find(fil);
104         if (cit != deplist.end()) return true;
105         return false;
106 }
107
108
109 void DepTable::remove_files_with_extension(string const & suf)
110 {
111         DepList tmp;
112         for (DepList::const_iterator cit = deplist.begin();
113              cit != deplist.end(); ++cit) {
114                 if (!suffixIs((*cit).first, suf.c_str()))
115                         tmp[(*cit).first] = (*cit).second;
116         }
117         deplist.swap(tmp);
118         
119 }
120
121
122 void DepTable::write(string const & f) const
123 {
124         ofstream ofs(f.c_str());
125         for (DepList::const_iterator cit = deplist.begin();
126              cit != deplist.end();
127              ++cit) {
128                 if (lyxerr.debugging()) {
129                         lyxerr << "Write dep: "
130                                << (*cit).first << " "
131                                << (*cit).second.first << " "
132                                << (*cit).second.second << endl;
133                 }
134                 ofs << (*cit).first << " "
135                     << (*cit).second.first << " "
136                     << (*cit).second.second << endl;
137         }
138 }
139
140
141 void DepTable::read(string const & f)
142 {
143         ifstream ifs(f.c_str());
144         string nome;
145         unsigned long one = 0;
146         unsigned long two = 0;
147         while(ifs >> nome >> one >> two) {
148                 if (lyxerr.debugging()) {
149                         lyxerr << "read dep: "
150                                << nome << " "
151                                << one << " "
152                                << two << endl;
153                 }
154                 deplist[nome] = make_pair(one, two);
155         }
156 }