1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 The LyX Team.
9 * ====================================================== */
15 #pragma implementation
25 #include "support/FileInfo.h"
26 #include "lastfiles.h"
29 LastFiles::LastFiles(string const & filename, bool st, unsigned int num)
32 setNumberOfFiles(num);
37 void LastFiles::setNumberOfFiles(unsigned int no)
39 if (0 < no && no <= ABSOLUTEMAXLASTFILES)
42 lyxerr << "LyX: lastfiles: too many files\n"
43 "\tdefault (=" << int(DEFAULTFILES)
45 num_files = DEFAULTFILES;
50 void LastFiles::readFile(string const & filename)
52 // we will not complain if we can't find filename nor will
53 // we issue a warning. (Lgb)
54 ifstream ifs(filename.c_str());
58 while(getline(ifs, tmp) && files.size() < num_files) {
60 if (!(fileInfo.newFile(tmp).exist() &&
61 fileInfo.isRegular()))
69 void LastFiles::writeFile(string const & filename) const
71 ofstream ofs(filename.c_str());
74 for (Files::const_iterator cit = files.begin();
77 ofs << (*cit) << '\n';
80 // Ok, ok. It is not required to do it this way...but it
81 // is kindo nice and shows the versiality of iterators and
82 // algorithms. I'll leave this in, and if I get reports
83 // about compilations errors I take it out again before
86 using std::ostream_iterator;
87 copy(files.begin(), files.end(),
88 ostream_iterator<string>(ofs, "\n"));
91 lyxerr << "LyX: Warning: unable to save LastFiles: "
96 void LastFiles::newFile(string const & file)
98 // If file already exist, delete it and reinsert at front.
99 Files::iterator it = find(files.begin(), files.end(), file);
100 if (it != files.end())
102 files.push_front(file);
103 if (files.size() > num_files)
108 string LastFiles::operator[](unsigned int i) const
110 if (i < files.size())