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
22 using std::ostream_iterator;
27 #include "support/FileInfo.h"
28 #include "lastfiles.h"
31 LastFiles::LastFiles(string const & filename, bool st, unsigned int num)
34 setNumberOfFiles(num);
39 void LastFiles::setNumberOfFiles(unsigned int no)
41 if (0 < no && no <= ABSOLUTEMAXLASTFILES)
44 lyxerr << "LyX: lastfiles: too many files\n"
45 "\tdefault (=" << int(DEFAULTFILES)
47 num_files = DEFAULTFILES;
52 void LastFiles::readFile(string const & filename)
54 // we will not complain if we can't find filename nor will
55 // we issue a warning. (Lgb)
56 ifstream ifs(filename.c_str());
60 while(getline(ifs, tmp) && files.size() < num_files) {
62 if (!(fileInfo.newFile(tmp).exist() &&
63 fileInfo.isRegular()))
71 void LastFiles::writeFile(string const & filename) const
73 ofstream ofs(filename.c_str());
76 for (Files::const_iterator cit = files.begin();
79 ofs << (*cit) << '\n';
82 // Ok, ok. It is not required to do it this way...but it
83 // is kindo nice and shows the versiality of iterators and
84 // algorithms. I'll leave this in, and if I get reports
85 // about compilations errors I take it out again before
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())