From 5a46224f7311067cda747e0cae32d22dd919f179 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Wed, 29 Sep 2010 13:05:57 +0000 Subject: [PATCH] Remove the magic boolean in getChildren() from the public interface. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35538 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 22 +++++++++++++++------- src/Buffer.h | 31 +++++++++++++++++++------------ src/BufferList.cpp | 2 +- src/frontends/qt4/GuiDocument.cpp | 2 +- src/frontends/qt4/GuiView.cpp | 2 +- 5 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 48127b5e7a..2d562c23e3 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -2292,7 +2292,7 @@ void Buffer::getLanguages(std::set & languages) const for (ParConstIterator it = par_iterator_begin(); it != end; ++it) it->getLanguages(languages); // also children - ListOfBuffers clist = getChildren(); + ListOfBuffers clist = getDescendents(); ListOfBuffers::const_iterator cit = clist.begin(); ListOfBuffers::const_iterator const cen = clist.end(); for (; cit != cen; ++cit) @@ -2482,7 +2482,7 @@ ListOfBuffers Buffer::allRelatives() const { if (parent()) return masterBuffer()->allRelatives(); - return getChildren(/* true */); + return getDescendents(); } @@ -2520,7 +2520,7 @@ bool Buffer::hasChildren() const } -void Buffer::getChildren(ListOfBuffers & clist, bool grand_children) const +void Buffer::collectChildren(ListOfBuffers & clist, bool grand_children) const { // loop over children Impl::BufferPositionMap::iterator it = d->children_positions.begin(); @@ -2534,15 +2534,23 @@ void Buffer::getChildren(ListOfBuffers & clist, bool grand_children) const clist.push_back(child); if (grand_children) // there might be grandchildren - child->getChildren(clist /*, true */); + child->collectChildren(clist, true); } } -ListOfBuffers Buffer::getChildren(bool grand_children) const +ListOfBuffers Buffer::getChildren() const { ListOfBuffers v; - getChildren(v, grand_children); + collectChildren(v, false); + return v; +} + + +ListOfBuffers Buffer::getDescendents() const +{ + ListOfBuffers v; + collectChildren(v, true); return v; } @@ -3430,7 +3438,7 @@ bool Buffer::doExport(string const & format, bool put_in_tempdir, } else errors(error_type); // also to the children, in case of master-buffer-view - ListOfBuffers clist = getChildren(); + ListOfBuffers clist = getDescendents(); ListOfBuffers::const_iterator cit = clist.begin(); ListOfBuffers::const_iterator const cen = clist.end(); for (; cit != cen; ++cit) { diff --git a/src/Buffer.h b/src/Buffer.h index 8b5465c673..a9696812bf 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -305,14 +305,6 @@ public: void setParent(Buffer const *); Buffer const * parent() const; - /// Collect all relative buffers, in the order in which they appear. - /// I.e., the "root" Buffer is first, then its first child, then any - /// of its children, etc. However, there are no duplicates in this - /// list. - /// This is "stable", too, in the sense that it returns the same - /// thing from whichever Buffer it is called. - ListOfBuffers allRelatives() const; - /** Get the document's master (or \c this if this is not a child document) */ @@ -324,11 +316,23 @@ public: /// \return true if this \c Buffer has children bool hasChildren() const; - /// return a vector of all children (and grandchildren) - ListOfBuffers getChildren(bool grand_children = true) const; + /// \return a list of the direct children of this Buffer. + /// this list has no duplicates and is in the order in which + /// the children appear. + ListOfBuffers getChildren() const; + + /// \return a list of all descendents of this Buffer (children, + /// grandchildren, etc). this list has no duplicates and is in + /// the order in which the children appear. + ListOfBuffers getDescendents() const; - /// Add all children (and grandchildren) to supplied vector - void getChildren(ListOfBuffers & children, bool grand_children = true) const; + /// Collect all relative buffers, in the order in which they appear. + /// I.e., the "root" Buffer is first, then its first child, then any + /// of its children, etc. However, there are no duplicates in this + /// list. + /// This is "stable", too, in the sense that it returns the same + /// thing from whichever Buffer it is called. + ListOfBuffers allRelatives() const; /// Is buffer read-only? bool isReadonly() const; @@ -606,7 +610,10 @@ private: /// of loaded child documents). support::FileNameList const & getBibfilesCache(UpdateScope scope = UpdateMaster) const; + /// + void collectChildren(ListOfBuffers & children, bool grand_children) const; + /// Use the Pimpl idiom to hide the internals. class Impl; /// The pointer never changes although *pimpl_'s contents may. diff --git a/src/BufferList.cpp b/src/BufferList.cpp index 15abbd830c..466c924bdb 100644 --- a/src/BufferList.cpp +++ b/src/BufferList.cpp @@ -276,7 +276,7 @@ Buffer * BufferList::getBufferFromTmp(string const & s) if (suffixIs(s, master_name)) return *it; // if not, try with the children - ListOfBuffers clist = (*it)->getChildren(); + ListOfBuffers clist = (*it)->getDescendents(); ListOfBuffers::const_iterator cit = clist.begin(); ListOfBuffers::const_iterator cend = clist.end(); for (; cit != cend; ++cit) { diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 68bc7ab4b8..782a05f7ea 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -3045,7 +3045,7 @@ void GuiDocument::updateIncludeonlys() masterChildModule->maintainAuxCB->setEnabled(true); } QTreeWidgetItem * item = 0; - ListOfBuffers children = buffer().getChildren(false); + ListOfBuffers children = buffer().getChildren(); ListOfBuffers::const_iterator it = children.begin(); ListOfBuffers::const_iterator end = children.end(); bool has_unincluded = false; diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 8db725e853..108d465e8a 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -2328,7 +2328,7 @@ bool GuiView::closeBuffer(Buffer & buf) // in the session file in the correct order. If we close the master // buffer, we can close or release the child buffers here too. if (!closing_) { - ListOfBuffers clist = buf.getChildren(false); + ListOfBuffers clist = buf.getChildren(); ListOfBuffers::const_iterator it = clist.begin(); ListOfBuffers::const_iterator const bend = clist.end(); for (; it != bend; ++it) { -- 2.39.5