use new-style print methods
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Thu, 31 Jul 2003 00:11:16 +0000 (00:11 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Thu, 31 Jul 2003 00:11:16 +0000 (00:11 +0000)
12 files changed:
ginac/clifford.cpp
ginac/clifford.h
ginac/color.cpp
ginac/color.h
ginac/fail.cpp
ginac/fail.h
ginac/symbol.cpp
ginac/symbol.h
ginac/tensor.cpp
ginac/tensor.h
ginac/wildcard.cpp
ginac/wildcard.h

index 0b3801e..ff834bc 100644 (file)
 
 namespace GiNaC {
 
-GINAC_IMPLEMENT_REGISTERED_CLASS(clifford, indexed)
-GINAC_IMPLEMENT_REGISTERED_CLASS(diracone, tensor)
-GINAC_IMPLEMENT_REGISTERED_CLASS(diracgamma, tensor)
-GINAC_IMPLEMENT_REGISTERED_CLASS(diracgamma5, tensor)
-GINAC_IMPLEMENT_REGISTERED_CLASS(diracgammaL, tensor)
-GINAC_IMPLEMENT_REGISTERED_CLASS(diracgammaR, tensor)
+GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(clifford, indexed,
+  print_func<print_dflt>(&clifford::do_print_dflt).
+  print_func<print_latex>(&clifford::do_print_latex))
+
+GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(diracone, tensor,
+  print_func<print_dflt>(&diracone::do_print).
+  print_func<print_latex>(&diracone::do_print_latex))
+
+GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(diracgamma, tensor,
+  print_func<print_dflt>(&diracgamma::do_print).
+  print_func<print_latex>(&diracgamma::do_print_latex))
+
+GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(diracgamma5, tensor,
+  print_func<print_dflt>(&diracgamma5::do_print).
+  print_func<print_latex>(&diracgamma5::do_print_latex))
+
+GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(diracgammaL, tensor,
+  print_func<print_context>(&diracgammaL::do_print).
+  print_func<print_latex>(&diracgammaL::do_print_latex))
+
+GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(diracgammaR, tensor,
+  print_func<print_context>(&diracgammaR::do_print).
+  print_func<print_latex>(&diracgammaR::do_print_latex))
 
 //////////
 // default constructors
@@ -142,26 +159,32 @@ bool clifford::match_same_type(const basic & other) const
        return representation_label == o.representation_label;
 }
 
-void clifford::print(const print_context & c, unsigned level) const
+static bool is_dirac_slash(const ex & seq0)
 {
-       if (!is_a<diracgamma5>(seq[0]) && !is_a<diracgammaL>(seq[0]) &&
-           !is_a<diracgammaR>(seq[0]) && !is_a<diracgamma>(seq[0]) &&
-           !is_a<diracone>(seq[0])) {
-
-               // dirac_slash() object is printed differently
-               if (is_a<print_tree>(c))
-                       inherited::print(c, level);
-               else if (is_a<print_latex>(c)) {
-                       c.s << "{";
-                       seq[0].print(c, level);
-                       c.s << "\\hspace{-1.0ex}/}";
-               } else {
-                       seq[0].print(c, level);
-                       c.s << "\\";
-               }
+       return !is_a<diracgamma5>(seq0) && !is_a<diracgammaL>(seq0) &&
+              !is_a<diracgammaR>(seq0) && !is_a<diracgamma>(seq0) &&
+              !is_a<diracone>(seq0);
+}
+
+void clifford::do_print_dflt(const print_dflt & c, unsigned level) const
+{
+       // dirac_slash() object is printed differently
+       if (is_dirac_slash(seq[0])) {
+               seq[0].print(c, level);
+               c.s << "\\";
+       } else
+               this->print_dispatch<inherited>(c, level);
+}
 
+void clifford::do_print_latex(const print_latex & c, unsigned level) const
+{
+       // dirac_slash() object is printed differently
+       if (is_dirac_slash(seq[0])) {
+               c.s << "{";
+               seq[0].print(c, level);
+               c.s << "\\hspace{-1.0ex}/}";
        } else
-               inherited::print(c, level);
+               this->print_dispatch<inherited>(c, level);
 }
 
 DEFAULT_COMPARE(diracone)
index 8dbc376..eebe5e1 100644 (file)
@@ -48,9 +48,6 @@ public:
        clifford(unsigned char rl, exvector * vp); // vp will be deleted
 
        // functions overriding virtual functions from base classes
-public:
-       void print(const print_context & c, unsigned level = 0) const;
-
 protected:
        ex eval_ncmul(const exvector & v) const;
        bool match_same_type(const basic & other) const;
@@ -63,6 +60,10 @@ protected:
 public:
        unsigned char get_representation_label() const {return representation_label;}
 
+protected:
+       void do_print_dflt(const print_dflt & c, unsigned level) const;
+       void do_print_latex(const print_latex & c, unsigned level) const;
+
        // member variables
 private:
        unsigned char representation_label; /**< Representation label to distinguish independent spin lines */
@@ -74,9 +75,10 @@ class diracone : public tensor
 {
        GINAC_DECLARE_REGISTERED_CLASS(diracone, tensor)
 
-       // functions overriding virtual functions from base classes
-public:
-       void print(const print_context & c, unsigned level = 0) const;
+       // non-virtual functions in this class
+protected:
+       void do_print(const print_context & c, unsigned level) const;
+       void do_print_latex(const print_latex & c, unsigned level) const;
 };
 
 
@@ -87,8 +89,12 @@ class diracgamma : public tensor
 
        // functions overriding virtual functions from base classes
 public:
-       void print(const print_context & c, unsigned level = 0) const;
        bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
+
+       // non-virtual functions in this class
+protected:
+       void do_print(const print_context & c, unsigned level) const;
+       void do_print_latex(const print_latex & c, unsigned level) const;
 };
 
 
@@ -98,9 +104,10 @@ class diracgamma5 : public tensor
 {
        GINAC_DECLARE_REGISTERED_CLASS(diracgamma5, tensor)
 
-       // functions overriding virtual functions from base classes
-public:
-       void print(const print_context & c, unsigned level = 0) const;
+       // non-virtual functions in this class
+protected:
+       void do_print(const print_context & c, unsigned level) const;
+       void do_print_latex(const print_latex & c, unsigned level) const;
 };
 
 
@@ -110,9 +117,10 @@ class diracgammaL : public tensor
 {
        GINAC_DECLARE_REGISTERED_CLASS(diracgammaL, tensor)
 
-       // functions overriding virtual functions from base classes
-public:
-       void print(const print_context & c, unsigned level = 0) const;
+       // non-virtual functions in this class
+protected:
+       void do_print(const print_context & c, unsigned level) const;
+       void do_print_latex(const print_latex & c, unsigned level) const;
 };
 
 
@@ -122,9 +130,10 @@ class diracgammaR : public tensor
 {
        GINAC_DECLARE_REGISTERED_CLASS(diracgammaR, tensor)
 
-       // functions overriding virtual functions from base classes
-public:
-       void print(const print_context & c, unsigned level = 0) const;
+       // non-virtual functions in this class
+protected:
+       void do_print(const print_context & c, unsigned level) const;
+       void do_print_latex(const print_latex & c, unsigned level) const;
 };
 
 
index fc66b54..1fb8e97 100644 (file)
 namespace GiNaC {
 
 GINAC_IMPLEMENT_REGISTERED_CLASS(color, indexed)
-GINAC_IMPLEMENT_REGISTERED_CLASS(su3one, tensor)
-GINAC_IMPLEMENT_REGISTERED_CLASS(su3t, tensor)
-GINAC_IMPLEMENT_REGISTERED_CLASS(su3f, tensor)
-GINAC_IMPLEMENT_REGISTERED_CLASS(su3d, tensor)
+
+GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(su3one, tensor,
+  print_func<print_dflt>(&su3one::do_print).
+  print_func<print_latex>(&su3one::do_print_latex))
+
+GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(su3t, tensor,
+  print_func<print_dflt>(&su3t::do_print).
+  print_func<print_latex>(&su3t::do_print))
+
+GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(su3f, tensor,
+  print_func<print_dflt>(&su3f::do_print).
+  print_func<print_latex>(&su3f::do_print))
+
+GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(su3d, tensor,
+  print_func<print_dflt>(&su3d::do_print).
+  print_func<print_latex>(&su3d::do_print))
 
 //////////
 // default constructors
index e7ad061..3af0c5c 100644 (file)
@@ -73,9 +73,10 @@ class su3one : public tensor
 {
        GINAC_DECLARE_REGISTERED_CLASS(su3one, tensor)
 
-       // functions overriding virtual functions from base classes
-public:
-       void print(const print_context & c, unsigned level = 0) const;
+       // non-virtual functions in this class
+protected:
+       void do_print(const print_context & c, unsigned level) const;
+       void do_print_latex(const print_latex & c, unsigned level) const;
 };
 
 /** This class represents an su(3) generator. */
@@ -85,8 +86,12 @@ class su3t : public tensor
 
        // functions overriding virtual functions from base classes
 public:
-       void print(const print_context & c, unsigned level = 0) const;
        bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
+
+       // non-virtual functions in this class
+protected:
+       void do_print(const print_context & c, unsigned level) const;
+       void do_print_latex(const print_latex & c, unsigned level) const;
 };
 
 /** This class represents the tensor of antisymmetric su(3) structure
@@ -97,9 +102,13 @@ class su3f : public tensor
 
        // functions overriding virtual functions from base classes
 public:
-       void print(const print_context & c, unsigned level = 0) const;
        ex eval_indexed(const basic & i) const;
        bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
+
+       // non-virtual functions in this class
+protected:
+       void do_print(const print_context & c, unsigned level) const;
+       void do_print_latex(const print_latex & c, unsigned level) const;
 };
 
 /** This class represents the tensor of symmetric su(3) structure constants. */
@@ -109,9 +118,13 @@ class su3d : public tensor
 
        // functions overriding virtual functions from base classes
 public:
-       void print(const print_context & c, unsigned level = 0) const;
        ex eval_indexed(const basic & i) const;
        bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
+
+       // non-virtual functions in this class
+protected:
+       void do_print(const print_context & c, unsigned level) const;
+       void do_print_latex(const print_latex & c, unsigned level) const;
 };
 
 
index 92aaa10..08ee89a 100644 (file)
@@ -30,7 +30,9 @@
 
 namespace GiNaC {
 
-GINAC_IMPLEMENT_REGISTERED_CLASS(fail, basic)
+GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(fail, basic,
+  print_func<print_context>(&fail::do_print).
+  print_func<print_tree>(&basic::do_print_tree))
 
 //////////
 // default constructor
index a537fa0..75a75bf 100644 (file)
@@ -33,10 +33,12 @@ class fail : public basic
        GINAC_DECLARE_REGISTERED_CLASS(fail, basic)
        
        // functions overriding virtual functions from base classes
-public:
-       void print(const print_context & c, unsigned level = 0) const;
 protected:
        unsigned return_type() const { return return_types::noncommutative_composite; };
+
+       // non-virtual functions in this class
+protected:
+       void do_print(const print_context & c, unsigned level) const;
 };
 
 /** Specialization of is_exactly_a<fail>(obj) for fail objects. */
index 6b265a7..1ed94f3 100644 (file)
 
 namespace GiNaC {
 
-GINAC_IMPLEMENT_REGISTERED_CLASS(symbol, basic)
+GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(symbol, basic,
+  print_func<print_context>(&symbol::do_print).
+  print_func<print_latex>(&symbol::do_print_latex).
+  print_func<print_tree>(&symbol::do_print_tree).
+  print_func<print_python_repr>(&symbol::do_print_python_repr))
 
 //////////
 // default constructor
@@ -108,24 +112,30 @@ void symbol::archive(archive_node &n) const
 
 // public
 
-void symbol::print(const print_context & c, unsigned level) const
+void symbol::do_print(const print_context & c, unsigned level) const
 {
-       if (is_a<print_tree>(c)) {
-
-               c.s << std::string(level, ' ') << name << " (" << class_name() << ")"
-                   << ", serial=" << serial
-                   << 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 != default_TeX_name())
-                       c.s << "','" << TeX_name;
-               c.s << "')";
-       } else
-               c.s << name;
+       c.s << name;
+}
+
+void symbol::do_print_latex(const print_latex & c, unsigned level) const
+{
+       c.s << TeX_name;
+}
+
+void symbol::do_print_tree(const print_tree & c, unsigned level) const
+{
+       c.s << std::string(level, ' ') << name << " (" << class_name() << ")"
+           << ", serial=" << serial
+           << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
+           << std::endl;
+}
+
+void symbol::do_print_python_repr(const print_python_repr & c, unsigned level) const
+{
+       c.s << class_name() << "('" << name;
+       if (TeX_name != default_TeX_name())
+               c.s << "','" << TeX_name;
+       c.s << "')";
 }
 
 bool symbol::info(unsigned inf) const
index 55f2826..5794f46 100644 (file)
@@ -62,7 +62,6 @@ public:
        
        // functions overriding virtual functions from base classes
 public:
-       void print(const print_context & c, unsigned level = 0) const;
        bool info(unsigned inf) const;
        ex eval(int level = 0) const;
        ex evalf(int level = 0) const { return *this; } // overwrites basic::evalf() for performance reasons
@@ -82,6 +81,11 @@ public:
        void unassign();
        void set_name(const std::string & n) { name = n; }
        std::string get_name() const { return name; }
+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;
+       void do_print_python_repr(const print_python_repr & c, unsigned level) const;
 private:
        std::string & autoname_prefix();
        std::string default_TeX_name() const;
index 302c0f6..a682f2d 100644 (file)
 namespace GiNaC {
 
 GINAC_IMPLEMENT_REGISTERED_CLASS(tensor, basic)
-GINAC_IMPLEMENT_REGISTERED_CLASS(tensdelta, tensor)
-GINAC_IMPLEMENT_REGISTERED_CLASS(tensmetric, tensor)
-GINAC_IMPLEMENT_REGISTERED_CLASS(minkmetric, tensmetric)
-GINAC_IMPLEMENT_REGISTERED_CLASS(spinmetric, tensmetric)
-GINAC_IMPLEMENT_REGISTERED_CLASS(tensepsilon, tensor)
+
+GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(tensdelta, tensor,
+  print_func<print_dflt>(&tensdelta::do_print).
+  print_func<print_latex>(&tensdelta::do_print_latex))
+
+GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(tensmetric, tensor,
+  print_func<print_dflt>(&tensmetric::do_print).
+  print_func<print_latex>(&tensmetric::do_print))
+
+GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(minkmetric, tensmetric,
+  print_func<print_dflt>(&minkmetric::do_print).
+  print_func<print_latex>(&minkmetric::do_print_latex))
+
+GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(spinmetric, tensmetric,
+  print_func<print_dflt>(&spinmetric::do_print).
+  print_func<print_latex>(&spinmetric::do_print_latex))
+
+GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(tensepsilon, tensor,
+  print_func<print_dflt>(&tensepsilon::do_print).
+  print_func<print_latex>(&tensepsilon::do_print_latex))
 
 //////////
 // constructors
index 712ec7e..446ede8 100644 (file)
@@ -60,9 +60,13 @@ class tensdelta : public tensor
 
        // functions overriding virtual functions from base classes
 public:
-       void print(const print_context & c, unsigned level = 0) const;
        ex eval_indexed(const basic & i) const;
        bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
+
+       // non-virtual functions in this class
+protected:
+       void do_print(const print_context & c, unsigned level) const;
+       void do_print_latex(const print_latex & c, unsigned level) const;
 };
 
 
@@ -75,9 +79,12 @@ class tensmetric : public tensor
 
        // functions overriding virtual functions from base classes
 public:
-       void print(const print_context & c, unsigned level = 0) const;
        ex eval_indexed(const basic & i) const;
        bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
+
+       // non-virtual functions in this class
+protected:
+       void do_print(const print_context & c, unsigned level) const;
 };
 
 
@@ -95,9 +102,13 @@ public:
 
        // functions overriding virtual functions from base classes
 public:
-       void print(const print_context & c, unsigned level = 0) const;
        ex eval_indexed(const basic & i) const;
 
+       // non-virtual functions in this class
+protected:
+       void do_print(const print_context & c, unsigned level) const;
+       void do_print_latex(const print_latex & c, unsigned level) const;
+
        // member variables
 private:
        bool pos_sig; /**< If true, the metric is diag(-1,1,1...). Otherwise it is diag(1,-1,-1,...). */
@@ -114,9 +125,13 @@ class spinmetric : public tensmetric
 
        // functions overriding virtual functions from base classes
 public:
-       void print(const print_context & c, unsigned level = 0) const;
        ex eval_indexed(const basic & i) const;
        bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
+
+       // non-virtual functions in this class
+protected:
+       void do_print(const print_context & c, unsigned level) const;
+       void do_print_latex(const print_latex & c, unsigned level) const;
 };
 
 
@@ -133,10 +148,14 @@ public:
 
        // functions overriding virtual functions from base classes
 public:
-       void print(const print_context & c, unsigned level = 0) const;
        ex eval_indexed(const basic & i) const;
        bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
 
+       // non-virtual functions in this class
+protected:
+       void do_print(const print_context & c, unsigned level) const;
+       void do_print_latex(const print_latex & c, unsigned level) const;
+
        // member variables
 private:
        bool minkowski; /**< If true, tensor is in Minkowski-type space. Otherwise it is in a Euclidean space. */
index 97fab9e..a0d5934 100644 (file)
 
 namespace GiNaC {
 
-GINAC_IMPLEMENT_REGISTERED_CLASS(wildcard, basic)
+GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(wildcard, basic,
+  print_func<print_context>(&wildcard::do_print).
+  print_func<print_tree>(&wildcard::do_print_tree).
+  print_func<print_python_repr>(&wildcard::do_print_python_repr))
 
 //////////
 // default constructor
@@ -82,16 +85,21 @@ int wildcard::compare_same_type(const basic & other) const
                return label < o.label ? -1 : 1;
 }
 
-void wildcard::print(const print_context & c, unsigned level) const
+void wildcard::do_print(const print_context & c, unsigned level) const
 {
-       if (is_a<print_tree>(c)) {
-               c.s << std::string(level, ' ') << class_name() << " (" << label << ")"
-                   << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
-                   << std::endl;
-       } else if (is_a<print_python_repr>(c)) {
-               c.s << class_name() << '(' << label << ')';
-       } else
-               c.s << "$" << label;
+       c.s << "$" << label;
+}
+
+void wildcard::do_print_tree(const print_tree & c, unsigned level) const
+{
+       c.s << std::string(level, ' ') << class_name() << " (" << label << ")"
+           << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
+           << std::endl;
+}
+
+void wildcard::do_print_python_repr(const print_python_repr & c, unsigned level) const
+{
+       c.s << class_name() << '(' << label << ')';
 }
 
 unsigned wildcard::calchash() const
index 86c5f4a..42c874f 100644 (file)
@@ -41,7 +41,6 @@ public:
 
        // functions overriding virtual functions from base classes
 public:
-       void print(const print_context & c, unsigned level = 0) const;
        bool match(const ex & pattern, lst & repl_lst) const;
 
 protected:
@@ -51,6 +50,11 @@ protected:
 public:
        unsigned get_label() const {return label;}
 
+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_python_repr(const print_python_repr & c, unsigned level) const;
+
        // member variables
 private:
        unsigned label; /**< Label used to distinguish different wildcards */