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"
31 extern BufferList bufferlist;
35 text_fits(Buffer * b, unsigned short p)
37 bool operator()(TextCache::value_type & vt) {
38 if (vt->buffer == buf && vt->paperWidth() == pw) return true;
47 LyXText * TextCache::findFit(Buffer * b, unsigned short p)
49 Cache::iterator it = find_if(cache.begin(), cache.end(),
51 if (it != cache.end()) {
52 LyXText * tmp = (*it);
62 show_text(ostream & o) : os(o) {}
63 void operator()(TextCache::value_type & vt) {
64 os << "\tBuffer: " << vt->buffer
65 << "\tWidth: " << vt->paperWidth() << endl;
71 void TextCache::show(ostream & os, string const & str)
73 os << "TextCache: " << str << endl;
74 for_each(cache.begin(), cache.end(), show_text(os));
78 void TextCache::show(ostream & os, LyXText * lt)
85 void TextCache::add(LyXText * text)
87 lyxerr.debug() << "TextCache::add " << text;
88 if (bufferlist.isLoaded(text->buffer)) {
89 cache.push_back(text);
90 lyxerr.debug() << " added" << endl;
93 lyxerr.debug() << " deleted" << endl;
100 void operator()(TextCache::value_type & vt) {
106 void TextCache::clear()
108 for_each(cache.begin(), cache.end(), delete_text());
115 has_buffer(Buffer * b)
117 bool operator()(TextCache::value_type & vt) {
118 if (vt->buffer == buf) return true;
126 void TextCache::removeAllWithBuffer(Buffer * buf)
128 Cache::iterator it = remove_if(cache.begin(), cache.end(),
130 if (it != cache.end()) {
131 if (lyxerr.debugging()) {
132 lyxerr.debug() << "TextCache::removeAllWithbuffer "
134 for_each(it, cache.end(), show_text(lyxerr));
137 for_each(it, cache.end(), delete_text());
138 cache.erase(it, cache.end());