X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fcontainer.pl;h=af9d5372ba4616cb441ed5c399a090c776fd490c;hp=571330f982ebde9f0f34a5b80132ea4ff05f94d2;hb=08af38543754f923653d73fd84625bb8a35b0136;hpb=094911eb78cacb6f2877a70c9ac74766df58ccea diff --git a/ginac/container.pl b/ginac/container.pl index 571330f9..af9d5372 100755 --- a/ginac/container.pl +++ b/ginac/container.pl @@ -186,10 +186,11 @@ $interface=< but malloc_alloc is -// unstandardized and not supported by newer GCCs. -#if defined(__GNUC__) && ((__GNUC__ == 2) && (__GNUC_MINOR__ < 97)) -typedef std::${STLHEADER} ${STLT}; +// 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 @@ -204,9 +205,7 @@ public: ${constructors_interface} public: - void printraw(std::ostream & os) const; - void print(std::ostream & os, unsigned upper_precedence=0) const; - void printtree(std::ostream & os, unsigned indent) const; + void print(const print_context & c, unsigned level = 0) const; bool info(unsigned inf) const; unsigned nops() const; ex & let_op(int i); @@ -226,9 +225,9 @@ public: virtual ${CONTAINER} & append(const ex & b); ${PREPEND_INTERFACE} protected: - virtual void printseq(std::ostream & os, char openbracket, char delim, + virtual void printseq(const print_context & c, char openbracket, char delim, char closebracket, unsigned this_precedence, - unsigned upper_precedence=0) const; + unsigned upper_precedence = 0) const; virtual ex this${CONTAINER}(${STLT} const & v) const; virtual ex this${CONTAINER}(${STLT} * vp) const; @@ -245,11 +244,6 @@ protected: static unsigned precedence; }; -// global constants - -extern const ${CONTAINER} some_${CONTAINER}; -extern const std::type_info & typeid_${CONTAINER}; - // utility functions inline const ${CONTAINER} &ex_to_${CONTAINER}(const ex &e) { @@ -306,6 +300,7 @@ $implementation=<printraw(os); - os << ","; - } - os << ")"; -} + if (is_of_type(c, print_tree)) { -void ${CONTAINER}::print(std::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); -} - -void ${CONTAINER}::printtree(std::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 << std::string(indent,' ') << "type=" << class_name() - << ", hash=" << hashvalue - << " (0x" << std::hex << hashvalue << std::dec << ")" - << ", flags=" << flags - << ", nops=" << nops() << std::endl; - for (${STLT}::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) { - (*cit).printtree(os,indent+delta_indent); + } else { + // always print brackets around seq, ignore upper_precedence + printseq(c, '${open_bracket}', ',', '${close_bracket}', precedence, precedence+1); } - os << std::string(indent+delta_indent,' ') << "=====" << std::endl; } // ${CONTAINER}::info() will be implemented by user elsewhere"; @@ -502,9 +484,9 @@ ex ${CONTAINER}::derivative(const symbol & s) const ex ${CONTAINER}::subs(const lst & ls, const lst & lr) const { ${STLT} * vp=subschildren(ls,lr); - if (vp==0) { - return *this; - } + if (vp==0) + return inherited::subs(ls, lr); + return this${CONTAINER}(vp); } @@ -570,23 +552,26 @@ ${PREPEND_IMPLEMENTATION} // protected -void ${CONTAINER}::printseq(std::ostream & os, char openbracket, char delim, +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) 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; + 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).bp->print(os,this_precedence); + it->print(c, this_precedence); } - if (this_precedence<=upper_precedence) os << closebracket; + + if (this_precedence <= upper_precedence) + c.s << closebracket; } ex ${CONTAINER}::this${CONTAINER}(${STLT} const & v) const @@ -749,13 +734,6 @@ ${STLT} * ${CONTAINER}::subschildren(const lst & ls, const lst & lr) const unsigned ${CONTAINER}::precedence = 10; -////////// -// global constants -////////// - -const ${CONTAINER} some_${CONTAINER}; -const std::type_info & typeid_${CONTAINER} = typeid(some_${CONTAINER}); - } // namespace GiNaC END_OF_IMPLEMENTATION