1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
5 * Copyright 1995 Matthias Ettrich
6 * Copyright 1995-2000 The LyX Team
8 * This file is Copyright 2000
11 * ====================================================== */
16 #pragma implementation
21 #include "TextCache.h"
23 #include "bufferlist.h"
30 extern BufferList bufferlist;
34 text_fits(Buffer * b, unsigned short p)
36 bool operator()(TextCache::value_type & vt) {
37 if (vt->params == buf && vt->paperWidth() == pw) return true;
46 LyXText * TextCache::findFit(Buffer * b, unsigned short p)
48 Cache::iterator it = find_if(cache.begin(), cache.end(),
50 if (it != cache.end()) {
51 LyXText * tmp = (*it);
61 show_text(ostream & o) : os(o) {}
62 void operator()(TextCache::value_type & vt) {
63 os << "\tBuffer: " << vt->params
64 << "\tWidth: " << vt->paperWidth() << endl;
70 void TextCache::show(ostream & os, string const & str)
72 os << "TextCache: " << str << endl;
73 for_each(cache.begin(), cache.end(), show_text(os));
77 void TextCache::show(ostream & os, LyXText * lt)
84 void TextCache::add(LyXText * text)
86 lyxerr.debug() << "TextCache::add " << text;
87 if (bufferlist.isLoaded(text->params)) {
88 cache.push_back(text);
89 lyxerr.debug() << " added" << endl;
92 lyxerr.debug() << " deleted" << endl;
99 void operator()(TextCache::value_type & vt) {
105 void TextCache::clear()
107 for_each(cache.begin(), cache.end(), delete_text());
114 has_buffer(Buffer * b)
116 bool operator()(TextCache::value_type & vt) {
117 if (vt->params == buf) return true;
125 void TextCache::removeAllWithBuffer(Buffer * buf)
127 Cache::iterator it = remove_if(cache.begin(), cache.end(),
129 if (it != cache.end()) {
130 if (lyxerr.debugging()) {
131 lyxerr.debug() << "TextCache::removeAllWithbuffer "
133 for_each(it, cache.end(), show_text(lyxerr));
136 for_each(it, cache.end(), delete_text());
137 cache.erase(it, cache.end());