From: Christian Bauer Date: Thu, 31 Jul 2003 00:11:16 +0000 (+0000) Subject: use new-style print methods X-Git-Tag: release_1-0-15~7 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=488cad4c124885230154720041bd51fa4d983a8b;hp=1ed8f877ea0ca066c276d5bea08f2e775559aa81 use new-style print methods --- diff --git a/ginac/clifford.cpp b/ginac/clifford.cpp index 0b3801e1..ff834bce 100644 --- a/ginac/clifford.cpp +++ b/ginac/clifford.cpp @@ -40,12 +40,29 @@ 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(&clifford::do_print_dflt). + print_func(&clifford::do_print_latex)) + +GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(diracone, tensor, + print_func(&diracone::do_print). + print_func(&diracone::do_print_latex)) + +GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(diracgamma, tensor, + print_func(&diracgamma::do_print). + print_func(&diracgamma::do_print_latex)) + +GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(diracgamma5, tensor, + print_func(&diracgamma5::do_print). + print_func(&diracgamma5::do_print_latex)) + +GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(diracgammaL, tensor, + print_func(&diracgammaL::do_print). + print_func(&diracgammaL::do_print_latex)) + +GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(diracgammaR, tensor, + print_func(&diracgammaR::do_print). + print_func(&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(seq[0]) && !is_a(seq[0]) && - !is_a(seq[0]) && !is_a(seq[0]) && - !is_a(seq[0])) { - - // dirac_slash() object is printed differently - if (is_a(c)) - inherited::print(c, level); - else if (is_a(c)) { - c.s << "{"; - seq[0].print(c, level); - c.s << "\\hspace{-1.0ex}/}"; - } else { - seq[0].print(c, level); - c.s << "\\"; - } + return !is_a(seq0) && !is_a(seq0) && + !is_a(seq0) && !is_a(seq0) && + !is_a(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(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(c, level); } DEFAULT_COMPARE(diracone) diff --git a/ginac/clifford.h b/ginac/clifford.h index 8dbc3767..eebe5e1f 100644 --- a/ginac/clifford.h +++ b/ginac/clifford.h @@ -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; }; diff --git a/ginac/color.cpp b/ginac/color.cpp index fc66b544..1fb8e97d 100644 --- a/ginac/color.cpp +++ b/ginac/color.cpp @@ -39,10 +39,22 @@ 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(&su3one::do_print). + print_func(&su3one::do_print_latex)) + +GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(su3t, tensor, + print_func(&su3t::do_print). + print_func(&su3t::do_print)) + +GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(su3f, tensor, + print_func(&su3f::do_print). + print_func(&su3f::do_print)) + +GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(su3d, tensor, + print_func(&su3d::do_print). + print_func(&su3d::do_print)) ////////// // default constructors diff --git a/ginac/color.h b/ginac/color.h index e7ad0618..3af0c5c2 100644 --- a/ginac/color.h +++ b/ginac/color.h @@ -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; }; diff --git a/ginac/fail.cpp b/ginac/fail.cpp index 92aaa102..08ee89aa 100644 --- a/ginac/fail.cpp +++ b/ginac/fail.cpp @@ -30,7 +30,9 @@ namespace GiNaC { -GINAC_IMPLEMENT_REGISTERED_CLASS(fail, basic) +GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(fail, basic, + print_func(&fail::do_print). + print_func(&basic::do_print_tree)) ////////// // default constructor diff --git a/ginac/fail.h b/ginac/fail.h index a537fa04..75a75bfc 100644 --- a/ginac/fail.h +++ b/ginac/fail.h @@ -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(obj) for fail objects. */ diff --git a/ginac/symbol.cpp b/ginac/symbol.cpp index 6b265a77..1ed94f3d 100644 --- a/ginac/symbol.cpp +++ b/ginac/symbol.cpp @@ -32,7 +32,11 @@ namespace GiNaC { -GINAC_IMPLEMENT_REGISTERED_CLASS(symbol, basic) +GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(symbol, basic, + print_func(&symbol::do_print). + print_func(&symbol::do_print_latex). + print_func(&symbol::do_print_tree). + print_func(&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(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(c)) { - c.s << TeX_name; - } else if (is_a(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 diff --git a/ginac/symbol.h b/ginac/symbol.h index 55f2826c..5794f46d 100644 --- a/ginac/symbol.h +++ b/ginac/symbol.h @@ -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; diff --git a/ginac/tensor.cpp b/ginac/tensor.cpp index 302c0f63..a682f2dd 100644 --- a/ginac/tensor.cpp +++ b/ginac/tensor.cpp @@ -40,11 +40,26 @@ 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(&tensdelta::do_print). + print_func(&tensdelta::do_print_latex)) + +GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(tensmetric, tensor, + print_func(&tensmetric::do_print). + print_func(&tensmetric::do_print)) + +GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(minkmetric, tensmetric, + print_func(&minkmetric::do_print). + print_func(&minkmetric::do_print_latex)) + +GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(spinmetric, tensmetric, + print_func(&spinmetric::do_print). + print_func(&spinmetric::do_print_latex)) + +GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(tensepsilon, tensor, + print_func(&tensepsilon::do_print). + print_func(&tensepsilon::do_print_latex)) ////////// // constructors diff --git a/ginac/tensor.h b/ginac/tensor.h index 712ec7e1..446ede86 100644 --- a/ginac/tensor.h +++ b/ginac/tensor.h @@ -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. */ diff --git a/ginac/wildcard.cpp b/ginac/wildcard.cpp index 97fab9e9..a0d59349 100644 --- a/ginac/wildcard.cpp +++ b/ginac/wildcard.cpp @@ -29,7 +29,10 @@ namespace GiNaC { -GINAC_IMPLEMENT_REGISTERED_CLASS(wildcard, basic) +GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(wildcard, basic, + print_func(&wildcard::do_print). + print_func(&wildcard::do_print_tree). + print_func(&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(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(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 diff --git a/ginac/wildcard.h b/ginac/wildcard.h index 86c5f4a1..42c874ff 100644 --- a/ginac/wildcard.h +++ b/ginac/wildcard.h @@ -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 */