X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fcontainer.pl;h=af9d5372ba4616cb441ed5c399a090c776fd490c;hp=0ef3b896d47908f8c4355b1a86637b75c9120d59;hb=f7a07ae7330a3543bb00aa7b659e2624d6c440c7;hpb=083b0f50275a536be807fa2a34c1e278098e12f5 diff --git a/ginac/container.pl b/ginac/container.pl index 0ef3b896..af9d5372 100755 --- a/ginac/container.pl +++ b/ginac/container.pl @@ -1,90 +1,142 @@ -#!/usr/bin/perl -w - -if ($#ARGV!=0) { - die 'usage: container.pl type (type=lst or exprseq)'; +if (($#ARGV!=0) and ($#ARGV!=1)) { + die 'usage: container.pl type [maxargs] (type=lst or exprseq)'; } if ($ARGV[0] eq 'lst') { - $type='lst'; + $type='lst'; } elsif ($ARGV[0] eq 'exprseq') { - $type='exprseq'; + $type='exprseq'; } else { - die 'only lst and exprseq supported'; + die 'only lst and exprseq supported'; } -#$type='lst'; -#$type='exprseq'; +if ($#ARGV==1) { + $maxargs=$ARGV[1]; +} else { + $maxargs=15; # must be greater or equal than the value used in function.pl +} if ($type eq 'exprseq') { - # settings for exprseq - $CONTAINER="exprseq"; - $STLHEADER="vector"; - $reserve=1; - $prepend=0; - $let_op=0; - $open_bracket='('; - $close_bracket=')'; - + # settings for exprseq + $CONTAINER="exprseq"; + $STLHEADER="vector"; + $reserve=1; + $prepend=0; + $let_op=0; + $open_bracket='('; + $close_bracket=')'; + } elsif ($type eq 'lst') { - # settings for lst - $CONTAINER="lst"; - $STLHEADER="list"; - $reserve=0; - $prepend=1; - $let_op=1; - $open_bracket='['; - $close_bracket=']'; + # settings for lst + $CONTAINER="lst"; + $STLHEADER="list"; + $reserve=0; + $prepend=1; + $let_op=1; + $open_bracket='['; + $close_bracket=']'; } else { - die "invalid type $type"; + die "invalid type $type"; } $CONTAINER_UC=uc(${CONTAINER}); $STLT="ex".$STLHEADER; if ($reserve) { - $RESERVE_IMPLEMENTATION="#define RESERVE(s,size) (s).reserve(size)"; + $RESERVE_IMPLEMENTATION="#define RESERVE(s,size) (s).reserve(size)"; } else { - $RESERVE_IMPLEMENTATION="#define RESERVE(s,size) // no reserve needed for ${STLHEADER}"; + $RESERVE_IMPLEMENTATION="#define RESERVE(s,size) // no reserve needed for ${STLHEADER}"; } if ($prepend) { - $PREPEND_INTERFACE=<=0); - GINAC_ASSERT(i=0); + GINAC_ASSERT(i ${STLT}; -typedef ${STLHEADER} ${STLT}; // CINT does not like ${STLHEADER}<...,default_alloc> + +// Cint currently does not like ${STLHEADER}<..,default_alloc> but malloc_alloc is +// unstandardized and not supported by newer GCCs. This ugly hack will go +// away soon! +#if (defined(__GNUC__) && (__GNUC__ == 2) && (__GNUC_MINOR__ < 97)) || (defined(G__GNUC) && (G__GNUC == 2) && (G__GNUC_MINOR < 97)) +typedef std::${STLHEADER} ${STLT}; +#else +typedef std::${STLHEADER} ${STLT}; +#endif class ${CONTAINER} : public basic { - GINAC_DECLARE_REGISTERED_CLASS(${CONTAINER}, basic) - -public: - ${CONTAINER}(); - ~${CONTAINER}(); - ${CONTAINER}(${CONTAINER} const & other); - ${CONTAINER} const & operator=(${CONTAINER} const & other); -protected: - void copy(${CONTAINER} const & other); - void destroy(bool call_parent); + GINAC_DECLARE_REGISTERED_CLASS(${CONTAINER}, basic) public: - ${CONTAINER}(${STLT} const & s, bool discardable=0); - ${CONTAINER}(${STLT} * vp); // vp will be deleted - explicit ${CONTAINER}(const ex & e1); - explicit ${CONTAINER}(const ex & e1, const ex & e2); - explicit ${CONTAINER}(const ex & e1, const ex & e2, const ex & e3); - explicit ${CONTAINER}(const ex & e1, const ex & e2, const ex & e3, - const ex & e4); - explicit ${CONTAINER}(const ex & e1, const ex & e2, const ex & e3, - const ex & e4, const ex & e5); - explicit ${CONTAINER}(const ex & e1, const ex & e2, const ex & e3, - const ex & e4, const ex & e5, const ex & e6); - explicit ${CONTAINER}(const ex & e1, const ex & e2, const ex & e3, - const ex & e4, const ex & e5, const ex & e6, - const ex & e7); - explicit ${CONTAINER}(const ex & e1, const ex & e2, const ex & e3, - const ex & e4, const ex & e5, const ex & e6, - const ex & e7, const ex & e8); - explicit ${CONTAINER}(const ex & e1, const ex & e2, const ex & e3, - const ex & e4, const ex & e5, const ex & e6, - const ex & e7, const ex & e8, const ex & e9); - explicit ${CONTAINER}(const ex & e1, const ex & e2, const ex & e3, - const ex & e4, const ex & e5, const ex & e6, - const ex & e7, const ex & e8, const ex & e9, - const ex &e10); + ${CONTAINER}(${STLT} const & s, bool discardable=0); + ${CONTAINER}(${STLT} * vp); // vp will be deleted +${constructors_interface} public: - basic * duplicate() const; - void printraw(ostream & os) const; - void print(ostream & os, unsigned upper_precedence=0) const; - void printtree(ostream & os, unsigned indent) const; - bool info(unsigned inf) const; - unsigned nops() const; - ex & let_op(int i); - ex expand(unsigned options=0) const; - bool has(const ex & other) const; - ex eval(int level=0) const; - ex evalf(int level=0) const; - ex normal(lst &sym_lst, lst &repl_lst, int level=0) const; - ex derivative(const symbol & s) const; - ex subs(const lst & ls, const lst & lr) const; + void print(const print_context & c, unsigned level = 0) const; + bool info(unsigned inf) const; + unsigned nops() const; + ex & let_op(int i); + ex expand(unsigned options=0) const; + bool has(const ex & other) const; + ex eval(int level=0) const; + ex evalf(int level=0) const; + ex normal(lst &sym_lst, lst &repl_lst, int level=0) const; + ex derivative(const symbol & s) const; + ex subs(const lst & ls, const lst & lr) const; protected: - int compare_same_type(const basic & other) const; - bool is_equal_same_type(const basic & other) const; - unsigned return_type(void) const; + bool is_equal_same_type(const basic & other) const; + unsigned return_type(void) const; - // new virtual functions which can be overridden by derived classes + // new virtual functions which can be overridden by derived classes public: - virtual ${CONTAINER} & append(const ex & b); + virtual ${CONTAINER} & append(const ex & b); ${PREPEND_INTERFACE} protected: - virtual void printseq(ostream & os, char openbracket, char delim, - char closebracket, unsigned this_precedence, - unsigned upper_precedence=0) const; - virtual ex this${CONTAINER}(${STLT} const & v) const; - virtual ex this${CONTAINER}(${STLT} * vp) const; + virtual void printseq(const print_context & c, char openbracket, char delim, + char closebracket, unsigned this_precedence, + unsigned upper_precedence = 0) const; + virtual ex this${CONTAINER}(${STLT} const & v) const; + virtual ex this${CONTAINER}(${STLT} * vp) const; protected: - bool is_canonical() const; - ${STLT} evalchildren(int level) const; - ${STLT} evalfchildren(int level) const; - ${STLT} normalchildren(int level) const; - ${STLT} diffchildren(const symbol & s) const; - ${STLT} * subschildren(const lst & ls, const lst & lr) const; + bool is_canonical() const; + ${STLT} evalchildren(int level) const; + ${STLT} evalfchildren(int level) const; + ${STLT} normalchildren(int level) const; + ${STLT} diffchildren(const symbol & s) const; + ${STLT} * subschildren(const lst & ls, const lst & lr) const; protected: - ${STLT} seq; - static unsigned precedence; + ${STLT} seq; + static unsigned precedence; }; -// global constants - -extern const ${CONTAINER} some_${CONTAINER}; -extern const type_info & typeid_${CONTAINER}; - // utility functions inline const ${CONTAINER} &ex_to_${CONTAINER}(const ex &e) { - return static_cast(*e.bp); + return static_cast(*e.bp); } inline ${CONTAINER} &ex_to_nonconst_${CONTAINER}(const ex &e) { - return static_cast<${CONTAINER} &>(*e.bp); + return static_cast<${CONTAINER} &>(*e.bp); } -#ifndef NO_NAMESPACE_GINAC } // namespace GiNaC -#endif // ndef NO_NAMESPACE_GINAC #endif // ndef __GINAC_${CONTAINER_UC}_H__ @@ -259,8 +276,9 @@ $implementation=<(s)); - } else { - seq=s; - } + debugmsg("${CONTAINER} ctor from ${STLT}", LOGLEVEL_CONSTRUCT); + if (discardable) { + seq.swap(const_cast<${STLT} &>(s)); + } else { + seq=s; + } } ${CONTAINER}::${CONTAINER}(${STLT} * vp) : basic(TINFO_${CONTAINER}) { - debugmsg("${CONTAINER} constructor from ${STLT} *",LOGLEVEL_CONSTRUCT); - GINAC_ASSERT(vp!=0); - seq.swap(*vp); - delete vp; -} - -${CONTAINER}::${CONTAINER}(const ex & e1) : basic(TINFO_${CONTAINER}) -{ - debugmsg("${CONTAINER} constructor from 1 ex", - LOGLEVEL_CONSTRUCT); - RESERVE(seq,1); - seq.push_back(e1); + debugmsg("${CONTAINER} ctor from ${STLT} *",LOGLEVEL_CONSTRUCT); + GINAC_ASSERT(vp!=0); + seq.swap(*vp); + delete vp; } -${CONTAINER}::${CONTAINER}(const ex & e1, const ex & e2) : basic(TINFO_${CONTAINER}) -{ - debugmsg("${CONTAINER} constructor from 2 ex", - LOGLEVEL_CONSTRUCT); - RESERVE(seq,2); - seq.push_back(e1); - seq.push_back(e2); -} - -${CONTAINER}::${CONTAINER}(const ex & e1, const ex & e2, const ex & e3) - : basic(TINFO_${CONTAINER}) -{ - debugmsg("${CONTAINER} constructor from 3 ex", - LOGLEVEL_CONSTRUCT); - RESERVE(seq,3); - seq.push_back(e1); - seq.push_back(e2); - seq.push_back(e3); -} - -${CONTAINER}::${CONTAINER}(const ex & e1, const ex & e2, const ex & e3, - const ex & e4) : basic(TINFO_${CONTAINER}) -{ - debugmsg("${CONTAINER} constructor from 4 ex", - LOGLEVEL_CONSTRUCT); - RESERVE(seq,4); - seq.push_back(e1); - seq.push_back(e2); - seq.push_back(e3); - seq.push_back(e4); -} - -${CONTAINER}::${CONTAINER}(const ex & e1, const ex & e2, const ex & e3, - const ex & e4, const ex & e5) : basic(TINFO_${CONTAINER}) -{ - debugmsg("${CONTAINER} constructor from 5 ex", - LOGLEVEL_CONSTRUCT); - RESERVE(seq,5); - seq.push_back(e1); - seq.push_back(e2); - seq.push_back(e3); - seq.push_back(e4); - seq.push_back(e5); -} - -${CONTAINER}::${CONTAINER}(const ex & e1, const ex & e2, const ex & e3, - const ex & e4, const ex & e5, const ex & e6) - : basic(TINFO_${CONTAINER}) -{ - debugmsg("${CONTAINER} constructor from 6 ex", - LOGLEVEL_CONSTRUCT); - RESERVE(seq,6); - seq.push_back(e1); - seq.push_back(e2); - seq.push_back(e3); - seq.push_back(e4); - seq.push_back(e5); - seq.push_back(e6); -} - -${CONTAINER}::${CONTAINER}(const ex & e1, const ex & e2, const ex & e3, - const ex & e4, const ex & e5, const ex & e6, - const ex & e7) : basic(TINFO_${CONTAINER}) -{ - debugmsg("${CONTAINER} constructor from 7 ex", - LOGLEVEL_CONSTRUCT); - RESERVE(seq,7); - seq.push_back(e1); - seq.push_back(e2); - seq.push_back(e3); - seq.push_back(e4); - seq.push_back(e5); - seq.push_back(e6); - seq.push_back(e7); -} - -${CONTAINER}::${CONTAINER}(const ex & e1, const ex & e2, const ex & e3, - const ex & e4, const ex & e5, const ex & e6, - const ex & e7, const ex & e8) : basic(TINFO_${CONTAINER}) -{ - debugmsg("${CONTAINER} constructor from 8 ex", - LOGLEVEL_CONSTRUCT); - RESERVE(seq,8); - seq.push_back(e1); - seq.push_back(e2); - seq.push_back(e3); - seq.push_back(e4); - seq.push_back(e5); - seq.push_back(e6); - seq.push_back(e7); - seq.push_back(e8); -} - -${CONTAINER}::${CONTAINER}(const ex & e1, const ex & e2, const ex & e3, - const ex & e4, const ex & e5, const ex & e6, - const ex & e7, const ex & e8, const ex & e9) - : basic(TINFO_${CONTAINER}) -{ - debugmsg("${CONTAINER} constructor from 9 ex", - LOGLEVEL_CONSTRUCT); - RESERVE(seq,9); - seq.push_back(e1); - seq.push_back(e2); - seq.push_back(e3); - seq.push_back(e4); - seq.push_back(e5); - seq.push_back(e6); - seq.push_back(e7); - seq.push_back(e8); - seq.push_back(e9); -} - -${CONTAINER}::${CONTAINER}(const ex & e1, const ex & e2, const ex & e3, - const ex & e4, const ex & e5, const ex & e6, - const ex & e7, const ex & e8, const ex & e9, - const ex &e10) - : basic(TINFO_${CONTAINER}) -{ - debugmsg("${CONTAINER} constructor from 10 ex", - LOGLEVEL_CONSTRUCT); - RESERVE(seq,10); - seq.push_back(e1); - seq.push_back(e2); - seq.push_back(e3); - seq.push_back(e4); - seq.push_back(e5); - seq.push_back(e6); - seq.push_back(e7); - seq.push_back(e8); - seq.push_back(e9); - seq.push_back(e10); -} +${constructors_implementation} ////////// // archiving @@ -513,31 +368,31 @@ ${CONTAINER}::${CONTAINER}(const ex & e1, const ex & e2, const ex & e3, /** Construct object from archive_node. */ ${CONTAINER}::${CONTAINER}(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst) { - debugmsg("${CONTAINER} constructor from archive_node", LOGLEVEL_CONSTRUCT); - for (unsigned int i=0; true; i++) { - ex e; - if (n.find_ex("seq", e, sym_lst, i)) - seq.push_back(e); - else - break; - } + debugmsg("${CONTAINER} ctor from archive_node", LOGLEVEL_CONSTRUCT); + for (unsigned int i=0; true; i++) { + ex e; + if (n.find_ex("seq", e, sym_lst, i)) + seq.push_back(e); + else + break; + } } /** Unarchive the object. */ ex ${CONTAINER}::unarchive(const archive_node &n, const lst &sym_lst) { - return (new ${CONTAINER}(n, sym_lst))->setflag(status_flags::dynallocated); + return (new ${CONTAINER}(n, sym_lst))->setflag(status_flags::dynallocated); } /** Archive the object. */ void ${CONTAINER}::archive(archive_node &n) const { - inherited::archive(n); - ${STLT}::const_iterator i = seq.begin(), iend = seq.end(); - while (i != iend) { - n.add_ex("seq", *i); - i++; - } + inherited::archive(n); + ${STLT}::const_iterator i = seq.begin(), iend = seq.end(); + while (i != iend) { + n.add_ex("seq", *i); + i++; + } } ////////// @@ -546,88 +401,70 @@ void ${CONTAINER}::archive(archive_node &n) const // public -basic * ${CONTAINER}::duplicate() const -{ - debugmsg("${CONTAINER} duplicate",LOGLEVEL_DUPLICATE); - return new ${CONTAINER}(*this); -} - -void ${CONTAINER}::printraw(ostream & os) const +void ${CONTAINER}::print(const print_context & c, unsigned level) const { - debugmsg("${CONTAINER} printraw",LOGLEVEL_PRINT); - - os << "${CONTAINER}("; - for (${STLT}::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) { - (*cit).bp->printraw(os); - os << ","; - } - os << ")"; -} + debugmsg("${CONTAINER} print", LOGLEVEL_PRINT); -void ${CONTAINER}::print(ostream & os, unsigned upper_precedence) const -{ - debugmsg("${CONTAINER} print",LOGLEVEL_PRINT); - // always print brackets around seq, ignore upper_precedence - printseq(os,'${open_bracket}',',','${close_bracket}',precedence,precedence+1); -} + if (is_of_type(c, print_tree)) { -void ${CONTAINER}::printtree(ostream & os, unsigned indent) const -{ - debugmsg("${CONTAINER} printtree",LOGLEVEL_PRINT); + c.s << std::string(level, ' ') << class_name() + << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec + << ", nops=" << nops() + << std::endl; + unsigned delta_indent = static_cast(c).delta_indent; + for (${STLT}::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) + cit->print(c, level + delta_indent); + c.s << std::string(level + delta_indent,' ') << "=====" << std::endl; - os << string(indent,' ') << "type=" << typeid(*this).name() - << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")" - << ", flags=" << flags - << ", nops=" << nops() << endl; - for (${STLT}::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) { - (*cit).printtree(os,indent+delta_indent); - } - os << string(indent+delta_indent,' ') << "=====" << endl; + } else { + // always print brackets around seq, ignore upper_precedence + printseq(c, '${open_bracket}', ',', '${close_bracket}', precedence, precedence+1); + } } // ${CONTAINER}::info() will be implemented by user elsewhere"; unsigned ${CONTAINER}::nops() const { - return seq.size(); + return seq.size(); } ${LET_OP_IMPLEMENTATION} ex ${CONTAINER}::expand(unsigned options) const { - ${STLT} s; - RESERVE(s,seq.size()); - for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) { - s.push_back((*it).expand(options)); - } + ${STLT} s; + RESERVE(s,seq.size()); + for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) { + s.push_back((*it).expand(options)); + } - return this${CONTAINER}(s); + return this${CONTAINER}(s); } // a ${CONTAINER} 'has' an expression if it is this expression itself or a child 'has' it bool ${CONTAINER}::has(const ex & other) const { - GINAC_ASSERT(other.bp!=0); - if (is_equal(*other.bp)) return true; - for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) { - if ((*it).has(other)) return true; - } - return false; + GINAC_ASSERT(other.bp!=0); + if (is_equal(*other.bp)) return true; + for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) { + if ((*it).has(other)) return true; + } + return false; } ex ${CONTAINER}::eval(int level) const { - if (level==1) { - return this->hold(); - } - return this${CONTAINER}(evalchildren(level)); + if (level==1) { + return this->hold(); + } + return this${CONTAINER}(evalchildren(level)); } ex ${CONTAINER}::evalf(int level) const { - return this${CONTAINER}(evalfchildren(level)); + return this${CONTAINER}(evalfchildren(level)); } /** Implementation of ex::normal() for ${CONTAINER}s. It normalizes the arguments @@ -635,67 +472,67 @@ ex ${CONTAINER}::evalf(int level) const * \@see ex::normal */ ex ${CONTAINER}::normal(lst &sym_lst, lst &repl_lst, int level) const { - ex n=this${CONTAINER}(normalchildren(level)); - return n.bp->basic::normal(sym_lst,repl_lst,level); + ex n=this${CONTAINER}(normalchildren(level)); + return n.bp->basic::normal(sym_lst,repl_lst,level); } ex ${CONTAINER}::derivative(const symbol & s) const { - return this${CONTAINER}(diffchildren(s)); + return this${CONTAINER}(diffchildren(s)); } ex ${CONTAINER}::subs(const lst & ls, const lst & lr) const { - ${STLT} * vp=subschildren(ls,lr); - if (vp==0) { - return *this; - } - return this${CONTAINER}(vp); + ${STLT} * vp=subschildren(ls,lr); + if (vp==0) + return inherited::subs(ls, lr); + + return this${CONTAINER}(vp); } // protected int ${CONTAINER}::compare_same_type(const basic & other) const { - GINAC_ASSERT(is_of_type(other,${CONTAINER})); - ${CONTAINER} const & o=static_cast<${CONTAINER} const &> - (const_cast(other)); - int cmpval; - ${STLT}::const_iterator it1=seq.begin(); - ${STLT}::const_iterator it2=o.seq.begin(); + GINAC_ASSERT(is_of_type(other,${CONTAINER})); + ${CONTAINER} const & o=static_cast<${CONTAINER} const &> + (const_cast(other)); + int cmpval; + ${STLT}::const_iterator it1=seq.begin(); + ${STLT}::const_iterator it2=o.seq.begin(); - for (; (it1!=seq.end())&&(it2!=o.seq.end()); ++it1, ++it2) { - cmpval=(*it1).compare(*it2); - if (cmpval!=0) return cmpval; - } + for (; (it1!=seq.end())&&(it2!=o.seq.end()); ++it1, ++it2) { + cmpval=(*it1).compare(*it2); + if (cmpval!=0) return cmpval; + } - if (it1==seq.end()) { - return (it2==o.seq.end() ? 0 : -1); - } + if (it1==seq.end()) { + return (it2==o.seq.end() ? 0 : -1); + } - return 1; + return 1; } bool ${CONTAINER}::is_equal_same_type(const basic & other) const { - GINAC_ASSERT(is_of_type(other,${CONTAINER})); - ${CONTAINER} const & o=static_cast<${CONTAINER} const &> - (const_cast(other)); - if (seq.size()!=o.seq.size()) return false; + GINAC_ASSERT(is_of_type(other,${CONTAINER})); + ${CONTAINER} const & o=static_cast<${CONTAINER} const &> + (const_cast(other)); + if (seq.size()!=o.seq.size()) return false; - ${STLT}::const_iterator it1=seq.begin(); - ${STLT}::const_iterator it2=o.seq.begin(); + ${STLT}::const_iterator it1=seq.begin(); + ${STLT}::const_iterator it2=o.seq.begin(); - for (; it1!=seq.end(); ++it1, ++it2) { - if (!(*it1).is_equal(*it2)) return false; - } + for (; it1!=seq.end(); ++it1, ++it2) { + if (!(*it1).is_equal(*it2)) return false; + } - return true; + return true; } unsigned ${CONTAINER}::return_type(void) const { - return return_types::noncommutative_composite; + return return_types::noncommutative_composite; } ////////// @@ -706,42 +543,45 @@ unsigned ${CONTAINER}::return_type(void) const ${CONTAINER} & ${CONTAINER}::append(const ex & b) { - ensure_if_modifiable(); - seq.push_back(b); - return *this; + ensure_if_modifiable(); + seq.push_back(b); + return *this; } ${PREPEND_IMPLEMENTATION} // protected -void ${CONTAINER}::printseq(ostream & os, char openbracket, char delim, - char closebracket, unsigned this_precedence, - unsigned upper_precedence) const -{ - if (this_precedence<=upper_precedence) os << openbracket; - if (seq.size()!=0) { - ${STLT}::const_iterator it,it_last; - it=seq.begin(); - it_last=seq.end(); - --it_last; - for (; it!=it_last; ++it) { - (*it).bp->print(os,this_precedence); - os << delim; - } - (*it).bp->print(os,this_precedence); - } - if (this_precedence<=upper_precedence) os << closebracket; +void ${CONTAINER}::printseq(const print_context & c, char openbracket, char delim, + char closebracket, unsigned this_precedence, + unsigned upper_precedence) const +{ + if (this_precedence <= upper_precedence) + c.s << openbracket; + + if (seq.size() != 0) { + ${STLT}::const_iterator it = seq.begin(), itend = seq.end(); + --itend; + while (it != itend) { + it->print(c, this_precedence); + c.s << delim; + it++; + } + it->print(c, this_precedence); + } + + if (this_precedence <= upper_precedence) + c.s << closebracket; } ex ${CONTAINER}::this${CONTAINER}(${STLT} const & v) const { - return ${CONTAINER}(v); + return ${CONTAINER}(v); } ex ${CONTAINER}::this${CONTAINER}(${STLT} * vp) const { - return ${CONTAINER}(vp); + return ${CONTAINER}(vp); } ////////// @@ -756,134 +596,134 @@ ex ${CONTAINER}::this${CONTAINER}(${STLT} * vp) const bool ${CONTAINER}::is_canonical() const { - if (seq.size()<=1) { return 1; } + if (seq.size()<=1) { return 1; } - ${STLT}::const_iterator it=seq.begin(); - ${STLT}::const_iterator it_last=it; - for (++it; it!=seq.end(); it_last=it, ++it) { - if ((*it_last).compare(*it)>0) { - if ((*it_last).compare(*it)>0) { - cout << *it_last << ">" << *it << "\\n"; - return 0; - } - } - } - return 1; + ${STLT}::const_iterator it=seq.begin(); + ${STLT}::const_iterator it_last=it; + for (++it; it!=seq.end(); it_last=it, ++it) { + if ((*it_last).compare(*it)>0) { + if ((*it_last).compare(*it)>0) { + std::cout << *it_last << ">" << *it << "\\n"; + return 0; + } + } + } + return 1; } ${STLT} ${CONTAINER}::evalchildren(int level) const { - ${STLT} s; - RESERVE(s,seq.size()); + ${STLT} s; + RESERVE(s,seq.size()); - if (level==1) { - return seq; - } - if (level == -max_recursion_level) { - throw(std::runtime_error("max recursion level reached")); - } - --level; - for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) { - s.push_back((*it).eval(level)); - } - return s; + if (level==1) { + return seq; + } + if (level == -max_recursion_level) { + throw(std::runtime_error("max recursion level reached")); + } + --level; + for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) { + s.push_back((*it).eval(level)); + } + return s; } ${STLT} ${CONTAINER}::evalfchildren(int level) const { - ${STLT} s; - RESERVE(s,seq.size()); + ${STLT} s; + RESERVE(s,seq.size()); - if (level==1) { - return seq; - } - if (level == -max_recursion_level) { - throw(std::runtime_error("max recursion level reached")); - } - --level; - for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) { - s.push_back((*it).evalf(level)); - } - return s; + if (level==1) { + return seq; + } + if (level == -max_recursion_level) { + throw(std::runtime_error("max recursion level reached")); + } + --level; + for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) { + s.push_back((*it).evalf(level)); + } + return s; } ${STLT} ${CONTAINER}::normalchildren(int level) const { - ${STLT} s; - RESERVE(s,seq.size()); + ${STLT} s; + RESERVE(s,seq.size()); - if (level==1) { - return seq; - } - if (level == -max_recursion_level) { - throw(std::runtime_error("max recursion level reached")); - } - --level; - for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) { - s.push_back((*it).normal(level)); - } - return s; + if (level==1) { + return seq; + } + if (level == -max_recursion_level) { + throw(std::runtime_error("max recursion level reached")); + } + --level; + for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) { + s.push_back((*it).normal(level)); + } + return s; } ${STLT} ${CONTAINER}::diffchildren(const symbol & y) const { - ${STLT} s; - RESERVE(s,seq.size()); - for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) { - s.push_back((*it).diff(y)); - } - return s; + ${STLT} s; + RESERVE(s,seq.size()); + for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) { + s.push_back((*it).diff(y)); + } + return s; } /* obsolete subschildren ${STLT} ${CONTAINER}::subschildren(const lst & ls, const lst & lr) const { - ${STLT} s; - RESERVE(s,seq.size()); - for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) { - s.push_back((*it).subs(ls,lr)); - } - return s; + ${STLT} s; + RESERVE(s,seq.size()); + for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) { + s.push_back((*it).subs(ls,lr)); + } + return s; } */ ${STLT} * ${CONTAINER}::subschildren(const lst & ls, const lst & lr) const { - // returns a NULL pointer if nothing had to be substituted - // returns a pointer to a newly created epvector otherwise - // (which has to be deleted somewhere else) - - ${STLT}::const_iterator last=seq.end(); - ${STLT}::const_iterator cit=seq.begin(); - while (cit!=last) { - const ex & subsed_ex=(*cit).subs(ls,lr); - if (!are_ex_trivially_equal(*cit,subsed_ex)) { - - // something changed, copy seq, subs and return it - ${STLT} *s=new ${STLT}; - RESERVE(*s,seq.size()); - - // copy parts of seq which are known not to have changed - ${STLT}::const_iterator cit2=seq.begin(); - while (cit2!=cit) { - s->push_back(*cit2); - ++cit2; - } - // copy first changed element - s->push_back(subsed_ex); - ++cit2; - // copy rest - while (cit2!=last) { - s->push_back((*cit2).subs(ls,lr)); - ++cit2; - } - return s; - } - ++cit; - } - - return 0; // nothing has changed + // returns a NULL pointer if nothing had to be substituted + // returns a pointer to a newly created epvector otherwise + // (which has to be deleted somewhere else) + + ${STLT}::const_iterator last=seq.end(); + ${STLT}::const_iterator cit=seq.begin(); + while (cit!=last) { + const ex & subsed_ex=(*cit).subs(ls,lr); + if (!are_ex_trivially_equal(*cit,subsed_ex)) { + + // something changed, copy seq, subs and return it + ${STLT} *s=new ${STLT}; + RESERVE(*s,seq.size()); + + // copy parts of seq which are known not to have changed + ${STLT}::const_iterator cit2=seq.begin(); + while (cit2!=cit) { + s->push_back(*cit2); + ++cit2; + } + // copy first changed element + s->push_back(subsed_ex); + ++cit2; + // copy rest + while (cit2!=last) { + s->push_back((*cit2).subs(ls,lr)); + ++cit2; + } + return s; + } + ++cit; + } + + return 0; // nothing has changed } ////////// @@ -892,18 +732,9 @@ ${STLT} * ${CONTAINER}::subschildren(const lst & ls, const lst & lr) const // protected -unsigned ${CONTAINER}::precedence=10; - -////////// -// global constants -////////// - -const ${CONTAINER} some_${CONTAINER}; -const type_info & typeid_${CONTAINER}=typeid(some_${CONTAINER}); +unsigned ${CONTAINER}::precedence = 10; -#ifndef NO_NAMESPACE_GINAC } // namespace GiNaC -#endif // ndef NO_NAMESPACE_GINAC END_OF_IMPLEMENTATION