]> git.lyx.org Git - features.git/commitdiff
make operator<<(*stream, ...) free functions;
authorAndré Pönitz <poenitz@gmx.net>
Mon, 3 Dec 2001 16:24:50 +0000 (16:24 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Mon, 3 Dec 2001 16:24:50 +0000 (16:24 +0000)
make *stream 'class' instead of 'struct' (not finished);
use LCOlor::mathline only for boxes.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3140 a592a061-630c-0410-9148-cb99ea01b6c8

23 files changed:
src/mathed/Makefile.am
src/mathed/formula.C
src/mathed/formulabase.C
src/mathed/formulamacro.C
src/mathed/math_arrayinset.C
src/mathed/math_casesinset.C
src/mathed/math_charinset.C
src/mathed/math_cursor.C
src/mathed/math_cursor.h
src/mathed/math_decorationinset.C
src/mathed/math_extern.C
src/mathed/math_fracinset.C
src/mathed/math_gridinset.C
src/mathed/math_inset.C
src/mathed/math_inset.h
src/mathed/math_mathmlstream.C
src/mathed/math_mathmlstream.h
src/mathed/math_rootinset.C
src/mathed/math_scriptinset.C
src/mathed/math_splitinset.C
src/mathed/math_sqrtinset.C
src/mathed/math_streamstr.h [new file with mode: 0644]
src/mathed/math_support.C

index 31e82e731914d7d61e2c10e52ff8c026c2ffc261..b077bc6cb2e55ac52d829a022dd9109c1793eb4b 100644 (file)
@@ -111,6 +111,7 @@ libmathed_la_SOURCES = \
        math_sqrtinset.h \
        math_stackrelinset.C \
        math_stackrelinset.h \
+       math_streamstr.h \
        math_stringinset.C \
        math_stringinset.h \
        math_support.C \
index 0b14506d4f15aef9b4d028ea98b6e9986089f6e4..b0bc0c7621662d03525ce6fb708845780008dea3 100644 (file)
@@ -283,20 +283,19 @@ void InsetFormula::write(Buffer const * buf, ostream & os) const
 }
 
 
-int InsetFormula::latex(Buffer const * buf, ostream & os, bool fragil, bool)
-       const
+int InsetFormula::latex(Buffer const *, ostream & os, bool fragil, bool) const
 {
-       WriteStream wi(buf, os, fragil);
+       WriteStream wi(os, fragil);
        par_->write(wi);
-       return wi.line_;
+       return wi.line();
 }
 
 
-int InsetFormula::ascii(Buffer const * buf, ostream & os, int) const
+int InsetFormula::ascii(Buffer const *, ostream & os, int) const
 {
-       WriteStream wi(buf, os, false);
+       WriteStream wi(os, false);
        par_->write(wi);
-       return wi.line_;
+       return wi.line();
 }
 
 
@@ -310,11 +309,11 @@ int InsetFormula::docbook(Buffer const * buf, ostream & os) const
 {
        MathMLStream ms(os);
        ms << MTag("equation") << MTag("alt");
-       int res = ascii(buf, ms.os_, 0);
+       int res = ascii(buf, ms.os(), 0);
        ms << ETag("alt") << MTag("math");
        ms << par_.nucleus();
        ms << ETag("math") << ETag("equation");
-       return ms.line_ + res;
+       return ms.line() + res;
 }
 
 
index 6f796ceea8b6adf42c43ef5f67d8e2cdf91f6b15..46287d7d662ffd0027a0ae0d7ed87a8632ab8534 100644 (file)
@@ -559,7 +559,7 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
 
        case LFUN_MATH_DELIM:
        {
-               //lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'\n";
+               lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'\n";
                string ls;
                string rs;
                istringstream is(arg.c_str());
@@ -755,7 +755,7 @@ void mathDispatchMathMacro(BufferView * bv, string const & arg)
 
 
 void mathDispatchMathDelim(BufferView * bv, string const & arg)
-{         
+{
        if (bv->available()) { 
                if (openNewInset(bv, new InsetFormula))
                        bv->theLockingInset()->localDispatch(bv, LFUN_MATH_DELIM, arg);
index 93b0689b479ef52f252da4420c0d97e1340049ac..4e6739ffb711a8d3b0973124336e143ede95c506 100644 (file)
@@ -71,26 +71,26 @@ Inset * InsetFormulaMacro::clone(Buffer const &, bool) const
 }
 
 
-void InsetFormulaMacro::write(Buffer const * buf, ostream & os) const
+void InsetFormulaMacro::write(Buffer const *, ostream & os) const
 {
        os << "FormulaMacro ";
-       WriteStream wi(buf, os, false);
+       WriteStream wi(os, false);
        par()->write(wi);
 }
 
 
-int InsetFormulaMacro::latex(Buffer const * buf, ostream & os, bool fragile, 
+int InsetFormulaMacro::latex(Buffer const *, ostream & os, bool fragile, 
                             bool /*free_spacing*/) const
 {
-       WriteStream wi(buf, os, fragile);
+       WriteStream wi(os, fragile);
        par()->write(wi);
        return 2;
 }
 
 
-int InsetFormulaMacro::ascii(Buffer const * buf, ostream & os, int) const
+int InsetFormulaMacro::ascii(Buffer const *, ostream & os, int) const
 {
-       WriteStream wi(buf, os, false);
+       WriteStream wi(os, false);
        par()->write(wi);
        return 0;
 }
index c0ed8a273f39771aee4b8361e7a285e0587104c8..2c6da9506ce21b6a24191c3aec86183167b81208 100644 (file)
@@ -71,7 +71,7 @@ void MathArrayInset::metrics(MathMetricsInfo const & st) const
 
 void MathArrayInset::write(WriteStream & os) const
 {
-       if (os.fragile)
+       if (os.fragile())
                os << "\\protect";
        os << "\\begin{array}";
 
@@ -81,7 +81,7 @@ void MathArrayInset::write(WriteStream & os) const
 
        MathGridInset::write(os);
 
-       if (os.fragile)
+       if (os.fragile())
                os << "\\protect";
        os << "\\end{array}\n";
 }
index 183e9550606ba13c1a8cd9966f549c297ece0374..7077507e7cc584270c2f0afeb40549fc9e184ea3 100644 (file)
@@ -36,11 +36,11 @@ void MathCasesInset::draw(Painter & pain, int x, int y) const
 
 void MathCasesInset::write(WriteStream & os) const
 {
-       if (os.fragile)
+       if (os.fragile())
                os << "\\protect";
        os << "\\begin{cases}";
        MathGridInset::write(os);
-       if (os.fragile)
+       if (os.fragile())
                os << "\\protect";
        os << "\\end{cases}\n";
 }
index 417078bd6d738a268ac5eff17ffe0344f566fdd7..b89280fce28b84124a48d31b68d9c9cc405572bf 100644 (file)
@@ -96,9 +96,9 @@ void MathCharInset::writeRaw(std::ostream & os) const
 
 void MathCharInset::write(WriteStream & os) const
 {
-       writeHeader(os.os);
-       writeRaw(os.os);
-       writeTrailer(os.os);
+       writeHeader(os.os());
+       writeRaw(os.os());
+       writeTrailer(os.os());
 }
 
 
index 127316be1045fb0b435715ee57b7e3772ee3acc0..0d70e911ce2bda37b4a767c58d42839765221439 100644 (file)
@@ -805,7 +805,7 @@ void MathCursor::drawSelection(Painter & pain) const
                int x  = c.xo() + c.pos2x(anc.pos_);
                int y1 = c.yo() - c.ascent();
                int y2 = c.yo() + c.descent();
-               pain.line(x, y1, x, y2, LColor::mathline);
+               pain.line(x, y1, x, y2, LColor::math);
        }
 #endif
 }
@@ -961,7 +961,7 @@ void MathCursor::normalize() const
                lyxerr << "this should not really happen - 2: "
                        << pos() << " " << size() <<  " in idx: " << it->idx()
                        << " in atom: '";
-               WriteStream wi(0, lyxerr, false);
+               WriteStream wi(lyxerr, false);
                it->par()->write(wi);
                lyxerr << "\n";
                dump("error 4");
index bea6dcfce563a16f8564569eee1d3e991ec11979..f38125aa459c82c4873e85dde7e7cea28523ee9c 100644 (file)
@@ -29,13 +29,25 @@ class InsetFormulaBase;
 class Painter;
 class Selection;
 
+/**
+
+[Have a look at math_inset.h first]
+
+The MathCursor is different from the kind of cursor used in the Outer
+World. It contains a stack of MathCursorPositions, each of which is made
+up of a inset pointer, an index and a position offset, marking a path from
+this formula's mathHullInset to the current position.
+
+*/
+
+
 /// Description of a position 
 struct MathCursorPos {
-       /// inset
+       /// pointer to an inset
        MathAtom * par_;
-       /// cell index
+       /// cell index of a position in this inset
        MathInset::idx_type idx_;
-       /// cell position
+       /// position in this cell
        MathInset::pos_type pos_;
 
        /// returns cell corresponding to this position
@@ -48,13 +60,13 @@ struct MathCursorPos {
        MathXArray & xcell(MathInset::idx_type idx) const;
 };
 
-/// 
+/// test for equality
 bool operator==(MathCursorPos const &, MathCursorPos const &);
-/// 
+/// test for unequality
 bool operator<(MathCursorPos const &, MathCursorPos const &);
 
 
-/// This is the external interface of Math's subkernel
+/// see above
 class MathCursor {
 public:
        /// short of anything else reasonable
@@ -82,25 +94,25 @@ public:
        void erase();
        ///
        void backspace();
-       ///
+       /// called for LFUN_HOME etc
        void home(bool sel = false);
-       ///
+       /// called for LFUN_END etc
        void end(bool sel = false);
-       ///
+       /// called for LFUN_RIGHT and LFUN_RIGHTSEL
        bool right(bool sel = false);
-       ///
+       /// called for LFUN_LEFT etc
        bool left(bool sel = false);
-       ///
+       /// called for LFUN_UP etc
        bool up(bool sel = false);
-       ///
+       /// called for LFUN_DOWN etc
        bool down(bool sel = false);
        /// Put the cursor in the first position
        void first();
        /// Put the cursor in the last position
        void last();
-       ///
+       /// move to next cell in current inset
        void idxNext();
-       ///
+       /// move to previous cell in current inset
        void idxPrev();
        ///
        void plainErase();
@@ -111,22 +123,21 @@ public:
 
        ///
        void delLine();
-       /// This is in pixels from (maybe?) the top of inset
+       /// in pixels from top of screen
        void setPos(int x, int y);
-       /// This is in pixels from (maybe?) the top of inset, don't move further
-       ///
+       /// in pixels from top of screen
        void getPos(int & x, int & y);
-       ///
+       /// 
        MathAtom & par() const;
        /// return the next enclosing grid inset and the cursor's index in it
        MathGridInset * enclosingGrid(idx_type &) const;
        ///
        InsetFormulaBase const * formula();
-       ///
+       /// current offset in the current cell
        pos_type pos() const;
-       ///
+       /// current cell
        idx_type idx() const;
-       ///
+       /// size of current cell
        size_type size() const;
        ///
        bool interpret(string const &);
@@ -134,8 +145,7 @@ public:
        bool interpret(char);
        ///
        bool toggleLimits();
-       ///
-       // Macro mode methods
+       /// interpret name a name of a macro
        void macroModeClose();
        ///
        bool inMacroMode() const;
@@ -167,9 +177,9 @@ public:
        void handleDelim(string const & l, string const & r);
        ///
        void handleNest(MathInset * p);
-       /// Splits cells and shifts right part to the next cell
+       /// splits cells and shifts right part to the next cell
        void splitCell();
-       /// Splits line and insert new row of cell 
+       /// splits line and insert new row of cell 
        void breakLine();
        /// read contents of line into an array
        void readLine(MathArray & ar) const;
@@ -192,7 +202,7 @@ public:
        ///
        row_type row() const;
 
-       /// Make sure cursor position is valid
+       /// make sure cursor position is valid
        void normalize() const;
        ///
        UpdatableInset * asHyperActiveInset() const;
@@ -235,14 +245,14 @@ public:
        /// path of positions the anchor had to go if it were leving each inset
        cursor_type Anchor_;
 
-       /// reference to the last item of the path
+       /// reference to the last item of the path, i.e. "The Cursor"
        MathCursorPos & cursor();
-       ///
+       /// reference to the last item of the path, i.e. "The Cursor"
        MathCursorPos const & cursor() const;
 
-       ///
+       /// dump selection information for debugging
        void seldump(char const * str) const;
-       ///
+       /// dump selection information for debugging
        void dump(char const * str) const;
        ///
        void stripFromLastEqualSign();
index 08762d17b7b61b2083957d85974bcc608d416868..977308b8fa9170963983cc914df95410b874ac52 100644 (file)
@@ -93,7 +93,7 @@ void MathDecorationInset::draw(Painter & pain, int x, int y) const
 
 void MathDecorationInset::write(WriteStream & os) const
 {
-       if (os.fragile && protect())
+       if (os.fragile() && protect())
                os << "\\protect";
        os << '\\' << name_.c_str() << '{' << cell(0) << '}';
 }
index 3d7593540d69da3fd93073cfd2271dd3bba611a9..6751dd405ad13aeaaf37ed8732dc9f88e34d0fce 100644 (file)
@@ -713,7 +713,7 @@ void write(MathArray const & dat, WriteStream & wi)
        MathArray ar = dat;
        extractStrings(ar);
        for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it) {
-               wi.firstitem = (it == ar.begin());
+               wi.firstitem() = (it == ar.begin());
                MathInset const * p = it->nucleus();
                if (it + 1 != ar.end()) {
                        if (MathScriptInset const * q = asScript(it)) {
index 1799838dacceacb563ae104f204e53eaf107e93a..c1f8f23ff4bfa78e7a965a23028803eee7206da4 100644 (file)
@@ -43,7 +43,7 @@ void MathFracInset::draw(Painter & pain, int x, int y) const
        xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 3 - 5);
        xcell(1).draw(pain, m - xcell(1).width() / 2, y + xcell(1).ascent()  + 3 - 5);
        if (!atop_)
-               pain.line(x + 2, y - 5, x + width() - 4, y - 5, LColor::mathline);
+               pain.line(x + 2, y - 5, x + width() - 4, y - 5, LColor::math);
 }
 
 
index 51668da8f8f40498ed671be1f02bb02e9c6efe82..893c5a06c20c69218a156c2e322bc8078946acb3 100644 (file)
@@ -3,7 +3,7 @@
 #endif
 
 #include "math_gridinset.h"
-#include "math_mathmlstream.h"
+#include "math_streamstr.h"
 #include "lyxfont.h"
 #include "Painter.h"
 #include "debug.h"
index 320d03f269eebb8aceb032dc42d2ba0a7152c744..ee98f6990123b6c332b75762590d309d0294105e 100644 (file)
 #include "debug.h"
 
 
-MathInset::MathInset()
-{}
-
-
-MathInset::~MathInset()
-{}
-
-
 int MathInset::height() const
 {
        return ascent() + descent();
@@ -44,7 +36,7 @@ int MathInset::height() const
 
 std::ostream & operator<<(std::ostream & os, MathInset const & inset)
 {
-       WriteStream wi(0, os, false);
+       WriteStream wi(os, false);
        inset.write(wi);
        return os;
 }
@@ -188,7 +180,7 @@ void MathInset::idxDeleteRange(idx_type, idx_type)
 void MathInset::normalize(NormalStream & os) const
 {
        os << "[unknown ";
-       WriteStream wi(0, os.os_, false);
+       WriteStream wi(os.os(), false);
        write(wi);
        os << "] ";
 }
@@ -197,7 +189,7 @@ void MathInset::normalize(NormalStream & os) const
 void MathInset::dump() const
 {
        lyxerr << "---------------------------------------------\n";
-       WriteStream wi(0, lyxerr, false);
+       WriteStream wi(lyxerr, false);
        write(wi);
        lyxerr << "\n---------------------------------------------\n";
 }
@@ -244,20 +236,20 @@ void MathInset::write(WriteStream &) const
 
 void MathInset::octavize(OctaveStream & os) const
 {
-       NormalStream ns(os.os_);
+       NormalStream ns(os.os());
        normalize(ns);
 }
 
 
 void MathInset::maplize(MapleStream & os) const
 {
-       NormalStream ns(os.os_);
+       NormalStream ns(os.os());
        normalize(ns);
 }
 
 
 void MathInset::mathmlize(MathMLStream & os) const
 {
-       NormalStream ns(os.os_);
+       NormalStream ns(os.os());
        normalize(ns);
 }
index 5a9c294e563e22a59afe274d4cfe5a6fbc8b0f37..ca568a3ed8d245f31aed0eace26d5a266a7fca5d 100644 (file)
 #include "math_xdata.h"
 #include "math_defs.h"
 
-/** Abstract base class for all math objects.
-    A math insets is for use of the math editor only, it isn't a
-    general LyX inset. It's used to represent all the math objects.
-    The formulaInset (a LyX inset) encapsulates a math inset.
+/**
+
+Abstract base class for all math objects.  A math insets is for use of the
+math editor only, it isn't a general LyX inset. It's used to represent all
+the math objects. 
+
+Math insets do not know there parents, a cursor position or things
+like that. The are dumb object that are contained in other math insets
+(mathNestInsets, in fact) thus forming a tree. The root of this tree is
+always a mathHullInset, which provides an interface to the Outer World by
+inclusion in the "real LyX insets" FormulaInset and FormulaMacroInset.
+
 */
 
 
@@ -79,10 +87,10 @@ public:
        /// type for column numbers
        typedef size_type                col_type;
 
-       ///
-       MathInset();
+       /// our members behave nicely...
+       MathInset() {}
        /// the virtual base destructor
-       virtual ~MathInset()
+       virtual ~MathInset() {}
 
        /// draw the object
        virtual void draw(Painter &, int x, int y) const;
index 35b2b9ae99a70e74f2463246b12fc0cbc743b97f..f4e9ad4f926904dd0f4a9f48977dfa6ab9b70d30 100644 (file)
@@ -11,61 +11,61 @@ MathMLStream::MathMLStream(std::ostream & os)
 {}
 
 
-MathMLStream & MathMLStream::operator<<(MathInset const * p)
+MathMLStream & operator<<(MathMLStream & ms, MathInset const * p)
 {
        if (p)
-               p->mathmlize(*this);
+               p->mathmlize(ms);
        else
-               lyxerr << "MathMLStream::operator<<(NULL) called\n";
-       return *this;           
+               lyxerr << "operator<<(MathMLStream, NULL) called\n";
+       return ms;
 }
 
 
-MathMLStream & MathMLStream::operator<<(MathArray const & ar)
+MathMLStream & operator<<(MathMLStream & ms, MathArray const & ar)
 {
-       mathmlize(ar, *this);
-       return *this;           
+       mathmlize(ar, ms);
+       return ms;
 }
 
 
-MathMLStream & MathMLStream::operator<<(char const * s)
+MathMLStream & operator<<(MathMLStream & ms, char const * s)
 {
-       os_ << s;
-       return *this;           
+       ms.os() << s;
+       return ms;
 }
 
 
-MathMLStream & MathMLStream::operator<<(char c)
+MathMLStream & operator<<(MathMLStream & ms, char c)
 {
-       os_ << c;
-       return *this;           
+       ms.os() << c;
+       return ms;
 }
 
 
-MathMLStream & MathMLStream::operator<<(MTag const & t)
+MathMLStream & operator<<(MathMLStream & ms, MTag const & t)
 {
-       ++tab_;
-       cr();
-       os_ << '<' << t.tag_ << '>';
-       return *this;           
+       ++ms.tab();
+       ms.cr();
+       ms.os() << '<' << t.tag_ << '>';
+       return ms;
 }
 
 
-MathMLStream & MathMLStream::operator<<(ETag const & t)
+MathMLStream & operator<<(MathMLStream & ms, ETag const & t)
 {
-       cr();
-       if (tab_ > 0)
-               --tab_;
-       os_ << "</" << t.tag_ << '>';
-       return *this;           
+       ms.cr();
+       if (ms.tab() > 0)
+               --ms.tab();
+       ms.os() << "</" << t.tag_ << '>';
+       return ms;
 }
 
 
 void MathMLStream::cr()
 {
-       os_ << '\n';
-       for (int i = 0; i < tab_; ++i)
-               os_ << ' ';
+       os() << '\n';
+       for (int i = 0; i < tab(); ++i)
+               os() << ' ';
 }
 
 
@@ -73,109 +73,109 @@ void MathMLStream::cr()
 //////////////////////////////////////////////////////////////////////
 
 
-MapleStream & MapleStream::operator<<(MathInset const * p)
+MapleStream & operator<<(MapleStream & ms, MathInset const * p)
 {
        if (p)
-               p->maplize(*this);
+               p->maplize(ms);
        else
-               lyxerr << "MathMLStream::operator<<(NULL) called\n";
-       return *this;           
+               lyxerr << "operator<<(MapleStream, NULL) called\n";
+       return ms;
 }
 
 
-MapleStream & MapleStream::operator<<(MathArray const & ar)
+MapleStream & operator<<(MapleStream & ms, MathArray const & ar)
 {
-       maplize(ar, *this);
-       return *this;           
+       maplize(ar, ms);
+       return ms;
 }
 
 
-MapleStream & MapleStream::operator<<(char const * s)
+MapleStream & operator<<(MapleStream & ms, char const * s)
 {
-       os_ << s;
-       return *this;           
+       ms.os() << s;
+       return ms;
 }
 
 
-MapleStream & MapleStream::operator<<(char c)
+MapleStream & operator<<(MapleStream & ms, char c)
 {
-       os_ << c;
-       return *this;           
+       ms.os() << c;
+       return ms;
 }
 
 
-MapleStream & MapleStream::operator<<(int i)
+MapleStream & operator<<(MapleStream & ms, int i)
 {
-       os_ << i;
-       return *this;           
+       ms.os() << i;
+       return ms;
 }
 
 
 //////////////////////////////////////////////////////////////////////
 
 
-OctaveStream & OctaveStream::operator<<(MathInset const * p)
+OctaveStream & operator<<(OctaveStream & ns, MathInset const * p)
 {
        if (p)
-               p->octavize(*this);
+               p->octavize(ns);
        else
-               lyxerr << "MathMLStream::operator<<(NULL) called\n";
-       return *this;           
+               lyxerr << "operator<<(OctaveStream, NULL) called\n";
+       return ns;
 }
 
 
-OctaveStream & OctaveStream::operator<<(MathArray const & ar)
+OctaveStream & operator<<(OctaveStream & ns, MathArray const & ar)
 {
-       octavize(ar, *this);
-       return *this;           
+       octavize(ar, ns);
+       return ns;
 }
 
 
-OctaveStream & OctaveStream::operator<<(char const * s)
+OctaveStream & operator<<(OctaveStream & ns, char const * s)
 {
-       os_ << s;
-       return *this;           
+       ns.os() << s;
+       return ns;
 }
 
 
-OctaveStream & OctaveStream::operator<<(char c)
+OctaveStream & operator<<(OctaveStream & ns, char c)
 {
-       os_ << c;
-       return *this;           
+       ns.os() << c;
+       return ns;
 }
 
 
 //////////////////////////////////////////////////////////////////////
 
 
-NormalStream & NormalStream::operator<<(MathInset const * p)
+NormalStream & operator<<(NormalStream & ns, MathInset const * p)
 {
        if (p)
-               p->normalize(*this);
+               p->normalize(ns);
        else
-               lyxerr << "MathMLStream::operator<<(NULL) called\n";
-       return *this;           
+               lyxerr << "operator<<(NormalStream, NULL) called\n";
+       return ns;
 }
 
 
-NormalStream & NormalStream::operator<<(MathArray const & ar)
+NormalStream & operator<<(NormalStream & ns, MathArray const & ar)
 {
-       normalize(ar, *this);
-       return *this;           
+       normalize(ar, ns);
+       return ns;
 }
 
 
-NormalStream & NormalStream::operator<<(char const * s)
+NormalStream & operator<<(NormalStream & ns, char const * s)
 {
-       os_ << s;
-       return *this;           
+       ns.os() << s;
+       return ns;
 }
 
 
-NormalStream & NormalStream::operator<<(char c)
+NormalStream & operator<<(NormalStream & ns, char c)
 {
-       os_ << c;
-       return *this;           
+       ns.os() << c;
+       return ns;
 }
 
 
@@ -183,76 +183,62 @@ NormalStream & NormalStream::operator<<(char c)
 //////////////////////////////////////////////////////////////////////
 
 
-WriteStream::WriteStream
-               (Buffer const * buffer_, std::ostream & os_, bool fragile_)
-       : buffer(buffer_), os(os_), fragile(fragile_), line_(0)
+WriteStream::WriteStream(std::ostream & os, bool fragile)
+       : os_(os), fragile_(fragile), line_(0)
 {}
 
 
-WriteStream::WriteStream(std::ostream & os_)
-       : buffer(0), os(os_), fragile(false), line_(0)
+WriteStream::WriteStream(std::ostream & os)
+       : os_(os), fragile_(false), line_(0)
 {}
 
 
-WriteStream & WriteStream::operator<<(MathInset const * p)
+WriteStream & operator<<(WriteStream & ws, MathInset const * p)
 {
        if (p)
-               p->write(*this);
+               p->write(ws);
        else
-               lyxerr << "MathMLStream::operator<<(NULL) called\n";
-       return *this;           
+               lyxerr << "operator<<(WriteStream, NULL) called\n";
+       return ws;
 }
 
 
-WriteStream & WriteStream::operator<<(MathArray const & ar)
+WriteStream & operator<<(WriteStream & ws, MathArray const & ar)
 {
-       write(ar, *this);
-       return *this;           
+       write(ar, ws);
+       return ws;
 }
 
 
-WriteStream & WriteStream::operator<<(string const & s)
+WriteStream & operator<<(WriteStream & ws, char const * s)
 {
-       os << s;
-       string::const_iterator cit = s.begin();
-       string::const_iterator end = s.end();
-       for ( ; cit != end ; ++cit) {
-               if (*cit == '\n')
-                       ++line_;
-       }
-       return *this;           
-}
-
-
-WriteStream & WriteStream::operator<<(char const * s)
-{
-       os << s;
+       ws.os() << s;
        for ( ; *s ; ++s) {
                if (*s == '\n')
-                       ++line_;
+                       ++ws.line();
        }
-       return *this;           
+       return ws;
 }
 
 
-WriteStream & WriteStream::operator<<(char c)
+WriteStream & operator<<(WriteStream & ws, char c)
 {
-       os << c;
+       ws.os() << c;
        if (c == '\n')
-               ++line_;
-       return *this;           
+               ++ws.line();
+       return ws;
 }
 
 
-WriteStream & WriteStream::operator<<(int i)
+WriteStream & operator<<(WriteStream & ws, int i)
 {
-       os << i;
-       return *this;           
+       ws.os() << i;
+       return ws;
 }
 
 
-WriteStream & WriteStream::operator<<(unsigned int i)
+WriteStream & operator<<(WriteStream & ws, unsigned int i)
 {
-       os << i;
-       return *this;           
+       ws.os() << i;
+       return ws;
 }
index e2c97008e316dcd4cbe6cf24f88a3b95d3cb34ea..7078efd82aea8ebef577e3871514a4341675395b 100644 (file)
@@ -1,15 +1,20 @@
 #ifndef MATH_MATHMLSTREAM_H
 #define MATH_MATHMLSTREAM_H
 
-#include "LString.h"
 
-#include "support/LOstream.h"
+// Please keep all four streams in one file until the interface has
+// settled.
+
 
 #include <iosfwd>
 
-struct MathArray;
-struct MathInset;
-struct Buffer;
+class MathArray;
+class MathInset;
+
+
+//
+//  MathML
+//
 
 struct MTag {
        ///
@@ -25,24 +30,19 @@ struct ETag {
        char const * const tag_;
 };
 
-struct MathMLStream {
+class MathMLStream {
+public:
        ///
        explicit MathMLStream(std::ostream & os);
        ///
-       MathMLStream & operator<<(MathInset const *);
-       ///
-       MathMLStream & operator<<(MathArray const &);
-       ///
-       MathMLStream & operator<<(char const *);
+       void cr();
        ///
-       MathMLStream & operator<<(char);
+       std::ostream & os() { return os_; }
        ///
-       MathMLStream & operator<<(MTag const &);
+       int & line() { return line_; }
        ///
-       MathMLStream & operator<<(ETag const &);
-       ///
-       void cr();
-
+       int & tab() { return tab_; }
+private:
        ///
        std::ostream & os_;
        ///
@@ -53,89 +53,145 @@ struct MathMLStream {
        char lastchar_;
 };
 
+///
+MathMLStream & operator<<(MathMLStream &, MathInset const *);
+///
+MathMLStream & operator<<(MathMLStream &, MathArray const &);
+///
+MathMLStream & operator<<(MathMLStream &, char const *);
+///
+MathMLStream & operator<<(MathMLStream &, char);
+///
+MathMLStream & operator<<(MathMLStream &, MTag const &);
+///
+MathMLStream & operator<<(MathMLStream &, ETag const &);
+
 
-struct NormalStream {
+
+//
+// Debugging
+//
+
+class NormalStream {
+public:
        ///
        explicit NormalStream(std::ostream & os) : os_(os) {}
        ///
-       std::ostream & os_;
+       std::ostream & os() { return os_; }
+private:
        ///
-       NormalStream & operator<<(MathInset const *);
-       ///
-       NormalStream & operator<<(MathArray const &);
-       ///
-       NormalStream & operator<<(char const *);
-       ///
-       NormalStream & operator<<(char);
+       std::ostream & os_;
 };
 
+///
+NormalStream & operator<<(NormalStream &, MathInset const *);
+///
+NormalStream & operator<<(NormalStream &, MathArray const &);
+///
+NormalStream & operator<<(NormalStream &, char const *);
+///
+NormalStream & operator<<(NormalStream &, char);
+
+
 
-struct MapleStream {
+
+//
+// Maple
+//
+
+
+class MapleStream {
+public:
        ///
        explicit MapleStream(std::ostream & os) : os_(os) {}
        ///
-       std::ostream & os_;
-       ///
-       MapleStream & operator<<(MathInset const *);
-       ///
-       MapleStream & operator<<(MathArray const &);
+       std::ostream & os() { return os_; }
+private:
        ///
-       MapleStream & operator<<(char const *);
-       ///
-       MapleStream & operator<<(char);
-       ///
-       MapleStream & operator<<(int);
+       std::ostream & os_;
 };
 
 
-struct OctaveStream {
+///
+MapleStream & operator<<(MapleStream &, MathInset const *);
+///
+MapleStream & operator<<(MapleStream &, MathArray const &);
+///
+MapleStream & operator<<(MapleStream &, char const *);
+///
+MapleStream & operator<<(MapleStream &, char);
+///
+MapleStream & operator<<(MapleStream &, int);
+
+
+//
+// Octave
+//
+
+
+class OctaveStream {
+public:
        ///
        explicit OctaveStream(std::ostream & os) : os_(os) {}
        ///
-       std::ostream & os_;
-       ///
-       OctaveStream & operator<<(MathInset const *);
+       std::ostream & os() { return os_; }
+private:
        ///
-       OctaveStream & operator<<(MathArray const &);
-       ///
-       OctaveStream & operator<<(char const *);
-       ///
-       OctaveStream & operator<<(char);
+       std::ostream & os_;
 };
 
+///
+OctaveStream & operator<<(OctaveStream &, MathInset const *);
+///
+OctaveStream & operator<<(OctaveStream &, MathArray const &);
+///
+OctaveStream & operator<<(OctaveStream &, char const *);
+///
+OctaveStream & operator<<(OctaveStream &, char);
 
-struct WriteStream {
-       ///
-       WriteStream(Buffer const * buffer_, std::ostream & os_, bool fragile_);
-       ///
-       explicit WriteStream(std::ostream & os_);
 
+
+//
+// LaTeX/LyX
+//
+
+class WriteStream {
+public:
        ///
-       WriteStream & operator<<(MathInset const *);
-       ///
-       WriteStream & operator<<(MathArray const &);
-       ///
-       WriteStream & operator<<(string const &);
-       ///
-       WriteStream & operator<<(char const *);
+       WriteStream(std::ostream & os, bool fragile);
        ///
-       WriteStream & operator<<(char);
+       explicit WriteStream(std::ostream & os_);
+       /// yes... the references will be removed some day...
+       int & line() { return line_; }
        ///
-       WriteStream & operator<<(int);
+       bool fragile() const { return fragile_; }
        ///
-       WriteStream & operator<<(unsigned int);
-
+       std::ostream & os() { return os_; }
        ///
-       Buffer const * buffer;
+       bool & firstitem() { return firstitem_; }
+private:
        ///
-       std::ostream & os;
+       std::ostream & os_;
        ///
-       bool fragile;
+       bool fragile_;
        /// are we at the beginning of an MathArray?
-       bool firstitem;
+       bool firstitem_;
        ///
        int line_;
 };
 
+///
+WriteStream & operator<<(WriteStream &, MathInset const *);
+///
+WriteStream & operator<<(WriteStream &, MathArray const &);
+///
+WriteStream & operator<<(WriteStream &, char const *);
+///
+WriteStream & operator<<(WriteStream &, char);
+///
+WriteStream & operator<<(WriteStream &, int);
+///
+WriteStream & operator<<(WriteStream &, unsigned int);
+
 
 #endif
index ee4a2d67fa52796dc76c1bc3e1eaad8c8c5a9591..69edc1cc9c107078e380e5c11b8f4637a589b623 100644 (file)
@@ -54,7 +54,7 @@ void MathRootInset::draw(Painter & pain, int x, int y) const
        xp[2] = x + w;        yp[2] = y + d;
        xp[3] = x + w - 2;    yp[3] = y + (d - a)/2 + 2;
        xp[4] = x;            yp[4] = y + (d - a)/2 + 2;
-       pain.lines(xp, yp, 5, LColor::mathline);
+       pain.lines(xp, yp, 5, LColor::math);
 }
 
 
index f4559bb69f6412e2759903dd8dbd260185115b2a..ac4b098e78e8f271a4569e6cd7a64a7da5f911df 100644 (file)
@@ -358,7 +358,7 @@ void MathScriptInset::write2(MathInset const * nuc, WriteStream & os) const
                                os << "\\limits ";
                }
        } else
-                       if (os.firstitem)
+                       if (os.firstitem())
                                lyxerr << "suppressing {} \n";
                        else
                                os << "{}";
index 02a0d567b5404cae4adbdce429bc34e7c2c9bb03..1a37210d7895f9202ba7c060347891e93993eb90 100644 (file)
@@ -19,13 +19,13 @@ MathInset * MathSplitInset::clone() const
 }
 
 
-void MathSplitInset::write(WriteStream & os) const
+void MathSplitInset::write(WriteStream & ws) const
 {
-       if (os.fragile)
-               os << "\\protect";
-       os << "\\begin{split}";
-       MathGridInset::write(os);
-       if (os.fragile)
-               os << "\\protect";
-       os << "\\end{split}\n";
+       if (ws.fragile())
+               ws << "\\protect";
+       ws << "\\begin{split}";
+       MathGridInset::write(ws);
+       if (ws.fragile())
+               ws << "\\protect";
+       ws << "\\end{split}\n";
 }
index 65023a12b400cdd9bb317c8d9456aeeb152c5687..684049e769febd9e9c1be11c85c3717befba8101 100644 (file)
@@ -39,7 +39,7 @@ void MathSqrtInset::draw(Painter & pain, int x, int y) const
        xp[1] = x + 8;      yp[1] = y - a + 1;
        xp[2] = x + 5;      yp[2] = y + d - 1;
        xp[3] = x;          yp[3] = y + (d - a)/2;
-       pain.lines(xp, yp, 4, LColor::mathline);
+       pain.lines(xp, yp, 4, LColor::math);
 }
 
 
diff --git a/src/mathed/math_streamstr.h b/src/mathed/math_streamstr.h
new file mode 100644 (file)
index 0000000..bd4d4ef
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef MATH_STREAMSTR_H
+#define MATH_STREAMSTR_H
+
+#include "LString.h"
+#include "math_mathmlstream.h"
+
+//
+// writing strings directly
+//
+
+inline WriteStream & operator<<(WriteStream & ws, string const & s)
+{
+       ws << s.c_str();
+       return ws;
+}
+
+#endif
index f48e9897d2793d4ee39edb7120a0477c22954cde..30f21f4ed522ec6fc89341d92be5a8c4e9f10fbc 100644 (file)
@@ -659,7 +659,7 @@ void mathed_draw_deco(Painter & pain, int x, int y, int w, int h,
                                mt.transform(xx, yy);
                        mt.transform(x2, y2);
                        pain.line(x + int(xx), y + int(yy), x + int(x2), y + int(y2),
-                                       LColor::mathline);
+                                       LColor::math);
                }       else {
                        int xp[32];
                        int yp[32];
@@ -676,7 +676,7 @@ void mathed_draw_deco(Painter & pain, int x, int y, int w, int h,
                                yp[j] = y + int(yy);
                                //  lyxerr << "P[" << j " " << xx << " " << yy << " " << x << " " << y << "]";
                        }
-                       pain.lines(xp, yp, n, LColor::mathline);
+                       pain.lines(xp, yp, n, LColor::math);
                }
        }
 }