From: André Pönitz Date: Mon, 3 Dec 2001 16:24:50 +0000 (+0000) Subject: make operator<<(*stream, ...) free functions; X-Git-Tag: 1.6.10~20238 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=aed2b1804c474ad4927a681c708b45bee6c4a36f;p=features.git make operator<<(*stream, ...) free functions; 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 --- diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index 31e82e7319..b077bc6cb2 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -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 \ diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 0b14506d4f..b0bc0c7621 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -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; } diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index 6f796ceea8..46287d7d66 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -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); diff --git a/src/mathed/formulamacro.C b/src/mathed/formulamacro.C index 93b0689b47..4e6739ffb7 100644 --- a/src/mathed/formulamacro.C +++ b/src/mathed/formulamacro.C @@ -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; } diff --git a/src/mathed/math_arrayinset.C b/src/mathed/math_arrayinset.C index c0ed8a273f..2c6da9506c 100644 --- a/src/mathed/math_arrayinset.C +++ b/src/mathed/math_arrayinset.C @@ -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"; } diff --git a/src/mathed/math_casesinset.C b/src/mathed/math_casesinset.C index 183e955060..7077507e7c 100644 --- a/src/mathed/math_casesinset.C +++ b/src/mathed/math_casesinset.C @@ -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"; } diff --git a/src/mathed/math_charinset.C b/src/mathed/math_charinset.C index 417078bd6d..b89280fce2 100644 --- a/src/mathed/math_charinset.C +++ b/src/mathed/math_charinset.C @@ -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()); } diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 127316be10..0d70e911ce 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -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"); diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index bea6dcfce5..f38125aa45 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -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(); diff --git a/src/mathed/math_decorationinset.C b/src/mathed/math_decorationinset.C index 08762d17b7..977308b8fa 100644 --- a/src/mathed/math_decorationinset.C +++ b/src/mathed/math_decorationinset.C @@ -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) << '}'; } diff --git a/src/mathed/math_extern.C b/src/mathed/math_extern.C index 3d7593540d..6751dd405a 100644 --- a/src/mathed/math_extern.C +++ b/src/mathed/math_extern.C @@ -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)) { diff --git a/src/mathed/math_fracinset.C b/src/mathed/math_fracinset.C index 1799838dac..c1f8f23ff4 100644 --- a/src/mathed/math_fracinset.C +++ b/src/mathed/math_fracinset.C @@ -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); } diff --git a/src/mathed/math_gridinset.C b/src/mathed/math_gridinset.C index 51668da8f8..893c5a06c2 100644 --- a/src/mathed/math_gridinset.C +++ b/src/mathed/math_gridinset.C @@ -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" diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index 320d03f269..ee98f69901 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -28,14 +28,6 @@ #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); } diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 5a9c294e56..ca568a3ed8 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -31,10 +31,18 @@ #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; diff --git a/src/mathed/math_mathmlstream.C b/src/mathed/math_mathmlstream.C index 35b2b9ae99..f4e9ad4f92 100644 --- a/src/mathed/math_mathmlstream.C +++ b/src/mathed/math_mathmlstream.C @@ -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_ << "'; - return *this; + ms.cr(); + if (ms.tab() > 0) + --ms.tab(); + ms.os() << "'; + 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; } diff --git a/src/mathed/math_mathmlstream.h b/src/mathed/math_mathmlstream.h index e2c97008e3..7078efd82a 100644 --- a/src/mathed/math_mathmlstream.h +++ b/src/mathed/math_mathmlstream.h @@ -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 -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 diff --git a/src/mathed/math_rootinset.C b/src/mathed/math_rootinset.C index ee4a2d67fa..69edc1cc9c 100644 --- a/src/mathed/math_rootinset.C +++ b/src/mathed/math_rootinset.C @@ -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); } diff --git a/src/mathed/math_scriptinset.C b/src/mathed/math_scriptinset.C index f4559bb69f..ac4b098e78 100644 --- a/src/mathed/math_scriptinset.C +++ b/src/mathed/math_scriptinset.C @@ -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 << "{}"; diff --git a/src/mathed/math_splitinset.C b/src/mathed/math_splitinset.C index 02a0d567b5..1a37210d78 100644 --- a/src/mathed/math_splitinset.C +++ b/src/mathed/math_splitinset.C @@ -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"; } diff --git a/src/mathed/math_sqrtinset.C b/src/mathed/math_sqrtinset.C index 65023a12b4..684049e769 100644 --- a/src/mathed/math_sqrtinset.C +++ b/src/mathed/math_sqrtinset.C @@ -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 index 0000000000..bd4d4ef66d --- /dev/null +++ b/src/mathed/math_streamstr.h @@ -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 diff --git a/src/mathed/math_support.C b/src/mathed/math_support.C index f48e9897d2..30f21f4ed5 100644 --- a/src/mathed/math_support.C +++ b/src/mathed/math_support.C @@ -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); } } }