commit d2d243d77f41b65baea72b4a58ecf4a8cfcb71b9
Author: Guillaume Munch <g...@lyx.org>
Date:   Sat Jun 4 10:49:21 2016 +0100

    Simplify the TexRow information for mathed output
    
    Replace the manual manipulation of a stack of RowEntries with a Changer
    function. When I introduced the stack of RowEntries, I did not know about 
the
    Changer mechanism.

diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp
index b505886..8138876 100644
--- a/src/mathed/InsetMathGrid.cpp
+++ b/src/mathed/InsetMathGrid.cpp
@@ -34,7 +34,6 @@
 #include "support/docstream.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
-
 #include "support/lassert.h"
 
 #include <sstream>
@@ -1275,7 +1274,7 @@ void InsetMathGrid::write(WriteStream & os,
                                ++col;
                                continue;
                        }
-                       os.pushRowEntry(entry);
+                       Changer dummy = os.changeRowEntry(entry);
                        if (cellinfo_[idx].multi_ == CELL_BEGIN_OF_MULTICOLUMN) 
{
                                size_t s = col + 1;
                                while (s < ncols() &&
@@ -1293,7 +1292,6 @@ void InsetMathGrid::write(WriteStream & os,
                                os << '}';
                        os << eocString(col + nccols - 1, lastcol);
                        col += nccols;
-                       os.popRowEntry();
                }
                eol = eolString(row, os.fragile(), os.latex(), last_eoln);
                os << eol;
diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp
index 3e38772..d1c413b 100644
--- a/src/mathed/InsetMathNest.cpp
+++ b/src/mathed/InsetMathNest.cpp
@@ -59,12 +59,12 @@
 #include "frontends/Painter.h"
 #include "frontends/Selection.h"
 
-#include "support/lassert.h"
 #include "support/debug.h"
+#include "support/docstream.h"
 #include "support/gettext.h"
+#include "support/lassert.h"
 #include "support/lstrings.h"
 #include "support/textutils.h"
-#include "support/docstream.h"
 
 #include <algorithm>
 #include <sstream>
@@ -380,9 +380,8 @@ void InsetMathNest::write(WriteStream & os) const
        docstring const latex_name = name();
        os << '\\' << latex_name;
        for (size_t i = 0; i < nargs(); ++i) {
-               os.pushRowEntry(TexRow::mathEntry(id(),i));
+               Changer dummy = os.changeRowEntry(TexRow::mathEntry(id(),i));
                os << '{' << cell(i) << '}';
-               os.popRowEntry();
        }
        if (nargs() == 0)
                os.pendingSpace(true);
@@ -408,13 +407,9 @@ void InsetMathNest::latex(otexstream & os, OutputParams 
const & runparams) const
                        runparams.dryrun ? WriteStream::wsDryrun : 
WriteStream::wsDefault,
                        runparams.encoding);
        wi.canBreakLine(os.canBreakLine());
-       if (runparams.lastid != -1) {
-               wi.pushRowEntry(os.texrow().textEntry(runparams.lastid,
-                                                                               
          runparams.lastpos));
-               write(wi);
-               wi.popRowEntry();
-       } else
-               write(wi);
+       Changer dummy = 
wi.changeRowEntry(os.texrow().textEntry(runparams.lastid,
+                                                               
runparams.lastpos));
+       write(wi);
        // Reset parbreak status after a math inset.
        os.lastChar(0);
        os.canBreakLine(wi.canBreakLine());
diff --git a/src/mathed/MathStream.cpp b/src/mathed/MathStream.cpp
index dabfc06..e91db43 100644
--- a/src/mathed/MathStream.cpp
+++ b/src/mathed/MathStream.cpp
@@ -15,8 +15,9 @@
 #include "MathData.h"
 #include "MathExtern.h"
 
-#include "support/textutils.h"
 #include "support/docstring.h"
+#include "support/RefChanger.h"
+#include "support/textutils.h"
 
 #include <algorithm>
 #include <cstring>
@@ -123,18 +124,20 @@ WriteStream & operator<<(WriteStream & ws, docstring 
const & s)
 
 WriteStream::WriteStream(otexrowstream & os, bool fragile, bool latex,
                                                 OutputType output, Encoding 
const * encoding)
-       : os_(os), fragile_(fragile), firstitem_(false), latex_(latex),
-         output_(output), pendingspace_(false), pendingbrace_(false),
-         textmode_(false), locked_(0), ascii_(0), canbreakline_(true),
-         line_(0), encoding_(encoding)
-{}
+       : WriteStream(os)
+{
+       fragile_ = fragile;
+       latex_ = latex;
+       output_ = output;
+       encoding_ = encoding;
+}
 
 
 WriteStream::WriteStream(otexrowstream & os)
        : os_(os), fragile_(false), firstitem_(false), latex_(false),
          output_(wsDefault), pendingspace_(false), pendingbrace_(false),
          textmode_(false), locked_(0), ascii_(0), canbreakline_(true),
-         line_(0), encoding_(0) 
+         line_(0), encoding_(0), row_entry_(TexRow::row_none)
 {}
 
 
@@ -183,26 +186,17 @@ void WriteStream::asciiOnly(bool ascii)
 }
 
 
-void WriteStream::pushRowEntry(TexRow::RowEntry entry)
-{
-       outer_row_entries_.push_back(entry);
-}
-
-
-void WriteStream::popRowEntry()
+Changer WriteStream::changeRowEntry(TexRow::RowEntry entry)
 {
-       if (!outer_row_entries_.empty())
-               outer_row_entries_.pop_back();
+       return make_change(row_entry_, entry);
 }
 
 
 bool WriteStream::startOuterRow()
 {
-       size_t n = outer_row_entries_.size();
-       if (n > 0)
-               return texrow().start(outer_row_entries_[n - 1]);
-       else
+       if (TexRow::isNone(row_entry_))
                return false;
+       return texrow().start(row_entry_);
 }
 
 
diff --git a/src/mathed/MathStream.h b/src/mathed/MathStream.h
index b8378ef..6f432b6 100644
--- a/src/mathed/MathStream.h
+++ b/src/mathed/MathStream.h
@@ -12,11 +12,12 @@
 #ifndef MATH_MATHMLSTREAM_H
 #define MATH_MATHMLSTREAM_H
 
-#include "support/strfwd.h"
-
 #include "InsetMath.h"
 #include "texstream.h"
 
+#include "support/Changer.h"
+#include "support/strfwd.h"
+
 
 namespace lyx {
 
@@ -87,11 +88,8 @@ public:
        /// LaTeX encoding
        Encoding const * encoding() const { return encoding_; }
 
-       /// maintains a stack of texrow informations about outer math insets.
-       /// push an entry
-       void pushRowEntry(TexRow::RowEntry entry);
-       /// pop an entry
-       void popRowEntry();
+       /// Temporarily change the TexRow information about the outer row entry.
+       Changer changeRowEntry(TexRow::RowEntry entry);
        /// TexRow::starts the innermost outer math inset
        /// returns true if the outer row entry will appear at this line
        bool startOuterRow();
@@ -122,8 +120,8 @@ private:
        int line_;
        ///
        Encoding const * encoding_;
-       ///
-       std::vector<TexRow::RowEntry> outer_row_entries_;
+       /// Row entry we are in
+       TexRow::RowEntry row_entry_;
 };
 
 ///

Reply via email to