]> git.lyx.org Git - lyx.git/blobdiff - src/coordcache.C
* src/tabular.[Ch]: simplify plaintext methods, because there
[lyx.git] / src / coordcache.C
index 11e5a8db3ee51eb691388aac5ff2c007dc76f546..b55b296ef13b4adc000914b06f43c6fa0d84de83 100644 (file)
@@ -1,24 +1,88 @@
+/* \file coordcache.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author André Pönitz
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
 
 #include "coordcache.h"
 #include "debug.h"
 
-CoordCache theCoords;
+#include "lyxtext.h"
+
+#include "insets/insetbase.h"
+
+#include <boost/assert.hpp>
+
+
+namespace lyx {
+
+Point::Point(int x, int y)
+       : x_(x), y_(y)
+{
+       BOOST_ASSERT(x > -1000000);
+       BOOST_ASSERT(x <  1000000);
+       BOOST_ASSERT(y > -1000000);
+       BOOST_ASSERT(y <  1000000);
+}
 
 // just a helper to be able to set a breakpoint
 void lyxbreaker(void const * data, const char * hint, int size)
 {
        lyxerr << "break on pointer: " << data << " hint: " << hint
                << " size: " << size << std::endl;
+       BOOST_ASSERT(false);
 }
 
 
 void CoordCache::clear()
 {
-//     lyxerr << "CoordCache: removing " << arrays_.data_.size()
-//             << " arrays" << std::endl;
-//     lyxerr << "CoordCache: removing " << insets_.data_.size()
-//             << " insets" << std::endl;
        arrays_.clear();
        insets_.clear();
+       pars_.clear();
+       slices0_.clear();
+       slices1_.clear();
+}
+
+
+Point CoordCache::get(LyXText const * text, pit_type pit) const
+{
+       ParPosCache::const_iterator const it = pars_.find(text);
+       BOOST_ASSERT(it != pars_.end());
+       InnerParPosCache::const_iterator const posit = it->second.find(pit);
+       BOOST_ASSERT(posit != it->second.end());
+       return posit->second;
+}
+
+void
+CoordCache::dump() const {
+       lyxerr << "ParPosCache contains:" << std::endl;
+       for (ParPosCache::const_iterator i = getParPos().begin(); i != getParPos().end(); ++i) {
+               LyXText const * lt = (*i).first;
+               InnerParPosCache const & cache = (*i).second;
+               lyxerr << "LyXText:" << lt << std::endl;
+               for (InnerParPosCache::const_iterator j = cache.begin(); j != cache.end(); ++j) {
+                       pit_type pit = (*j).first;
+                       Paragraph const & par = lt->getPar(pit);
+                       Point p = (*j).second;
+                       lyxerr << "Paragraph " << pit << ": \"";
+                       for (int k = 0; k < std::min(static_cast<lyx::pos_type>(10), par.size()); ++k) {
+                               lyxerr << to_utf8(docstring(1,par.getChar(k)));
+                       }
+                       lyxerr << "\" has point " << p.x_ << "," << p.y_ << std::endl;
+               }
+       }
+
+       lyxerr << "InsetCache contains:" << std::endl;
+       for (CoordCacheBase<InsetBase>::cache_type::const_iterator i = getInsets().getData().begin(); i != getInsets().getData().end(); ++i) {
+               InsetBase const * inset = (*i).first;
+               Point p = (*i).second;
+               lyxerr << "Inset " << inset << "(" << to_utf8(inset->getInsetName()) << ") has point " << p.x_ << "," << p.y_ << std::endl;
+       }
 }
 
+} // namespace lyx