]> git.lyx.org Git - features.git/commitdiff
Buffer methods for dealing with recursive includes.
authorRichard Kimberly Heck <rikiheck@lyx.org>
Sat, 25 Apr 2020 21:34:27 +0000 (17:34 -0400)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 13:48:57 +0000 (15:48 +0200)
src/Buffer.cpp
src/Buffer.h

index 4be7e2119701c6a456ee574300d5aa3ffb18c39d..ebb302f3ec2d0e3af4764ce082ae94ca4a0b8f00 100644 (file)
@@ -297,6 +297,8 @@ public:
        ///
        CloneList_ptr clone_list_;
 
+       ///
+       std::list<Buffer const *> include_list_;
 private:
        /// So we can force access via the accessors.
        mutable Buffer const * parent_buffer;
@@ -5591,4 +5593,55 @@ void Buffer::clearExternalModification() const
 }
 
 
+void Buffer::pushIncludedBuffer(Buffer const * buf) const
+{
+       masterBuffer()->d->include_list_.push_back(buf);
+       if (lyxerr.debugging(Debug::FILES)) {
+               LYXERR0("Pushed. Stack now:");
+               if (masterBuffer()->d->include_list_.empty())
+                       LYXERR0("EMPTY!");
+               else
+                       for (auto const & b : masterBuffer()->d->include_list_)
+                               LYXERR0(b->fileName());
+       }
+}
+
+
+void Buffer::popIncludedBuffer() const
+{
+       masterBuffer()->d->include_list_.pop_back();
+       if (lyxerr.debugging(Debug::FILES)) {
+               LYXERR0("Popped. Stack now:");
+               if (masterBuffer()->d->include_list_.empty())
+                       LYXERR0("EMPTY!");
+               else
+                       for (auto const & b : masterBuffer()->d->include_list_)
+                               LYXERR0(b->fileName());
+       }
+}
+
+
+bool Buffer::isBufferIncluded(Buffer const * buf) const
+{
+       if (!buf)
+               return false;
+       if (lyxerr.debugging(Debug::FILES)) {
+               LYXERR0("Checking for " << buf->fileName() << ". Stack now:");
+               if (masterBuffer()->d->include_list_.empty())
+                       LYXERR0("EMPTY!");
+               else
+                       for (auto const & b : masterBuffer()->d->include_list_)
+                               LYXERR0(b->fileName());
+       }
+       list<Buffer const *> const & blist = masterBuffer()->d->include_list_;
+       return find(blist.begin(), blist.end(), buf) != blist.end();
+}
+
+
+void Buffer::clearIncludeList() const
+{
+       LYXERR(Debug::FILES, "Clearing include list for " << fileName());
+       d->include_list_.clear();
+}
+
 } // namespace lyx
index e717e463bd08c0d9a80d296a0c9585327b98ca5b..8eb6e06494d93bbc27740d97f0c22eb009eb5057 100644 (file)
@@ -783,6 +783,13 @@ public:
        ///
        support::FileName getBibfilePath(docstring const & bibid) const;
 
+       /// routines for dealing with possible self-inclusion
+       void pushIncludedBuffer(Buffer const * buf) const;
+       void popIncludedBuffer() const;
+       bool isBufferIncluded(Buffer const * buf) const;
+private:
+       void clearIncludeList() const;
+
 private:
        friend class MarkAsExporting;
        /// mark the buffer as busy exporting something, or not