]> www.ginac.de Git - ginac.git/blobdiff - ginac/container.pl
* introduced typedef propinfovector in order to please Cint.
[ginac.git] / ginac / container.pl
index 232d299c6fc12e0bb073ab5aa59c9a7923b1d694..55da47c010df80d72077008d56c00623b6e909be 100755 (executable)
@@ -132,7 +132,7 @@ $constructors_implementation=generate(
        <<'END_OF_CONSTRUCTORS_IMPLEMENTATION','const ex & param${N}',', ','    seq.push_back(param${N});',"\n");
 ${CONTAINER}::${CONTAINER}(${SEQ1}) : basic(TINFO_${CONTAINER})
 {
-       debugmsg(\"${CONTAINER} constructor from ${N}*ex\",LOGLEVEL_CONSTRUCT);
+       debugmsg(\"${CONTAINER} ctor from ${N}*ex\",LOGLEVEL_CONSTRUCT);
        RESERVE(seq,${N});
 ${SEQ2}
 }
@@ -183,9 +183,7 @@ $interface=<<END_OF_INTERFACE;
 #include "basic.h"
 #include "ex.h"
 
-#ifndef NO_NAMESPACE_GINAC
 namespace GiNaC {
-#endif // ndef NO_NAMESPACE_GINAC
 
 
 // Cint does not like ${STLHEADER}<..,default_alloc> but malloc_alloc is
@@ -206,10 +204,7 @@ public:
 ${constructors_interface}
 
 public:
-       basic * duplicate() const;
-       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);
@@ -221,7 +216,6 @@ public:
        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;
 
@@ -230,9 +224,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;
 
@@ -249,11 +243,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)
 {
@@ -265,9 +254,7 @@ inline ${CONTAINER} &ex_to_nonconst_${CONTAINER}(const ex &e)
        return static_cast<${CONTAINER} &>(*e.bp);
 }
 
-#ifndef NO_NAMESPACE_GINAC
 } // namespace GiNaC
-#endif // ndef NO_NAMESPACE_GINAC
 
 #endif // ndef __GINAC_${CONTAINER_UC}_H__
 
@@ -312,26 +299,25 @@ $implementation=<<END_OF_IMPLEMENTATION;
 
 #include "${CONTAINER}.h"
 #include "ex.h"
+#include "print.h"
 #include "archive.h"
 #include "debugmsg.h"
 
-#ifndef NO_NAMESPACE_GINAC
 namespace GiNaC {
-#endif // ndef NO_NAMESPACE_GINAC
 
 GINAC_IMPLEMENT_REGISTERED_CLASS(${CONTAINER}, basic)
 
 ${RESERVE_IMPLEMENTATION}
 
 //////////
-// default constructor, destructor, copy constructor assignment operator and helpers
+// default ctor, dtor, copy ctor assignment operator and helpers
 //////////
 
 // public
 
 ${CONTAINER}::${CONTAINER}() : basic(TINFO_${CONTAINER})
 {
-       debugmsg("${CONTAINER} default constructor",LOGLEVEL_CONSTRUCT);
+       debugmsg("${CONTAINER} default ctor",LOGLEVEL_CONSTRUCT);
 }
 
 // protected
@@ -349,14 +335,14 @@ void ${CONTAINER}::destroy(bool call_parent)
 }
 
 //////////
-// other constructors
+// other ctors
 //////////
 
 // public
 
 ${CONTAINER}::${CONTAINER}(${STLT} const & s, bool discardable) :  basic(TINFO_${CONTAINER})
 {
-       debugmsg("${CONTAINER} constructor from ${STLT}", LOGLEVEL_CONSTRUCT);
+       debugmsg("${CONTAINER} ctor from ${STLT}", LOGLEVEL_CONSTRUCT);
        if (discardable) {
                seq.swap(const_cast<${STLT} &>(s));
        } else {
@@ -366,7 +352,7 @@ ${CONTAINER}::${CONTAINER}(${STLT} const & s, bool discardable) :  basic(TINFO_$
 
 ${CONTAINER}::${CONTAINER}(${STLT} * vp) : basic(TINFO_${CONTAINER})
 {
-       debugmsg("${CONTAINER} constructor from ${STLT} *",LOGLEVEL_CONSTRUCT);
+       debugmsg("${CONTAINER} ctor from ${STLT} *",LOGLEVEL_CONSTRUCT);
        GINAC_ASSERT(vp!=0);
        seq.swap(*vp);
        delete vp;
@@ -381,7 +367,7 @@ ${constructors_implementation}
 /** 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);
+       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))
@@ -414,44 +400,25 @@ void ${CONTAINER}::archive(archive_node &n) const
 
 // public
 
-basic * ${CONTAINER}::duplicate() const
-{
-       debugmsg("${CONTAINER} duplicate",LOGLEVEL_DUPLICATE);
-       return new ${CONTAINER}(*this);
-}
-
-void ${CONTAINER}::printraw(std::ostream & os) const
+void ${CONTAINER}::print(const print_context & c, unsigned level) const
 {
-       debugmsg("${CONTAINER} printraw",LOGLEVEL_PRINT);
+       debugmsg("${CONTAINER} print", LOGLEVEL_PRINT);
 
-       os << "${CONTAINER}(";
-       for (${STLT}::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
-               (*cit).bp->printraw(os);
-               os << ",";
-       }
-       os << ")";
-}
-
-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);
-}
+       if (is_of_type(c, print_tree)) {
 
-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<const print_tree &>(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";
@@ -516,9 +483,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);
 }
 
@@ -584,23 +551,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
@@ -761,18 +731,9 @@ ${STLT} * ${CONTAINER}::subschildren(const lst & ls, const lst & lr) const
 
 // protected
 
-unsigned ${CONTAINER}::precedence=10;
-
-//////////
-// global constants
-//////////
-
-const ${CONTAINER} some_${CONTAINER};
-const std::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