From 5a153a4961c734bbae12699461519f98108276bc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Sat, 14 Aug 2004 14:04:37 +0000 Subject: [PATCH] forgot these... git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8924 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/coordcache.C | 24 +++++++++++++ src/coordcache.h | 91 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 src/coordcache.C create mode 100644 src/coordcache.h diff --git a/src/coordcache.C b/src/coordcache.C new file mode 100644 index 0000000000..fdc24d9b3e --- /dev/null +++ b/src/coordcache.C @@ -0,0 +1,24 @@ + +#include "coordcache.h" +#include "debug.h" + +CoordCache theCoords; + +// 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; +} + + +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(); +} + diff --git a/src/coordcache.h b/src/coordcache.h new file mode 100644 index 0000000000..ac89bd251e --- /dev/null +++ b/src/coordcache.h @@ -0,0 +1,91 @@ +#ifndef COORDCACHE_H +#define COORDCACHE_H + +#include "mathed/math_data.h" +#include "insets/insetbase.h" +#include "lyxtext.h" + +#include + +#include + +void lyxbreaker(void const * data, const char * hint, int size); + +struct Point { + Point() + : x_(0), y_(0) + {} + + Point(int x, int y) : x_(x), y_(y) + { + BOOST_ASSERT(x > -3000); + BOOST_ASSERT(x < 4000); + BOOST_ASSERT(y > -3000); + BOOST_ASSERT(y < 4000); + } + + int x_, y_; +}; + + +template class CoordCacheBase { +public: + void clear() + { + data_.clear(); + } + + void add(T const * thing, int x, int y) + { + data_[thing] = Point(x, y); + } + + int x(T const * thing) const + { + check(thing, "x"); + return data_.find(thing)->second.x_; + } + + int y(T const * thing) const + { + check(thing, "y"); + return data_.find(thing)->second.y_; + } + + Point xy(T const * thing) const + { + check(thing, "xy"); + return data_.find(thing)->second; + } + + bool has(T const * thing) const + { + return data_.find(thing) != data_.end(); + } + +private: + friend class CoordCache; + + void check(T const * thing, char const * hint) const + { + if (!has(thing)) { + lyxbreaker(thing, hint, data_.size()); + BOOST_ASSERT(false); + } + } + + std::map data_; +}; + + +class CoordCache { +public: + void clear(); + + CoordCacheBase arrays_; + CoordCacheBase insets_; +}; + +extern CoordCache theCoords; + +#endif -- 2.39.2