]> www.ginac.de Git - ginac.git/commitdiff
use new-style print methods
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Wed, 6 Aug 2003 18:43:52 +0000 (18:43 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Wed, 6 Aug 2003 18:43:52 +0000 (18:43 +0000)
ginac/constant.cpp
ginac/constant.h
ginac/idx.cpp
ginac/idx.h
ginac/symmetry.cpp
ginac/symmetry.h

index d3c91588c186be4bfe64354fb553cdc4fd3bb405..baf10805083dcf20993ab1d65810d373ea72b885 100644 (file)
 
 namespace GiNaC {
 
 
 namespace GiNaC {
 
-GINAC_IMPLEMENT_REGISTERED_CLASS(constant, basic)
+GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(constant, basic,
+  print_func<print_context>(&constant::do_print).
+  print_func<print_latex>(&constant::do_print_latex).
+  print_func<print_tree>(&constant::do_print_tree).
+  print_func<print_python_repr>(&constant::do_print_python_repr))
 
 //////////
 // default constructor
 
 //////////
 // default constructor
@@ -108,21 +112,29 @@ void constant::archive(archive_node &n) const
 
 // public
 
 
 // public
 
-void constant::print(const print_context & c, unsigned level) const
+void constant::do_print(const print_context & c, unsigned level) const
 {
 {
-       if (is_a<print_tree>(c)) {
-               c.s << std::string(level, ' ') << name << " (" << class_name() << ")"
-                   << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
-                   << std::endl;
-       } else if (is_a<print_latex>(c)) {
-               c.s << TeX_name;
-       } else if (is_a<print_python_repr>(c)) {
-               c.s << class_name() << "('" << name << "'";
-               if (TeX_name != "\\mbox{" + name + "}")
-                       c.s << ",TeX_name='" << TeX_name << "'";
-               c.s << ')';
-       } else
-               c.s << name;
+       c.s << name;
+}
+
+void constant::do_print_tree(const print_tree & c, unsigned level) const
+{
+       c.s << std::string(level, ' ') << name << " (" << class_name() << ")"
+           << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
+           << std::endl;
+}
+
+void constant::do_print_latex(const print_latex & c, unsigned level) const
+{
+       c.s << TeX_name;
+}
+
+void constant::do_print_python_repr(const print_python_repr & c, unsigned level) const
+{
+       c.s << class_name() << "('" << name << "'";
+       if (TeX_name != "\\mbox{" + name + "}")
+               c.s << ",TeX_name='" << TeX_name << "'";
+       c.s << ')';
 }
 
 ex constant::evalf(int level) const
 }
 
 ex constant::evalf(int level) const
index 0092ac3b1c9d308082cded8c523d72966a3da818..f44ec9dcf08b30d356bf7d01e7198e53ca8fe2b3 100644 (file)
@@ -48,21 +48,20 @@ public:
        
        // functions overriding virtual functions from base classes
 public:
        
        // functions overriding virtual functions from base classes
 public:
-       void print(const print_context & c, unsigned level = 0) const;
        ex evalf(int level = 0) const;
 protected:
        ex derivative(const symbol & s) const;
        bool is_equal_same_type(const basic & other) const;
        unsigned calchash() const;
        
        ex evalf(int level = 0) const;
 protected:
        ex derivative(const symbol & s) const;
        bool is_equal_same_type(const basic & other) const;
        unsigned calchash() const;
        
-       // new virtual functions which can be overridden by derived classes
-       // none
-       
        // non-virtual functions in this class
        // non-virtual functions in this class
-       // none
-       
+protected:
+       void do_print(const print_context & c, unsigned level) const;
+       void do_print_tree(const print_tree & c, unsigned level) const;
+       void do_print_latex(const print_latex & c, unsigned level) const;
+       void do_print_python_repr(const print_python_repr & c, unsigned level) const;
+
 // member variables
 // member variables
-       
 private:
        std::string name;     ///< printname of this constant
        std::string TeX_name; ///< LaTeX name
 private:
        std::string name;     ///< printname of this constant
        std::string TeX_name; ///< LaTeX name
index 01692294041c3335c298fbfc96337bf826edf57c..1b4bf6f5e3d2f781d00080892f8f719ce2c2012d 100644 (file)
 
 namespace GiNaC {
 
 
 namespace GiNaC {
 
-GINAC_IMPLEMENT_REGISTERED_CLASS(idx, basic)
-GINAC_IMPLEMENT_REGISTERED_CLASS(varidx, idx)
-GINAC_IMPLEMENT_REGISTERED_CLASS(spinidx, varidx)
+GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(idx, basic,
+  print_func<print_context>(&idx::do_print).
+  print_func<print_latex>(&idx::do_print_latex).
+  print_func<print_tree>(&idx::do_print_tree))
+
+GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(varidx, idx,
+  print_func<print_context>(&varidx::do_print).
+  // print_latex inherited from idx
+  print_func<print_tree>(&varidx::do_print_tree))
+
+GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(spinidx, varidx,
+  print_func<print_context>(&spinidx::do_print).
+  print_func<print_latex>(&spinidx::do_print_latex).
+  print_func<print_tree>(&spinidx::do_print_tree))
 
 //////////
 // default constructor
 
 //////////
 // default constructor
@@ -123,120 +134,92 @@ DEFAULT_UNARCHIVE(spinidx)
 // functions overriding virtual functions from base classes
 //////////
 
 // functions overriding virtual functions from base classes
 //////////
 
-void idx::print(const print_context & c, unsigned level) const
-{
-       if (is_a<print_tree>(c)) {
-
-               c.s << std::string(level, ' ') << class_name()
-                   << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
-                   << std::endl;
-               unsigned delta_indent = static_cast<const print_tree &>(c).delta_indent;
-               value.print(c, level + delta_indent);
-               dim.print(c, level + delta_indent);
-
-       } else {
-
-               if (is_a<print_latex>(c))
-                       c.s << "{";
-               else
-                       c.s << ".";
-               bool need_parens = !(is_exactly_a<numeric>(value) || is_a<symbol>(value));
-               if (need_parens)
-                       c.s << "(";
-               value.print(c);
-               if (need_parens)
-                       c.s << ")";
-               if (c.options & print_options::print_index_dimensions) {
-                       c.s << "[";
-                       dim.print(c);
-                       c.s << "]";
-               }
-               if (is_a<print_latex>(c))
-                       c.s << "}";
+void idx::do_print_idx(const print_context & c, unsigned level) const
+{
+       bool need_parens = !(is_exactly_a<numeric>(value) || is_a<symbol>(value));
+       if (need_parens)
+               c.s << "(";
+       value.print(c);
+       if (need_parens)
+               c.s << ")";
+       if (c.options & print_options::print_index_dimensions) {
+               c.s << "[";
+               dim.print(c);
+               c.s << "]";
        }
 }
 
        }
 }
 
-void varidx::print(const print_context & c, unsigned level) const
+void idx::do_print(const print_context & c, unsigned level) const
 {
 {
-       if (is_a<print_tree>(c)) {
+       c.s << ".";
+       do_print_idx(c, level);
+}
 
 
-               c.s << std::string(level, ' ') << class_name()
-                   << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
-                   << (covariant ? ", covariant" : ", contravariant")
-                   << std::endl;
-               unsigned delta_indent = static_cast<const print_tree &>(c).delta_indent;
-               value.print(c, level + delta_indent);
-               dim.print(c, level + delta_indent);
+void idx::do_print_latex(const print_latex & c, unsigned level) const
+{
+       c.s << "{";
+       do_print_idx(c, level);
+       c.s << "}";
+}
 
 
-       } else {
-               if (is_a<print_latex>(c))
-                       c.s << "{";
-               else {
-                       if (covariant)
-                               c.s << ".";
-                       else
-                               c.s << "~";
-               }
-               bool need_parens = !(is_exactly_a<numeric>(value) || is_a<symbol>(value));
-               if (need_parens)
-                       c.s << "(";
-               value.print(c);
-               if (need_parens)
-                       c.s << ")";
-               if (c.options & print_options::print_index_dimensions) {
-                       c.s << "[";
-                       dim.print(c);
-                       c.s << "]";
-               }
-               if (is_a<print_latex>(c))
-                       c.s << "}";
-       }
+void idx::do_print_tree(const print_tree & c, unsigned level) const
+{
+       c.s << std::string(level, ' ') << class_name()
+           << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
+           << std::endl;
+       value.print(c, level +  c.delta_indent);
+       dim.print(c, level + c.delta_indent);
 }
 
 }
 
-void spinidx::print(const print_context & c, unsigned level) const
+void varidx::do_print(const print_context & c, unsigned level) const
 {
 {
-       if (is_a<print_tree>(c)) {
+       if (covariant)
+               c.s << ".";
+       else
+               c.s << "~";
+       do_print_idx(c, level);
+}
 
 
-               c.s << std::string(level, ' ') << class_name()
-                   << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
-                   << (covariant ? ", covariant" : ", contravariant")
-                   << (dotted ? ", dotted" : ", undotted")
-                   << std::endl;
-               unsigned delta_indent = static_cast<const print_tree &>(c).delta_indent;
-               value.print(c, level + delta_indent);
-               dim.print(c, level + delta_indent);
+void varidx::do_print_tree(const print_tree & c, unsigned level) const
+{
+       c.s << std::string(level, ' ') << class_name()
+           << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
+           << (covariant ? ", covariant" : ", contravariant")
+           << std::endl;
+       value.print(c, level + c.delta_indent);
+       dim.print(c, level + c.delta_indent);
+}
 
 
-       } else {
+void spinidx::do_print(const print_context & c, unsigned level) const
+{
+       if (covariant)
+               c.s << ".";
+       else
+               c.s << "~";
+       if (dotted)
+               c.s << "*";
+       do_print_idx(c, level);
+}
 
 
-               bool is_tex = is_a<print_latex>(c);
-               if (is_tex) {
-                       if (covariant)
-                               c.s << "_{";
-                       else
-                               c.s << "^{";
-               } else {
-                       if (covariant)
-                               c.s << ".";
-                       else
-                               c.s << "~";
-               }
-               if (dotted) {
-                       if (is_tex)
-                               c.s << "\\dot{";
-                       else
-                               c.s << "*";
-               }
-               bool need_parens = !(is_exactly_a<numeric>(value) || is_a<symbol>(value));
-               if (need_parens)
-                       c.s << "(";
-               value.print(c);
-               if (need_parens)
-                       c.s << ")";
-               if (is_tex && dotted)
-                       c.s << "}";
-               if (is_tex)
-                       c.s << "}";
-       }
+void spinidx::do_print_latex(const print_latex & c, unsigned level) const
+{
+       if (dotted)
+               c.s << "\\dot{";
+       else
+               c.s << "{";
+       do_print_idx(c, level);
+       c.s << "}";
+}
+
+void spinidx::do_print_tree(const print_tree & c, unsigned level) const
+{
+       c.s << std::string(level, ' ') << class_name()
+           << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
+           << (covariant ? ", covariant" : ", contravariant")
+           << (dotted ? ", dotted" : ", undotted")
+           << std::endl;
+       value.print(c, level + c.delta_indent);
+       dim.print(c, level + c.delta_indent);
 }
 
 bool idx::info(unsigned inf) const
 }
 
 bool idx::info(unsigned inf) const
index 985226d72d441b9c604c478ff801b0e642f410f7..16c515f22380e7c929f09d30a46fa5bebf35b0fb 100644 (file)
@@ -48,7 +48,6 @@ public:
 
        // functions overriding virtual functions from base classes
 public:
 
        // functions overriding virtual functions from base classes
 public:
-       void print(const print_context & c, unsigned level = 0) const;
        bool info(unsigned inf) const;
        size_t nops() const;
        ex op(size_t i) const;
        bool info(unsigned inf) const;
        size_t nops() const;
        ex op(size_t i) const;
@@ -94,6 +93,12 @@ public:
         *  If this is undecidable, throw an exception. */
        ex minimal_dim(const idx & other) const;
 
         *  If this is undecidable, throw an exception. */
        ex minimal_dim(const idx & other) const;
 
+protected:
+       void do_print_idx(const print_context & c, unsigned level) const;
+       void do_print(const print_context & c, unsigned level) const;
+       void do_print_latex(const print_latex & c, unsigned level) const;
+       void do_print_tree(const print_tree & c, unsigned level) const;
+
 protected:
        ex value; /**< Expression that constitutes the index (numeric or symbolic name) */
        ex dim;   /**< Dimension of space (can be symbolic or numeric) */
 protected:
        ex value; /**< Expression that constitutes the index (numeric or symbolic name) */
        ex dim;   /**< Dimension of space (can be symbolic or numeric) */
@@ -118,7 +123,6 @@ public:
 
        // functions overriding virtual functions from base classes
 public:
 
        // functions overriding virtual functions from base classes
 public:
-       void print(const print_context & c, unsigned level = 0) const;
        bool is_dummy_pair_same_type(const basic & other) const;
 
 protected:
        bool is_dummy_pair_same_type(const basic & other) const;
 
 protected:
@@ -135,6 +139,10 @@ public:
        /** Make a new index with the same value but the opposite variance. */
        ex toggle_variance() const;
 
        /** Make a new index with the same value but the opposite variance. */
        ex toggle_variance() const;
 
+protected:
+       void do_print(const print_context & c, unsigned level) const;
+       void do_print_tree(const print_tree & c, unsigned level) const;
+
        // member variables
 protected:
        bool covariant; /**< x.mu, default is contravariant: x~mu */
        // member variables
 protected:
        bool covariant; /**< x.mu, default is contravariant: x~mu */
@@ -163,7 +171,6 @@ public:
 
        // functions overriding virtual functions from base classes
 public:
 
        // functions overriding virtual functions from base classes
 public:
-       void print(const print_context & c, unsigned level = 0) const;
        bool is_dummy_pair_same_type(const basic & other) const;
 
 protected:
        bool is_dummy_pair_same_type(const basic & other) const;
 
 protected:
@@ -185,6 +192,11 @@ public:
         *  dottedness. */
        ex toggle_variance_dot() const;
 
         *  dottedness. */
        ex toggle_variance_dot() const;
 
+protected:
+       void do_print(const print_context & c, unsigned level) const;
+       void do_print_latex(const print_latex & c, unsigned level) const;
+       void do_print_tree(const print_tree & c, unsigned level) const;
+
        // member variables
 protected:
        bool dotted;
        // member variables
 protected:
        bool dotted;
index 504a9fc46f875929518e571bd5711b8007b366c2..6a50fe1dcebcc1563da2a74f14da58157b933655 100644 (file)
@@ -34,7 +34,9 @@
 
 namespace GiNaC {
 
 
 namespace GiNaC {
 
-GINAC_IMPLEMENT_REGISTERED_CLASS(symmetry, basic)
+GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(symmetry, basic,
+  print_func<print_context>(&symmetry::do_print).
+  print_func<print_tree>(&symmetry::do_print_tree))
 
 /*
    Some notes about the structure of a symmetry tree:
 
 /*
    Some notes about the structure of a symmetry tree:
@@ -146,63 +148,60 @@ int symmetry::compare_same_type(const basic & other) const
        return 0;
 }
 
        return 0;
 }
 
-void symmetry::print(const print_context & c, unsigned level) const
+void symmetry::do_print(const print_context & c, unsigned level) const
 {
 {
-       if (is_a<print_tree>(c)) {
-
-               c.s << std::string(level, ' ') << class_name()
-                   << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
-                   << ", type=";
-
+       if (children.empty()) {
+               if (indices.size() > 0)
+                       c.s << *(indices.begin());
+               else
+                       c.s << "none";
+       } else {
                switch (type) {
                switch (type) {
-                       case none: c.s << "none"; break;
-                       case symmetric: c.s << "symm"; break;
-                       case antisymmetric: c.s << "anti"; break;
-                       case cyclic: c.s << "cycl"; break;
-                       default: c.s << "<unknown>"; break;
+                       case none: c.s << '!'; break;
+                       case symmetric: c.s << '+'; break;
+                       case antisymmetric: c.s << '-'; break;
+                       case cyclic: c.s << '@'; break;
+                       default: c.s << '?'; break;
                }
                }
-
-               c.s << ", indices=(";
-               if (!indices.empty()) {
-                       std::set<unsigned>::const_iterator i = indices.begin(), end = indices.end();
-                       --end;
-                       while (i != end)
-                               c.s << *i++ << ",";
-                       c.s << *i;
+               c.s << '(';
+               size_t num = children.size();
+               for (size_t i=0; i<num; i++) {
+                       children[i].print(c);
+                       if (i != num - 1)
+                               c.s << ",";
                }
                }
-               c.s << ")\n";
+               c.s << ')';
+       }
+}
 
 
-               unsigned delta_indent = static_cast<const print_tree &>(c).delta_indent;
-               exvector::const_iterator i = children.begin(), end = children.end();
-               while (i != end) {
-                       i->print(c, level + delta_indent);
-                       ++i;
-               }
+void symmetry::do_print_tree(const print_tree & c, unsigned level) const
+{
+       c.s << std::string(level, ' ') << class_name()
+           << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
+           << ", type=";
+
+       switch (type) {
+               case none: c.s << "none"; break;
+               case symmetric: c.s << "symm"; break;
+               case antisymmetric: c.s << "anti"; break;
+               case cyclic: c.s << "cycl"; break;
+               default: c.s << "<unknown>"; break;
+       }
 
 
-       } else {
+       c.s << ", indices=(";
+       if (!indices.empty()) {
+               std::set<unsigned>::const_iterator i = indices.begin(), end = indices.end();
+               --end;
+               while (i != end)
+                       c.s << *i++ << ",";
+               c.s << *i;
+       }
+       c.s << ")\n";
 
 
-               if (children.empty()) {
-                       if (indices.size() > 0)
-                               c.s << *(indices.begin());
-                       else
-                               c.s << "none";
-               } else {
-                       switch (type) {
-                               case none: c.s << '!'; break;
-                               case symmetric: c.s << '+'; break;
-                               case antisymmetric: c.s << '-'; break;
-                               case cyclic: c.s << '@'; break;
-                               default: c.s << '?'; break;
-                       }
-                       c.s << '(';
-                       size_t num = children.size();
-                       for (size_t i=0; i<num; i++) {
-                               children[i].print(c);
-                               if (i != num - 1)
-                                       c.s << ",";
-                       }
-                       c.s << ')';
-               }
+       exvector::const_iterator i = children.begin(), end = children.end();
+       while (i != end) {
+               i->print(c, level + c.delta_indent);
+               ++i;
        }
 }
 
        }
 }
 
index 0b805edc08c794a607b965e93e7bb95f3e55fab1..d5a3ca8d21bd77e547693e432ccc4ef81b9e34f3 100644 (file)
@@ -61,10 +61,6 @@ public:
        /** Create node with two children. */
        symmetry(symmetry_type t, const symmetry &c1, const symmetry &c2);
 
        /** Create node with two children. */
        symmetry(symmetry_type t, const symmetry &c1, const symmetry &c2);
 
-       // functions overriding virtual functions from base classes
-public:
-       void print(const print_context & c, unsigned level = 0) const;
-
        // non-virtual functions in this class
 public:
        /** Get symmetry type. */
        // non-virtual functions in this class
 public:
        /** Get symmetry type. */
@@ -85,6 +81,10 @@ public:
        /** Check whether this node actually represents any kind of symmetry. */
        bool has_symmetry() const {return type != none || !children.empty(); }
 
        /** Check whether this node actually represents any kind of symmetry. */
        bool has_symmetry() const {return type != none || !children.empty(); }
 
+protected:
+       void do_print(const print_context & c, unsigned level) const;
+       void do_print_tree(const print_tree & c, unsigned level) const;
+
        // member variables
 private:
        /** Type of symmetry described by this node. */
        // member variables
 private:
        /** Type of symmetry described by this node. */