mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 18:08:10 +00:00
use shared_ptr for chache and cached_text
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2189 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
63d5a3c4d4
commit
f82d1cd90b
@ -1,3 +1,8 @@
|
||||
2001-07-05 Lars Gullik Bjønnes <larsbj@birdstep.com>
|
||||
|
||||
* insettext.[hC]: make cached_text a shared_ptr, make Cache be a map
|
||||
of BufferView * and shared_ptr<LyXText>
|
||||
|
||||
2001-07-05 Juergen Vigna <jug@sad.it>
|
||||
|
||||
* insettext.C (clear): deleted also the cache not only LyXText.
|
||||
|
@ -118,14 +118,10 @@ void InsetText::init(InsetText const * ins)
|
||||
|
||||
InsetText::~InsetText()
|
||||
{
|
||||
// delete all instances of LyXText before deleting the paragraps used
|
||||
// by it.
|
||||
cached_bview = 0;
|
||||
for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) {
|
||||
delete (*cit).second;
|
||||
(*cit).second = 0;
|
||||
}
|
||||
|
||||
// NOTE
|
||||
|
||||
while (par) {
|
||||
Paragraph * tmp = par->next();
|
||||
delete par;
|
||||
@ -136,19 +132,10 @@ InsetText::~InsetText()
|
||||
|
||||
void InsetText::clear()
|
||||
{
|
||||
// delete all instances of LyXText before deleting the paragraps used
|
||||
// by it.
|
||||
cached_bview = 0;
|
||||
for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) {
|
||||
delete (*cit).second;
|
||||
(*cit).second = 0;
|
||||
}
|
||||
|
||||
// now also delete all caches this should be safe, hopefully
|
||||
for (Cache::iterator cit = cache.begin(); cit != cache.end();
|
||||
cit = cache.begin())
|
||||
{
|
||||
cache.erase((*cit).first);
|
||||
}
|
||||
cache.clear();
|
||||
|
||||
while (par) {
|
||||
Paragraph * tmp = par->next();
|
||||
@ -231,7 +218,7 @@ int InsetText::ascent(BufferView * bv, LyXFont const &) const
|
||||
|
||||
int InsetText::descent(BufferView * bv, LyXFont const &) const
|
||||
{
|
||||
LyXText * t = getLyXText(bv);
|
||||
LyXText * t = getLyXText(bv);
|
||||
int y_temp = 0;
|
||||
Row * row = t->getRowNearY(y_temp);
|
||||
insetDescent = t->height - row->ascent_of_text() +
|
||||
@ -429,7 +416,7 @@ void InsetText::clearFrame(Painter & pain, bool cleared) const
|
||||
|
||||
void InsetText::update(BufferView * bv, LyXFont const & font, bool reinit)
|
||||
{
|
||||
LyXText * t = getLyXText(bv);
|
||||
LyXText * t = getLyXText(bv);
|
||||
|
||||
#if 0
|
||||
int ww = t->width;
|
||||
@ -496,7 +483,7 @@ void InsetText::setUpdateStatus(BufferView * bv, int what) const
|
||||
|
||||
void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty)
|
||||
{
|
||||
LyXText * t = getLyXText(bv);
|
||||
LyXText * t = getLyXText(bv);
|
||||
t->fullRebreak(bv);
|
||||
setUpdateStatus(bv, what);
|
||||
if (need_update != CURSOR || t->status != LyXText::UNCHANGED ||
|
||||
@ -1505,19 +1492,10 @@ int InsetText::getMaxWidth(BufferView * bv, UpdatableInset const * inset) const
|
||||
|
||||
void InsetText::setParagraphData(Paragraph * p)
|
||||
{
|
||||
// delete all instances of LyXText before deleting the paragraps used
|
||||
// by it.
|
||||
cached_bview = 0;
|
||||
for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit){
|
||||
delete (*cit).second;
|
||||
(*cit).second = 0;
|
||||
}
|
||||
|
||||
// now also delete all caches this should be safe, hopefully
|
||||
for (Cache::iterator cit = cache.begin(); cit != cache.end();
|
||||
cit = cache.begin())
|
||||
{
|
||||
cache.erase((*cit).first);
|
||||
}
|
||||
cache.clear();
|
||||
|
||||
while (par) {
|
||||
Paragraph * tmp = par->next();
|
||||
@ -1627,10 +1605,10 @@ Row * InsetText::crow(BufferView * bv) const
|
||||
|
||||
|
||||
LyXText * InsetText::getLyXText(BufferView const * lbv,
|
||||
bool const recursive) const
|
||||
bool const recursive) const
|
||||
{
|
||||
if (!recursive && (cached_bview == lbv))
|
||||
return cached_text;
|
||||
return cached_text.get();
|
||||
|
||||
// Super UGLY! (Lgb)
|
||||
BufferView * bv = const_cast<BufferView *>(lbv);
|
||||
@ -1639,15 +1617,15 @@ LyXText * InsetText::getLyXText(BufferView const * lbv,
|
||||
Cache::iterator it = cache.find(bv);
|
||||
|
||||
if (it != cache.end()) {
|
||||
lyx::Assert(it->second);
|
||||
lyx::Assert(it->second.get());
|
||||
|
||||
cached_text = it->second;
|
||||
if (recursive && the_locking_inset) {
|
||||
return the_locking_inset->getLyXText(bv);
|
||||
}
|
||||
return cached_text;
|
||||
return cached_text.get();
|
||||
}
|
||||
cached_text = new LyXText(const_cast<InsetText *>(this));
|
||||
cached_text.reset(new LyXText(const_cast<InsetText *>(this)));
|
||||
cached_text->init(bv);
|
||||
|
||||
cache.insert(make_pair(bv, cached_text));
|
||||
@ -1659,7 +1637,7 @@ LyXText * InsetText::getLyXText(BufferView const * lbv,
|
||||
return the_locking_inset->getLyXText(bv);
|
||||
}
|
||||
}
|
||||
return cached_text;
|
||||
return cached_text.get();
|
||||
}
|
||||
|
||||
|
||||
@ -1673,9 +1651,8 @@ void InsetText::deleteLyXText(BufferView * bv, bool recursive) const
|
||||
return;
|
||||
}
|
||||
|
||||
lyx::Assert(it->second);
|
||||
|
||||
delete it->second;
|
||||
lyx::Assert(it->second.get());
|
||||
|
||||
cache.erase(bv);
|
||||
if (recursive) {
|
||||
/// then remove all LyXText in text-insets
|
||||
@ -1699,7 +1676,7 @@ void InsetText::resizeLyXText(BufferView * bv, bool force) const
|
||||
if (it == cache.end()) {
|
||||
return;
|
||||
}
|
||||
lyx::Assert(it->second);
|
||||
lyx::Assert(it->second.get());
|
||||
|
||||
Paragraph * lpar = 0;
|
||||
Paragraph * selstartpar = 0;
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "inset.h"
|
||||
#include "LString.h"
|
||||
#include "lyxcursor.h"
|
||||
#include <boost/smart_ptr.hpp>
|
||||
|
||||
class Painter;
|
||||
class BufferView;
|
||||
@ -221,7 +222,7 @@ protected:
|
||||
|
||||
private:
|
||||
///
|
||||
typedef std::map<BufferView *, LyXText *> Cache;
|
||||
typedef std::map<BufferView *, boost::shared_ptr<LyXText> > Cache;
|
||||
///
|
||||
typedef Cache::value_type value_type;
|
||||
///
|
||||
@ -324,6 +325,7 @@ private:
|
||||
mutable bool frame_is_visible;
|
||||
///
|
||||
mutable BufferView * cached_bview;
|
||||
mutable LyXText * cached_text;
|
||||
///
|
||||
mutable boost::shared_ptr<LyXText> cached_text;
|
||||
};
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user