]> git.lyx.org Git - features.git/commitdiff
Simplify the TexRow information for mathed output
authorGuillaume Munch <gm@lyx.org>
Sat, 4 Jun 2016 09:49:21 +0000 (10:49 +0100)
committerGuillaume Munch <gm@lyx.org>
Mon, 13 Jun 2016 07:46:15 +0000 (08:46 +0100)
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.

src/mathed/InsetMathGrid.cpp
src/mathed/InsetMathNest.cpp
src/mathed/MathStream.cpp
src/mathed/MathStream.h

index b505886586bd4449ec86e6aea1164073d5b1e7e6..81388767ae03eab296f17a6e835d4291854842d7 100644 (file)
@@ -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;
index 3e3877253f4040aacf23c7a0ed131c322de3ad24..d1c413b620bcb6fcf072a10183c8001fcab30ac1 100644 (file)
 #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());
index dabfc0680f93bb5ff8a03a9b9d880290be681aeb..e91db433f96c9eb8f4d95a306f76642274ec7553 100644 (file)
@@ -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_);
 }
 
 
index b8378ef0d9178454d85a1d2233b476d452f2b748..6f432b65fcfed9b4cf5f4d855b50685c1e9260bc 100644 (file)
 #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_;
 };
 
 ///