From 2c75ad0294d4cf3698c77020f910e184a60ce5a8 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Mon, 18 Mar 2013 19:32:30 -0400 Subject: [PATCH] Allowing direct, read-write access to the references cache just seems like a bad idea. --- src/Buffer.cpp | 13 ++++++++++--- src/Buffer.h | 9 ++++++++- src/insets/InsetLabel.cpp | 6 +++--- src/insets/InsetRef.cpp | 2 +- src/mathed/InsetMathRef.cpp | 2 +- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 2455b808fb..c6a8c2202b 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -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(masterBuffer())->references(label); + return const_cast(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(this)->references(label); + return const_cast(this)->getReferenceCache(label); +} + + +void Buffer::addReference(docstring const & label, Inset * inset, ParIterator it) +{ + References & refs = getReferenceCache(label); + refs.push_back(make_pair(inset, it)); } diff --git a/src/Buffer.h b/src/Buffer.h index cd0540cb7b..e30a09a9c5 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -660,10 +660,15 @@ public: /// typedef std::vector > 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); /// diff --git a/src/insets/InsetLabel.cpp b/src/insets/InsetLabel.cpp index c2ef896b86..4dfbc96448 100644 --- a/src/insets/InsetLabel.cpp +++ b/src/insets/InsetLabel.cpp @@ -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) { diff --git a/src/insets/InsetRef.cpp b/src/insets/InsetRef.cpp index 0c8e471d5c..42e7fabe1a 100644 --- a/src/insets/InsetRef.cpp +++ b/src/insets/InsetRef.cpp @@ -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) { diff --git a/src/mathed/InsetMathRef.cpp b/src/mathed/InsetMathRef.cpp index ae1768351c..ef08cbcd3d 100644 --- a/src/mathed/InsetMathRef.cpp +++ b/src/mathed/InsetMathRef.cpp @@ -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); }