]> git.lyx.org Git - lyx.git/blob - src/DepTable.C
white-space changes, removed definitions.h several enum changes because of this,...
[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 = lyxsum(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 = lyxsum((*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()
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)
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)
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 void DepTable::write(string const & f)
102 {
103         ofstream ofs(f.c_str());
104         for (DepList::const_iterator cit = deplist.begin();
105              cit != deplist.end();
106              ++cit) {
107                 if (lyxerr.debugging()) {
108                         lyxerr << "Write dep: "
109                                << (*cit).first << " "
110                                << (*cit).second.first << " "
111                                << (*cit).second.second << endl;
112                 }
113                 ofs << (*cit).first << " "
114                     << (*cit).second.first << " "
115                     << (*cit).second.second << endl;
116         }
117 }
118
119 void DepTable::read(string const &f)
120 {
121         ifstream ifs(f.c_str());
122         string nome;
123         unsigned long one = 0;
124         unsigned long two = 0;
125         while(ifs >> nome >> one >> two) {
126                 if (lyxerr.debugging()) {
127                         lyxerr << "read dep: "
128                                << nome << " "
129                                << one << " "
130                                << two << endl;
131                 }
132                 deplist[nome] = make_pair(one, two);
133         }
134 }