]> git.lyx.org Git - lyx.git/blob - src/coordcache.C
update Basque and Romanian l10n
[lyx.git] / src / coordcache.C
1 /* \file coordcache.C
2  * This file is part of LyX, the document processor.
3  * Licence details can be found in the file COPYING.
4  *
5  * \author André Pönitz
6  *
7  * Full author contact details are available in file CREDITS.
8  */
9
10 #include <config.h>
11
12 #include "coordcache.h"
13 #include "debug.h"
14
15 #include "lyxtext.h"
16
17 #include "insets/insetbase.h"
18
19 #include <boost/assert.hpp>
20
21
22 namespace lyx {
23
24 Point::Point(int x, int y)
25         : x_(x), y_(y)
26 {
27         BOOST_ASSERT(x > -1000000);
28         BOOST_ASSERT(x <  1000000);
29         BOOST_ASSERT(y > -1000000);
30         BOOST_ASSERT(y <  1000000);
31 }
32
33 // just a helper to be able to set a breakpoint
34 void lyxbreaker(void const * data, const char * hint, int size)
35 {
36         lyxerr << "break on pointer: " << data << " hint: " << hint
37                 << " size: " << size << std::endl;
38         BOOST_ASSERT(false);
39 }
40
41
42 void CoordCache::clear()
43 {
44         arrays_.clear();
45         insets_.clear();
46         pars_.clear();
47         slices0_.clear();
48         slices1_.clear();
49 }
50
51
52 Point CoordCache::get(LyXText const * text, pit_type pit) const
53 {
54         ParPosCache::const_iterator const it = pars_.find(text);
55         BOOST_ASSERT(it != pars_.end());
56         InnerParPosCache::const_iterator const posit = it->second.find(pit);
57         BOOST_ASSERT(posit != it->second.end());
58         return posit->second;
59 }
60
61 void
62 CoordCache::dump() const {
63         lyxerr << "ParPosCache contains:" << std::endl;
64         for (ParPosCache::const_iterator i = getParPos().begin(); i != getParPos().end(); ++i) {
65                 LyXText const * lt = (*i).first;
66                 InnerParPosCache const & cache = (*i).second;
67                 lyxerr << "LyXText:" << lt << std::endl;
68                 for (InnerParPosCache::const_iterator j = cache.begin(); j != cache.end(); ++j) {
69                         pit_type pit = (*j).first;
70                         Paragraph const & par = lt->getPar(pit);
71                         Point p = (*j).second;
72                         lyxerr << "Paragraph " << pit << ": \"";
73                         for (int k = 0; k < std::min(static_cast<lyx::pos_type>(10), par.size()); ++k) {
74                                 lyxerr << to_utf8(docstring(1,par.getChar(k)));
75                         }
76                         lyxerr << "\" has point " << p.x_ << "," << p.y_ << std::endl;
77                 }
78         }
79
80         lyxerr << "InsetCache contains:" << std::endl;
81         for (CoordCacheBase<InsetBase>::cache_type::const_iterator i = getInsets().getData().begin(); i != getInsets().getData().end(); ++i) {
82                 InsetBase const * inset = (*i).first;
83                 Point p = (*i).second;
84                 lyxerr << "Inset " << inset << "(" << to_utf8(inset->getInsetName()) << ") has point " << p.x_ << "," << p.y_ << std::endl;
85         }
86 }
87
88 } // namespace lyx