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
19 #define RESERVE(s,size) // no reserve needed for list
22 // default constructor, destructor, copy constructor assignment operator and helpers
27 lst::lst() : basic(TINFO_LST)
29 debugmsg("lst default constructor",LOGLEVEL_CONSTRUCT);
34 debugmsg("lst destructor",LOGLEVEL_DESTRUCT);
38 lst::lst(lst const & other)
40 debugmsg("lst copy constructor",LOGLEVEL_CONSTRUCT);
44 lst const & lst::operator=(lst const & other)
46 debugmsg("lst operator=",LOGLEVEL_ASSIGNMENT);
56 void lst::copy(lst const & other)
62 void lst::destroy(bool call_parent)
65 if (call_parent) basic::destroy(call_parent);
74 lst::lst(exlist const & s, bool discardable) : basic(TINFO_LST)
76 debugmsg("lst constructor from exlist",
79 seq.swap(const_cast<exlist &>(s));
85 lst::lst(exlist * vp) : basic(TINFO_LST)
87 debugmsg("lst constructor from exlist *",LOGLEVEL_CONSTRUCT);
93 lst::lst(ex const & e1) : basic(TINFO_LST)
95 debugmsg("lst constructor from 1 ex",
101 lst::lst(ex const & e1, ex const & e2) : basic(TINFO_LST)
103 debugmsg("lst constructor from 2 ex",
110 lst::lst(ex const & e1, ex const & e2, ex const & e3)
113 debugmsg("lst constructor from 3 ex",
121 lst::lst(ex const & e1, ex const & e2, ex const & e3,
122 ex const & e4) : basic(TINFO_LST)
124 debugmsg("lst constructor from 4 ex",
133 lst::lst(ex const & e1, ex const & e2, ex const & e3,
134 ex const & e4, ex const & e5) : basic(TINFO_LST)
136 debugmsg("lst constructor from 5 ex",
146 lst::lst(ex const & e1, ex const & e2, ex const & e3,
147 ex const & e4, ex const & e5, ex const & e6)
150 debugmsg("lst constructor from 6 ex",
161 lst::lst(ex const & e1, ex const & e2, ex const & e3,
162 ex const & e4, ex const & e5, ex const & e6,
163 ex const & e7) : basic(TINFO_LST)
165 debugmsg("lst constructor from 7 ex",
177 lst::lst(ex const & e1, ex const & e2, ex const & e3,
178 ex const & e4, ex const & e5, ex const & e6,
179 ex const & e7, ex const & e8) : basic(TINFO_LST)
181 debugmsg("lst constructor from 8 ex",
194 lst::lst(ex const & e1, ex const & e2, ex const & e3,
195 ex const & e4, ex const & e5, ex const & e6,
196 ex const & e7, ex const & e8, ex const & e9)
199 debugmsg("lst constructor from 9 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,
219 debugmsg("lst constructor from 10 ex",
235 // functions overriding virtual functions from bases classes
240 basic * lst::duplicate() const
242 debugmsg("lst duplicate",LOGLEVEL_DUPLICATE);
243 return new lst(*this);
246 void lst::printraw(ostream & os) const
248 debugmsg("lst printraw",LOGLEVEL_PRINT);
251 for (exlist::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
252 (*cit).bp->printraw(os);
258 void lst::print(ostream & os, unsigned upper_precedence) const
260 debugmsg("lst print",LOGLEVEL_PRINT);
261 // always print brackets around seq, ignore upper_precedence
262 printseq(os,'[',',',']',precedence,precedence+1);
265 void lst::printtree(ostream & os, unsigned indent) const
267 debugmsg("lst printtree",LOGLEVEL_PRINT);
269 os << string(indent,' ') << "type=" << typeid(*this).name()
270 << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
271 << ", flags=" << flags
272 << ", nops=" << nops() << endl;
273 for (exlist::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
274 (*cit).printtree(os,indent+delta_indent);
276 os << string(indent+delta_indent,' ') << "=====" << endl;
279 // lst::info() will be implemented by user elsewhere";
281 int lst::nops() const
286 ex & lst::let_op(int const i)
291 exlist::iterator it=seq.begin();
292 for (int j=0; j<i; j++) {
299 ex lst::expand(unsigned options) const
302 RESERVE(s,seq.size());
303 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
304 s.push_back((*it).expand(options));
310 // a lst 'has' an expression if it is this expression itself or a child 'has' it
312 bool lst::has(ex const & other) const
315 if (is_equal(*other.bp)) return true;
316 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
317 if ((*it).has(other)) return true;
322 ex lst::eval(int level) const
327 return thislst(evalchildren(level));
330 ex lst::evalf(int level) const
332 return thislst(evalfchildren(level));
335 /** Implementation of ex::normal() for lsts. It normalizes the arguments
336 * and replaces the lst by a temporary symbol.
338 ex lst::normal(lst &sym_lst, lst &repl_lst, int level) const
340 ex n=thislst(normalchildren(level));
341 return n.bp->basic::normal(sym_lst,repl_lst,level);
344 ex lst::diff(symbol const & s) const
346 return thislst(diffchildren(s));
349 ex lst::subs(lst const & ls, lst const & lr) const
351 exlist * vp=subschildren(ls,lr);
360 int lst::compare_same_type(basic const & other) const
362 ASSERT(is_of_type(other,lst));
363 lst const & o=static_cast<lst const &>
364 (const_cast<basic &>(other));
366 exlist::const_iterator it1=seq.begin();
367 exlist::const_iterator it2=o.seq.begin();
369 for (; (it1!=seq.end())&&(it2!=o.seq.end()); ++it1, ++it2) {
370 cmpval=(*it1).compare(*it2);
371 if (cmpval!=0) return cmpval;
374 if (it1==seq.end()) {
375 return (it2==o.seq.end() ? 0 : -1);
381 bool lst::is_equal_same_type(basic const & other) const
383 ASSERT(is_of_type(other,lst));
384 lst const & o=static_cast<lst const &>
385 (const_cast<basic &>(other));
386 if (seq.size()!=o.seq.size()) return false;
388 exlist::const_iterator it1=seq.begin();
389 exlist::const_iterator it2=o.seq.begin();
391 for (; it1!=seq.end(); ++it1, ++it2) {
392 if (!(*it1).is_equal(*it2)) return false;
398 unsigned lst::return_type(void) const
400 return return_types::noncommutative_composite;
404 // new virtual functions which can be overridden by derived classes
409 lst & lst::append(ex const & b)
411 ensure_if_modifiable();
416 lst & lst::prepend(ex const & b)
418 ensure_if_modifiable();
426 void lst::printseq(ostream & os, char openbracket, char delim,
427 char closebracket, unsigned this_precedence,
428 unsigned upper_precedence) const
430 if (this_precedence<=upper_precedence) os << openbracket;
432 exlist::const_iterator it,it_last;
436 for (; it!=it_last; ++it) {
437 (*it).bp->print(os,this_precedence);
440 (*it).bp->print(os,this_precedence);
442 if (this_precedence<=upper_precedence) os << closebracket;
445 ex lst::thislst(exlist const & v) const
450 ex lst::thislst(exlist * vp) const
456 // non-virtual functions in this class
465 bool lst::is_canonical() const
467 if (seq.size()<=1) { return 1; }
469 exlist::const_iterator it=seq.begin();
470 exlist::const_iterator it_last=it;
471 for (++it; it!=seq.end(); it_last=it, ++it) {
472 if ((*it_last).compare(*it)>0) {
473 if ((*it_last).compare(*it)>0) {
474 cout << *it_last << ">" << *it << "\n";
483 exlist lst::evalchildren(int level) const
486 RESERVE(s,seq.size());
491 if (level == -max_recursion_level) {
492 throw(std::runtime_error("max recursion level reached"));
495 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
496 s.push_back((*it).eval(level));
501 exlist lst::evalfchildren(int level) const
504 RESERVE(s,seq.size());
509 if (level == -max_recursion_level) {
510 throw(std::runtime_error("max recursion level reached"));
513 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
514 s.push_back((*it).evalf(level));
519 exlist lst::normalchildren(int level) const
522 RESERVE(s,seq.size());
527 if (level == -max_recursion_level) {
528 throw(std::runtime_error("max recursion level reached"));
531 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
532 s.push_back((*it).normal(level));
537 exlist lst::diffchildren(symbol const & y) const
540 RESERVE(s,seq.size());
541 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
542 s.push_back((*it).diff(y));
547 /* obsolete subschildren
548 exlist lst::subschildren(lst const & ls, lst const & lr) const
551 RESERVE(s,seq.size());
552 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
553 s.push_back((*it).subs(ls,lr));
559 exlist * lst::subschildren(lst const & ls, lst const & lr) const
561 // returns a NULL pointer if nothing had to be substituted
562 // returns a pointer to a newly created epvector otherwise
563 // (which has to be deleted somewhere else)
565 exlist::const_iterator last=seq.end();
566 exlist::const_iterator cit=seq.begin();
568 ex const & subsed_ex=(*cit).subs(ls,lr);
569 if (!are_ex_trivially_equal(*cit,subsed_ex)) {
571 // something changed, copy seq, subs and return it
572 exlist *s=new exlist;
573 RESERVE(*s,seq.size());
575 // copy parts of seq which are known not to have changed
576 exlist::const_iterator cit2=seq.begin();
581 // copy first changed element
582 s->push_back(subsed_ex);
586 s->push_back((*cit2).subs(ls,lr));
594 return 0; // nothing has changed
598 // static member variables
603 unsigned lst::precedence=10;
610 type_info const & typeid_lst=typeid(some_lst);