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"
29 extern BufferList bufferlist;
33 text_fits(Buffer * b, unsigned short p)
35 bool operator()(TextCache::value_type & vt) {
36 if (vt->params == buf && vt->paperWidth() == pw) return true;
45 LyXText * TextCache::findFit(Buffer * b, unsigned short p)
47 Cache::iterator it = find_if(cache.begin(), cache.end(),
49 if (it != cache.end()) {
50 LyXText * tmp = (*it);
60 show_text(ostream & o) : os(o) {}
61 void operator()(TextCache::value_type & vt) {
62 os << "\tBuffer: " << vt->params
63 << "\tWidth: " << vt->paperWidth() << endl;
69 void TextCache::show(ostream & os, string const & str)
71 os << "TextCache: " << str << endl;
72 for_each(cache.begin(), cache.end(), show_text(os));
76 void TextCache::show(ostream & os, LyXText const * lt)
79 st(const_cast<LyXText*>(lt));
83 void TextCache::add(LyXText * text)
85 lyxerr.debug() << "TextCache::add " << text;
86 if (bufferlist.isLoaded(text->params)) {
87 cache.push_back(text);
88 lyxerr.debug() << " added" << endl;
91 lyxerr.debug() << " deleted" << endl;
98 void operator()(TextCache::value_type & vt) {
104 void TextCache::clear()
106 for_each(cache.begin(), cache.end(), delete_text());
113 has_buffer(Buffer * b)
115 bool operator()(TextCache::value_type & vt) {
116 if (vt->params == buf) return true;
124 void TextCache::removeAllWithBuffer(Buffer * buf)
126 Cache::iterator it = remove_if(cache.begin(), cache.end(),
128 if (it != cache.end()) {
129 if (lyxerr.debugging()) {
130 lyxerr.debug() << "TextCache::removeAllWithbuffer "
132 for_each(it, cache.end(), show_text(lyxerr));
135 for_each(it, cache.end(), delete_text());
136 cache.erase(it, cache.end());