1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
15 #pragma implementation
21 #include "support/FileInfo.h"
22 #include "lastfiles.h"
29 using std::ostream_iterator;
33 LastFiles::LastFiles(string const & filename, bool st, unsigned int num)
36 setNumberOfFiles(num);
41 void LastFiles::setNumberOfFiles(unsigned int no)
43 if (0 < no && no <= ABSOLUTEMAXLASTFILES)
46 lyxerr << "LyX: lastfiles: too many files\n"
47 "\tdefault (=" << int(DEFAULTFILES)
49 num_files = DEFAULTFILES;
54 void LastFiles::readFile(string const & filename)
56 // we will not complain if we can't find filename nor will
57 // we issue a warning. (Lgb)
58 ifstream ifs(filename.c_str());
62 while(getline(ifs, tmp) && files.size() < num_files) {
64 if (!(fileInfo.newFile(tmp).exist() &&
65 fileInfo.isRegular()))
73 void LastFiles::writeFile(string const & filename) const
75 ofstream ofs(filename.c_str());
77 copy(files.begin(), files.end(),
78 ostream_iterator<string>(ofs, "\n"));
80 lyxerr << "LyX: Warning: unable to save LastFiles: "
85 void LastFiles::newFile(string const & file)
87 // If file already exist, delete it and reinsert at front.
88 Files::iterator it = find(files.begin(), files.end(), file);
89 if (it != files.end())
91 files.push_front(file);
92 if (files.size() > num_files)
97 string const LastFiles::operator[](unsigned int i) const