1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
5 * Copyright 1995 Matthias Ettrich
6 * Copyright 1995-2001 The LyX Team
8 * This file is Copyright 2000-2001
11 * ====================================================== */
16 #pragma implementation
21 #include "TextCache.h"
23 #include "bufferlist.h"
32 extern BufferList bufferlist;
38 text_fits(Buffer * b, int p)
40 bool operator()(TextCache::value_type const & vt) const {
41 if (vt.first == buf && vt.second.first == pw)
53 show_text(ostream & o) : os(o) {}
54 void operator()(TextCache::value_type const & vt) {
55 os << "\tBuffer: " << vt.first
56 << "\tWidth: " << vt.second.first << endl;
65 void operator()(TextCache::value_type & vt) {
66 delete vt.second.second;
73 LyXText * TextCache::findFit(Buffer * b, int p)
75 Cache::iterator it = find_if(cache.begin(), cache.end(),
77 if (it != cache.end()) {
78 LyXText * tmp = (*it).second.second;
86 void TextCache::show(ostream & os, string const & str)
88 os << "TextCache: " << str << endl;
89 for_each(cache.begin(), cache.end(), show_text(os));
93 void TextCache::show(ostream & os, TextCache::value_type const & vt)
100 void TextCache::add(Buffer * buf, int workwidth, LyXText * text)
102 lyxerr.debug() << "TextCache::add " << text;
103 if (bufferlist.isLoaded(buf)) {
104 cache[buf] = make_pair(workwidth, text);
105 lyxerr.debug() << " added" << endl;
108 lyxerr.debug() << " deleted" << endl;
113 void TextCache::clear()
115 for_each(cache.begin(), cache.end(), delete_text());
120 void TextCache::removeAllWithBuffer(Buffer * buf)