This commit was manufactured by cvs2svn to create tag
[lyx.git] / src / DepTable.C
blobdd15f5d042899b9346379dde09e745cbbade70fb
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  */
14 #include <config.h>
16 #ifdef __GNUG__
17 #pragma implementation
18 #endif
20 #include "DepTable.h"
21 #include "support/lyxlib.h"
22 #include "support/filetools.h"
23 #include <fstream>
25 void DepTable::insert(string const & fi,
26                       bool upd,
27                       unsigned long one,
28                       unsigned long two)
30         // not quite sure if this is the correct place for MakeAbsPath
31         string f = MakeAbsPath(fi);
32         if (deplist.find(f) == deplist.end()) {
33                 if (upd) {
34                         one = two;
35                         two = lyxsum(f.c_str());
36                 }
37                 deplist[f] = make_pair(one, two);
38         }
40                 
42 void DepTable::update()
44         for(DepList::iterator itr = deplist.begin();
45             itr != deplist.end();
46             ++itr) {
47                 unsigned long one = (*itr).second.second;
48                 unsigned long two = lyxsum((*itr).first.c_str());
49                 (*itr).second = make_pair(one, two);
50                 if (lyxerr.debugging()) {
51                         lyxerr << "update: " << (*itr).first << " "
52                                << one << " " << two << endl;
53                 }
54         }
58 bool DepTable::sumchange()
60         for (DepList::const_iterator cit = deplist.begin();
61              cit != deplist.end();
62              ++cit) {
63                 if ((*cit).second.first != (*cit).second.second) return true;
64         }
65         return false;
69 bool DepTable::haschanged(string const & f)
71         // not quite sure if this is the correct place for MakeAbsPath
72         string fil = MakeAbsPath(f);
73         DepList::const_iterator cit = deplist.find(fil);
74         if (cit != deplist.end()) {
75                 if ((*cit).second.first != (*cit).second.second
76                     && (*cit).second.second != 0)
77                         return true;
78         }
79         return false;
83 bool DepTable::extchanged(string const & ext)
85         for (DepList::const_iterator cit = deplist.begin();
86              cit != deplist.end();
87              ++cit) {
88                 if (suffixIs((*cit).first, ext.c_str())) {
89                         if ((*cit).second.first != (*cit).second.second)
90                                 return true;
91                 }
92         }
93                      
94         return false;
98 void DepTable::write(string const & f)
100         ofstream ofs(f.c_str());
101         for (DepList::const_iterator cit = deplist.begin();
102              cit != deplist.end();
103              ++cit) {
104                 if (lyxerr.debugging()) {
105                         lyxerr << "Write dep: "
106                                << (*cit).first << " "
107                                << (*cit).second.first << " "
108                                << (*cit).second.second << endl;
109                 }
110                 ofs << (*cit).first << " "
111                     << (*cit).second.first << " "
112                     << (*cit).second.second << endl;
113         }
116 void DepTable::read(string const &f)
118         ifstream ifs(f.c_str());
119         string nome;
120         unsigned long one = 0;
121         unsigned long two = 0;
122         while(ifs >> nome >> one >> two) {
123                 if (lyxerr.debugging()) {
124                         lyxerr << "read dep: "
125                                << nome << " "
126                                << one << " "
127                                << two << endl;
128                 }
129                 deplist[nome] = make_pair(one, two);
130         }