commit fd50fb720f45a9064ccd91c1066e80ce6b5aa8a5
Author: Jean-Marc Lasgouttes <[email protected]>
Date:   Mon Dec 5 14:47:13 2016 +0100

    Introduce (Inset|InsetList|Paragraph)::resetBuffer
    
    This avoids an ugly cast like
         setBuffer(*static_cast<Buffer *>(0));
    that clang does not appreciate.
---
 src/CutAndPaste.cpp  |    2 +-
 src/InsetList.cpp    |   18 ++++++++++++------
 src/InsetList.h      |    2 ++
 src/Paragraph.cpp    |    6 ++++++
 src/Paragraph.h      |    2 ++
 src/insets/Inset.cpp |    6 ++++++
 src/insets/Inset.h   |    2 ++
 7 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp
index 7e09ac9..17dbdc6 100644
--- a/src/CutAndPaste.cpp
+++ b/src/CutAndPaste.cpp
@@ -652,7 +652,7 @@ void copySelectionHelper(Buffer const & buf, Text const & 
text,
        // are not linked to something else.
        it = copy_pars.begin();
        for (; it != it_end; ++it) {
-               it->setBuffer(*static_cast<Buffer *>(0));
+               it->resetBuffer();
                it->setInsetOwner(0);
        }
 
diff --git a/src/InsetList.cpp b/src/InsetList.cpp
index 3d4f715..d1b6d43 100644
--- a/src/InsetList.cpp
+++ b/src/InsetList.cpp
@@ -10,18 +10,15 @@
  */
 
 #include <config.h>
-#include <algorithm>
 
 #include "InsetList.h"
 
-#include "Buffer.h"
-#include "BufferParams.h"
-#include "BranchList.h"
-
-#include "insets/InsetBranch.h"
+#include "insets/Inset.h"
 
 #include "support/debug.h"
 
+#include <algorithm>
+
 using namespace std;
 
 namespace lyx {
@@ -84,6 +81,15 @@ void InsetList::setBuffer(Buffer & b)
 }
 
 
+void InsetList::resetBuffer()
+{
+       List::iterator it = list_.begin();
+       List::iterator end = list_.end();
+       for (; it != end; ++it)
+               it->inset->resetBuffer();
+}
+
+
 InsetList::iterator InsetList::insetIterator(pos_type pos)
 {
        InsetTable search_elem(pos, 0);
diff --git a/src/InsetList.h b/src/InsetList.h
index dcaa28e..f704a39 100644
--- a/src/InsetList.h
+++ b/src/InsetList.h
@@ -36,6 +36,8 @@ public:
        InsetList(InsetList const &, pos_type beg, pos_type end);
        ///
        void setBuffer(Buffer &);
+       ///
+       void resetBuffer();
 
        ///
        class InsetTable {
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index 05c10b5..135ba96 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -3534,6 +3534,12 @@ void Paragraph::setBuffer(Buffer & b)
 }
 
 
+void Paragraph::resetBuffer()
+{
+       d->insetlist_.resetBuffer();
+}
+
+
 Inset * Paragraph::releaseInset(pos_type pos)
 {
        Inset * inset = d->insetlist_.release(pos);
diff --git a/src/Paragraph.h b/src/Paragraph.h
index 184c976..2133d8c 100644
--- a/src/Paragraph.h
+++ b/src/Paragraph.h
@@ -396,6 +396,8 @@ public:
        InsetList const & insetList() const;
        ///
        void setBuffer(Buffer &);
+       ///
+       void resetBuffer();
 
        ///
        bool isHfill(pos_type pos) const;
diff --git a/src/insets/Inset.cpp b/src/insets/Inset.cpp
index 6e2e4a0..09a45e4 100644
--- a/src/insets/Inset.cpp
+++ b/src/insets/Inset.cpp
@@ -186,6 +186,12 @@ void Inset::setBuffer(Buffer & buffer)
 }
 
 
+void Inset::resetBuffer()
+{
+       buffer_ = nullptr;
+}
+
+
 Buffer & Inset::buffer()
 {
        if (!buffer_) {
diff --git a/src/insets/Inset.h b/src/insets/Inset.h
index 48ad7be..3398a9d 100644
--- a/src/insets/Inset.h
+++ b/src/insets/Inset.h
@@ -108,6 +108,8 @@ public:
 
        /// change associated Buffer
        virtual void setBuffer(Buffer & buffer);
+       /// reset associated Buffer to null value
+       virtual void resetBuffer();
        /// retrieve associated Buffer
        virtual Buffer & buffer();
        virtual Buffer const & buffer() const;

Reply via email to