Allowing direct, read-write access to the references cache just seems

like a bad idea.
This commit is contained in:
Richard Heck 2013-03-18 19:32:30 -04:00
parent 27e27db147
commit 2c75ad0294
5 changed files with 23 additions and 9 deletions

View File

@ -3269,10 +3269,10 @@ void Buffer::listParentMacros(MacroSet & macros, LaTeXFeatures & features) const
}
Buffer::References & Buffer::references(docstring const & label)
Buffer::References & Buffer::getReferenceCache(docstring const & label)
{
if (d->parent())
return const_cast<Buffer *>(masterBuffer())->references(label);
return const_cast<Buffer *>(masterBuffer())->getReferenceCache(label);
RefCache::iterator it = d->ref_cache_.find(label);
if (it != d->ref_cache_.end())
@ -3288,7 +3288,14 @@ Buffer::References & Buffer::references(docstring const & label)
Buffer::References const & Buffer::references(docstring const & label) const
{
return const_cast<Buffer *>(this)->references(label);
return const_cast<Buffer *>(this)->getReferenceCache(label);
}
void Buffer::addReference(docstring const & label, Inset * inset, ParIterator it)
{
References & refs = getReferenceCache(label);
refs.push_back(make_pair(inset, it));
}

View File

@ -660,10 +660,15 @@ public:
///
typedef std::vector<std::pair<Inset *, ParIterator> > References;
References & references(docstring const & label);
///
References const & references(docstring const & label) const;
///
void addReference(docstring const & label, Inset * inset, ParIterator it);
///
void clearReferenceCache() const;
///
void setInsetLabel(docstring const & label, InsetLabel const * il);
///
InsetLabel const * insetLabel(docstring const & label) const;
/// return a list of all used branches (also in children)
@ -713,6 +718,8 @@ private:
/// mark the buffer as busy exporting something, or not
void setExportStatus(bool e) const;
///
References & getReferenceCache(docstring const & label);
/// Change name of buffer. Updates "read-only" flag.
void setFileName(support::FileName const & fname);
///

View File

@ -109,9 +109,9 @@ void InsetLabel::updateLabelAndRefs(docstring const & new_label,
void InsetLabel::updateReferences(docstring const & old_label,
docstring const & new_label)
{
Buffer::References & refs = buffer().references(old_label);
Buffer::References::iterator it = refs.begin();
Buffer::References::iterator end = refs.end();
Buffer::References const & refs = buffer().references(old_label);
Buffer::References::const_iterator it = refs.begin();
Buffer::References::const_iterator end = refs.end();
for (; it != end; ++it) {
buffer().undo().recordUndo(CursorData(it->second));
if (it->first->lyxCode() == MATH_REF_CODE) {

View File

@ -270,7 +270,7 @@ void InsetRef::updateBuffer(ParIterator const & it, UpdateType)
{
docstring const & ref = getParam("reference");
// register this inset into the buffer reference cache.
buffer().references(ref).push_back(make_pair(this, it));
buffer().addReference(ref, this, it);
docstring label;
for (int i = 0; !types[i].latex_name.empty(); ++i) {

View File

@ -184,7 +184,7 @@ void InsetMathRef::updateBuffer(ParIterator const & it, UpdateType /*utype*/)
return;
}
// register this inset into the buffer reference cache.
buffer().references(getTarget()).push_back(make_pair(this, it));
buffer().addReference(getTarget(), this, it);
}