3 * The methods .print() are responsible for the nice default-output of
4 * objects. All related helper-functions go in here as well.
6 * GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 void ex::print(ostream & os, unsigned upper_precedence) const
29 debugmsg("ex print",LOGLEVEL_PRINT);
31 bp->print(os,upper_precedence);
34 void ex::dbgprint(void) const
36 debugmsg("ex dbgprint",LOGLEVEL_PRINT);
41 void basic::print(ostream & os, unsigned upper_precedence) const
43 debugmsg("basic print",LOGLEVEL_PRINT);
44 os << "[basic object]";
47 void basic::dbgprint(void) const
53 void symbol::print(ostream & os, unsigned upper_precedence) const
55 debugmsg("symbol print",LOGLEVEL_PRINT);
59 void constant::print(ostream & os, unsigned upper_precedence) const
61 debugmsg("constant print",LOGLEVEL_PRINT);
65 void power::print(ostream & os, unsigned upper_precedence) const
67 debugmsg("power print",LOGLEVEL_PRINT);
69 if (precedence<=upper_precedence) os << "(";
70 basis.print(os,precedence);
72 exponent.print(os,precedence);
73 if (precedence<=upper_precedence) os << ")";
75 os << "pow(" << basis << "," << exponent << ")";
79 void fail::print(ostream & os, unsigned upper_precedence) const
81 debugmsg("fail print",LOGLEVEL_PRINT);
85 void expairseq::printpair(ostream & os, expair const & p, unsigned upper_precedence) const
88 p.rest.bp->print(os,precedence);
90 p.coeff.bp->print(os,precedence);
95 void expairseq::printseq(ostream & os, char delim, unsigned this_precedence,
96 unsigned upper_precedence) const
98 if (this_precedence<=upper_precedence) os << "(";
99 epvector::const_iterator itt,it,it_last,it_start;
102 it_start=seq.begin();
106 for (it=seq.begin(); it!=it_last; ++it) {
108 expair const & k = *itt;
109 printpair(os,*it, this_precedence);
110 if (((is_ex_of_type(k.rest, numeric)) && (k.coeff*k.rest > 0) ) || ((!is_ex_of_type(k.rest, numeric)) && (k.coeff >0))){
114 printpair(os,*it,this_precedence);
118 for (it = it_last ; it!=it_start; --it) {
119 if ((*it).rest.is_equal(exMINUSONE()) &&
120 (*it).coeff.is_equal(exONE())) {
123 printpair(os, *it,this_precedence);
127 printpair(os,*it,this_precedence);
130 clog << "Nobody expects the Spanish Inquisition: "
131 << "deliminator unknown!" << endl;
133 if (this_precedence<=upper_precedence) os << ")";
137 void expairseq::printseq(ostream & os, char delim, unsigned this_precedence,
138 unsigned upper_precedence) const
140 if (this_precedence<=upper_precedence) os << "(";
141 epvector::const_iterator it,it_last;
144 for (it=seq.begin(); it!=it_last; ++it) {
145 printpair(os,*it,this_precedence);
148 printpair(os,*it,this_precedence);
149 if (!overall_coeff.is_equal(default_overall_coeff())) {
150 os << delim << overall_coeff;
152 if (this_precedence<=upper_precedence) os << ")";
155 void expairseq::print(ostream & os, unsigned upper_precedence) const
157 debugmsg("expairseq print",LOGLEVEL_PRINT);
159 printseq(os,',',precedence,upper_precedence);
163 void add::printpair(ostream & os, expair const & p, unsigned upper_precedence) const
178 void add::print(ostream & os, unsigned upper_precedence) const
180 debugmsg("add print",LOGLEVEL_PRINT);
181 if (precedence<=upper_precedence) os << "(";
183 for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
185 if (cit->coeff > 0) os << '+';
189 if (cit->coeff == -1) {
192 if (cit->coeff != 1) {
193 (cit->coeff).print(os,precedence);
199 if (!overall_coeff.is_zero()) {
200 if (overall_coeff > 0) os << '+';
203 if (precedence<=upper_precedence) os << ")";
206 void mul::printpair(ostream & os, expair const & p, unsigned upper_precedence) const
209 if (p.coeff.compare(exONE())==0) {
210 p.rest.print(os,upper_precedence);
212 // outer parens around ex needed for broken gcc-2.95 parser:
213 (ex(power(p.rest,p.coeff))).print(os,upper_precedence);
218 void mul::print(ostream & os, unsigned upper_precedence) const
220 debugmsg("mul print",LOGLEVEL_PRINT);
221 if (precedence<=upper_precedence) os << "(";
223 if (!overall_coeff.is_equal(exONE())) {
224 overall_coeff.print(os,precedence);
227 for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
233 recombine_pair_to_ex(*cit).print(os,precedence);
235 if (precedence<=upper_precedence) os << ")";
238 void ncmul::print(ostream & os, unsigned upper_precedence) const
240 debugmsg("ncmul print",LOGLEVEL_PRINT);
241 printseq(os,'(','%',')',precedence,upper_precedence);
244 /*void function::print(ostream & os, unsigned upper_precedence) const
246 * debugmsg("function print",LOGLEVEL_PRINT);
248 * printseq(os,'(',',',')',exprseq::precedence,function::precedence);
251 void series::print(ostream &os, unsigned upper_precedence) const
253 debugmsg("symbol print", LOGLEVEL_PRINT);
254 convert_to_poly().print(os, upper_precedence);
257 void relational::print(ostream & os, unsigned upper_precedence) const
259 debugmsg("relational print",LOGLEVEL_PRINT);
260 if (precedence<=upper_precedence) os << "(";
261 lh.print(os,precedence);
278 case greater_or_equal:
282 os << "(INVALID RELATIONAL OPERATOR)";
284 rh.print(os,precedence);
285 if (precedence<=upper_precedence) os << ")";
288 void matrix::print(ostream & os, unsigned upper_precedence) const
290 debugmsg("matrix print",LOGLEVEL_PRINT);
292 for (int r=0; r<row-1; ++r) {
294 for (int c=0; c<col-1; ++c) {
295 os << m[r*col+c] << ",";
297 os << m[col*(r+1)-1] << "]], ";
300 for (int c=0; c<col-1; ++c) {
301 os << m[(row-1)*col+c] << ",";
303 os << m[row*col-1] << "]] ]]";