]> git.lyx.org Git - lyx.git/blobdiff - src/TextCache.C
fix typo that put too many include paths for most people
[lyx.git] / src / TextCache.C
index 0b5be6340e0e35874ddbbe265039683c9d90230a..31f97029f08e170bebeb43cca037eeccd2fb2868 100644 (file)
@@ -1,11 +1,11 @@
 /* This file is part of
- * ====================================================== 
- * 
- *           LyX, The Document Processor        
+ * ======================================================
+ *
+ *           LyX, The Document Processor
  *           Copyright 1995 Matthias Ettrich
- *           Copyright 1995-2000 The LyX Team
+ *           Copyright 1995-2001 The LyX Team
  *
- *           This file is Copyright 2000
+ *           This file is Copyright 2000-2001
  *           Lars Gullik Bjønnes
  *
  * ====================================================== */
 #pragma implementation
 #endif
 
-#include <algorithm>
-
 #include "TextCache.h"
 #include "buffer.h"
 #include "bufferlist.h"
+#include "debug.h"
+
+#include <algorithm>
 
 using std::ostream;
 using std::for_each;
 using std::remove_if;
 using std::find_if;
 using std::endl;
+using std::make_pair;
 
 extern BufferList bufferlist;
 
+namespace {
+
 class text_fits {
 public:
-       text_fits(Buffer * b, unsigned short p)
+       text_fits(Buffer * b, int p)
                : buf(b), pw(p) {}
-       bool operator()(TextCache::value_type & vt) {
-               if (vt->params == buf && vt->paperWidth() == pw) return true;
+       bool operator()(TextCache::value_type const & vt) const {
+               if (vt.first == buf && vt.second.first == pw)
+                       return true;
                return false;
        }
 private:
        Buffer * buf;
-       unsigned short pw;
+       int pw;
 };
 
 
-LyXText * TextCache::findFit(Buffer * b, unsigned short p)
+class show_text {
+public:
+       show_text(ostream & o) : os(o) {}
+       void operator()(TextCache::value_type const & vt) {
+               os << "\tBuffer: " << vt.first
+                  << "\tWidth: " << vt.second.first << endl;
+       }
+private:
+       ostream & os;
+};
+
+
+class delete_text {
+public:
+       void operator()(TextCache::value_type & vt) {
+               delete vt.second.second;
+       }
+};
+
+} // namespace anon
+
+
+LyXText * TextCache::findFit(Buffer * b, int p)
 {
        Cache::iterator it = find_if(cache.begin(), cache.end(),
                                     text_fits(b, p));
        if (it != cache.end()) {
-               LyXText * tmp = (*it);
+               LyXText * tmp = it->second.second;
                cache.erase(it);
                return tmp;
        }
@@ -57,17 +84,6 @@ LyXText * TextCache::findFit(Buffer * b, unsigned short p)
 }
 
 
-class show_text {
-public:
-       show_text(ostream & o) : os(o) {}
-       void operator()(TextCache::value_type & vt) {
-               os << "\tBuffer: " << vt->params
-                  << "\tWidth: " << vt->paperWidth() << endl;
-       }
-private:
-       ostream & os;
-};
-
 void TextCache::show(ostream & os, string const & str)
 {
        os << "TextCache: " << str << endl;
@@ -75,34 +91,26 @@ void TextCache::show(ostream & os, string const & str)
 }
 
 
-void TextCache::show(ostream & os, LyXText * lt)
+void TextCache::show(ostream & os, TextCache::value_type const & vt)
 {
        show_text st(os);
-       st(lt);
+       st(vt);
 }
 
 
-void TextCache::add(LyXText * text)
+void TextCache::add(Buffer * buf, int workwidth, LyXText * text)
 {
-       lyxerr.debug() << "TextCache::add " << text;
-       if (bufferlist.isLoaded(text->params)) {
-               cache.push_back(text);
-               lyxerr.debug() << " added" << endl;
+       lyxerr[Debug::INFO] << "TextCache::add " << text;
+       if (bufferlist.isLoaded(buf)) {
+               cache[buf] = make_pair(workwidth, text);
+               lyxerr[Debug::INFO] << " added" << endl;
        } else {
                delete text;
-               lyxerr.debug() << " deleted" << endl;
+               lyxerr[Debug::INFO] << " deleted" << endl;
        }
 }
 
 
-class delete_text {
-public:
-       void operator()(TextCache::value_type & vt) {
-               delete vt;
-       }
-};
-
-
 void TextCache::clear()
 {
        for_each(cache.begin(), cache.end(), delete_text());
@@ -110,33 +118,9 @@ void TextCache::clear()
 }
 
 
-class has_buffer {
-public:
-       has_buffer(Buffer * b)
-               : buf(b) {}
-       bool operator()(TextCache::value_type & vt) {
-               if (vt->params == buf) return true;
-               return false;
-       }
-private:
-       Buffer * buf;
-};
-
-
 void TextCache::removeAllWithBuffer(Buffer * buf)
 {
-       Cache::iterator it = remove_if(cache.begin(), cache.end(),
-                                      has_buffer(buf));
-       if (it != cache.end()) {
-               if (lyxerr.debugging()) {
-                       lyxerr.debug() << "TextCache::removeAllWithbuffer "
-                               "Removing:\n";
-                       for_each(it, cache.end(), show_text(lyxerr));
-                       lyxerr << endl;
-               }
-               for_each(it, cache.end(), delete_text());
-               cache.erase(it, cache.end());
-       }
+       cache.erase(buf);
 }
 
 // Global instance