3 * Implementation of GiNaC's lst.
4 * This file was generated automatically by container.pl.
5 * Please do not modify it directly, edit the perl script instead!
6 * container.pl options: $CONTAINER=lst
15 * GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38 #define RESERVE(s,size) // no reserve needed for list
41 // default constructor, destructor, copy constructor assignment operator and helpers
46 lst::lst() : basic(TINFO_lst)
48 debugmsg("lst default constructor",LOGLEVEL_CONSTRUCT);
53 debugmsg("lst destructor",LOGLEVEL_DESTRUCT);
57 lst::lst(lst const & other)
59 debugmsg("lst copy constructor",LOGLEVEL_CONSTRUCT);
63 lst const & lst::operator=(lst const & other)
65 debugmsg("lst operator=",LOGLEVEL_ASSIGNMENT);
75 void lst::copy(lst const & other)
81 void lst::destroy(bool call_parent)
84 if (call_parent) basic::destroy(call_parent);
93 lst::lst(exlist const & s, bool discardable) : basic(TINFO_lst)
95 debugmsg("lst constructor from exlist",
98 seq.swap(const_cast<exlist &>(s));
104 lst::lst(exlist * vp) : basic(TINFO_lst)
106 debugmsg("lst constructor from exlist *",LOGLEVEL_CONSTRUCT);
112 lst::lst(ex const & e1) : basic(TINFO_lst)
114 debugmsg("lst constructor from 1 ex",
120 lst::lst(ex const & e1, ex const & e2) : basic(TINFO_lst)
122 debugmsg("lst constructor from 2 ex",
129 lst::lst(ex const & e1, ex const & e2, ex const & e3)
132 debugmsg("lst constructor from 3 ex",
140 lst::lst(ex const & e1, ex const & e2, ex const & e3,
141 ex const & e4) : basic(TINFO_lst)
143 debugmsg("lst constructor from 4 ex",
152 lst::lst(ex const & e1, ex const & e2, ex const & e3,
153 ex const & e4, ex const & e5) : basic(TINFO_lst)
155 debugmsg("lst constructor from 5 ex",
165 lst::lst(ex const & e1, ex const & e2, ex const & e3,
166 ex const & e4, ex const & e5, ex const & e6)
169 debugmsg("lst constructor from 6 ex",
180 lst::lst(ex const & e1, ex const & e2, ex const & e3,
181 ex const & e4, ex const & e5, ex const & e6,
182 ex const & e7) : basic(TINFO_lst)
184 debugmsg("lst constructor from 7 ex",
196 lst::lst(ex const & e1, ex const & e2, ex const & e3,
197 ex const & e4, ex const & e5, ex const & e6,
198 ex const & e7, ex const & e8) : basic(TINFO_lst)
200 debugmsg("lst constructor from 8 ex",
213 lst::lst(ex const & e1, ex const & e2, ex const & e3,
214 ex const & e4, ex const & e5, ex const & e6,
215 ex const & e7, ex const & e8, ex const & e9)
218 debugmsg("lst constructor from 9 ex",
232 lst::lst(ex const & e1, ex const & e2, ex const & e3,
233 ex const & e4, ex const & e5, ex const & e6,
234 ex const & e7, ex const & e8, ex const & e9,
238 debugmsg("lst constructor from 10 ex",
254 // functions overriding virtual functions from bases classes
259 basic * lst::duplicate() const
261 debugmsg("lst duplicate",LOGLEVEL_DUPLICATE);
262 return new lst(*this);
265 void lst::printraw(ostream & os) const
267 debugmsg("lst printraw",LOGLEVEL_PRINT);
270 for (exlist::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
271 (*cit).bp->printraw(os);
277 void lst::print(ostream & os, unsigned upper_precedence) const
279 debugmsg("lst print",LOGLEVEL_PRINT);
280 // always print brackets around seq, ignore upper_precedence
281 printseq(os,'[',',',']',precedence,precedence+1);
284 void lst::printtree(ostream & os, unsigned indent) const
286 debugmsg("lst printtree",LOGLEVEL_PRINT);
288 os << string(indent,' ') << "type=" << typeid(*this).name()
289 << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
290 << ", flags=" << flags
291 << ", nops=" << nops() << endl;
292 for (exlist::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
293 (*cit).printtree(os,indent+delta_indent);
295 os << string(indent+delta_indent,' ') << "=====" << endl;
298 // lst::info() will be implemented by user elsewhere";
300 int lst::nops() const
305 ex & lst::let_op(int const i)
310 exlist::iterator it=seq.begin();
311 for (int j=0; j<i; j++) {
318 ex lst::expand(unsigned options) const
321 RESERVE(s,seq.size());
322 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
323 s.push_back((*it).expand(options));
329 // a lst 'has' an expression if it is this expression itself or a child 'has' it
331 bool lst::has(ex const & other) const
334 if (is_equal(*other.bp)) return true;
335 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
336 if ((*it).has(other)) return true;
341 ex lst::eval(int level) const
346 return thislst(evalchildren(level));
349 ex lst::evalf(int level) const
351 return thislst(evalfchildren(level));
354 /** Implementation of ex::normal() for lsts. It normalizes the arguments
355 * and replaces the lst by a temporary symbol.
357 ex lst::normal(lst &sym_lst, lst &repl_lst, int level) const
359 ex n=thislst(normalchildren(level));
360 return n.bp->basic::normal(sym_lst,repl_lst,level);
363 ex lst::diff(symbol const & s) const
365 return thislst(diffchildren(s));
368 ex lst::subs(lst const & ls, lst const & lr) const
370 exlist * vp=subschildren(ls,lr);
379 int lst::compare_same_type(basic const & other) const
381 ASSERT(is_of_type(other,lst));
382 lst const & o=static_cast<lst const &>
383 (const_cast<basic &>(other));
385 exlist::const_iterator it1=seq.begin();
386 exlist::const_iterator it2=o.seq.begin();
388 for (; (it1!=seq.end())&&(it2!=o.seq.end()); ++it1, ++it2) {
389 cmpval=(*it1).compare(*it2);
390 if (cmpval!=0) return cmpval;
393 if (it1==seq.end()) {
394 return (it2==o.seq.end() ? 0 : -1);
400 bool lst::is_equal_same_type(basic const & other) const
402 ASSERT(is_of_type(other,lst));
403 lst const & o=static_cast<lst const &>
404 (const_cast<basic &>(other));
405 if (seq.size()!=o.seq.size()) return false;
407 exlist::const_iterator it1=seq.begin();
408 exlist::const_iterator it2=o.seq.begin();
410 for (; it1!=seq.end(); ++it1, ++it2) {
411 if (!(*it1).is_equal(*it2)) return false;
417 unsigned lst::return_type(void) const
419 return return_types::noncommutative_composite;
423 // new virtual functions which can be overridden by derived classes
428 lst & lst::append(ex const & b)
430 ensure_if_modifiable();
435 lst & lst::prepend(ex const & b)
437 ensure_if_modifiable();
445 void lst::printseq(ostream & os, char openbracket, char delim,
446 char closebracket, unsigned this_precedence,
447 unsigned upper_precedence) const
449 if (this_precedence<=upper_precedence) os << openbracket;
451 exlist::const_iterator it,it_last;
455 for (; it!=it_last; ++it) {
456 (*it).bp->print(os,this_precedence);
459 (*it).bp->print(os,this_precedence);
461 if (this_precedence<=upper_precedence) os << closebracket;
464 ex lst::thislst(exlist const & v) const
469 ex lst::thislst(exlist * vp) const
475 // non-virtual functions in this class
484 bool lst::is_canonical() const
486 if (seq.size()<=1) { return 1; }
488 exlist::const_iterator it=seq.begin();
489 exlist::const_iterator it_last=it;
490 for (++it; it!=seq.end(); it_last=it, ++it) {
491 if ((*it_last).compare(*it)>0) {
492 if ((*it_last).compare(*it)>0) {
493 cout << *it_last << ">" << *it << "\n";
502 exlist lst::evalchildren(int level) const
505 RESERVE(s,seq.size());
510 if (level == -max_recursion_level) {
511 throw(std::runtime_error("max recursion level reached"));
514 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
515 s.push_back((*it).eval(level));
520 exlist lst::evalfchildren(int level) const
523 RESERVE(s,seq.size());
528 if (level == -max_recursion_level) {
529 throw(std::runtime_error("max recursion level reached"));
532 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
533 s.push_back((*it).evalf(level));
538 exlist lst::normalchildren(int level) const
541 RESERVE(s,seq.size());
546 if (level == -max_recursion_level) {
547 throw(std::runtime_error("max recursion level reached"));
550 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
551 s.push_back((*it).normal(level));
556 exlist lst::diffchildren(symbol const & y) const
559 RESERVE(s,seq.size());
560 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
561 s.push_back((*it).diff(y));
566 /* obsolete subschildren
567 exlist lst::subschildren(lst const & ls, lst const & lr) const
570 RESERVE(s,seq.size());
571 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
572 s.push_back((*it).subs(ls,lr));
578 exlist * lst::subschildren(lst const & ls, lst const & lr) const
580 // returns a NULL pointer if nothing had to be substituted
581 // returns a pointer to a newly created epvector otherwise
582 // (which has to be deleted somewhere else)
584 exlist::const_iterator last=seq.end();
585 exlist::const_iterator cit=seq.begin();
587 ex const & subsed_ex=(*cit).subs(ls,lr);
588 if (!are_ex_trivially_equal(*cit,subsed_ex)) {
590 // something changed, copy seq, subs and return it
591 exlist *s=new exlist;
592 RESERVE(*s,seq.size());
594 // copy parts of seq which are known not to have changed
595 exlist::const_iterator cit2=seq.begin();
600 // copy first changed element
601 s->push_back(subsed_ex);
605 s->push_back((*cit2).subs(ls,lr));
613 return 0; // nothing has changed
617 // static member variables
622 unsigned lst::precedence=10;
629 type_info const & typeid_lst=typeid(some_lst);