3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * Full author contact details are available in file CREDITS.
13 #include "lastfiles.h"
16 #include <boost/filesystem/operations.hpp>
22 namespace fs = boost::filesystem;
31 using std::ostream_iterator;
34 LastFiles::LastFiles(string const & filename, bool st, unsigned int num)
37 setNumberOfFiles(num);
42 void LastFiles::setNumberOfFiles(unsigned int no)
44 if (0 < no && no <= ABSOLUTEMAXLASTFILES)
47 lyxerr << "LyX: lastfiles: too many files\n"
48 "\tdefault (=" << int(DEFAULTFILES)
50 num_files = DEFAULTFILES;
55 void LastFiles::readFile(string const & filename)
57 // we will not complain if we can't find filename nor will
58 // we issue a warning. (Lgb)
59 ifstream ifs(filename.c_str());
62 while (getline(ifs, tmp) && files.size() < num_files) {
63 if (dostat && !fs::exists(tmp))
70 void LastFiles::writeFile(string const & filename) const
72 ofstream ofs(filename.c_str());
74 copy(files.begin(), files.end(),
75 ostream_iterator<string>(ofs, "\n"));
77 lyxerr << "LyX: Warning: unable to save LastFiles: "
82 void LastFiles::newFile(string const & file)
84 // If file already exist, delete it and reinsert at front.
85 Files::iterator it = find(files.begin(), files.end(), file);
86 if (it != files.end())
88 files.push_front(file);
89 if (files.size() > num_files)
94 string const LastFiles::operator[](unsigned int i) const