X-Git-Url: https://ginac.de/ginac.git//ginac.git?a=blobdiff_plain;f=ginac%2Fwildcard.cpp;h=38a67de90a44792d811cf7b4666fa55dd6999353;hb=140461b30310931d750ad1f16bb7eb7e69352251;hp=97fab9e919e101895a52d13d7cb9058886236906;hpb=68fdf425abf14d016d5f95ee7b9d06a19a3c5926;p=ginac.git diff --git a/ginac/wildcard.cpp b/ginac/wildcard.cpp index 97fab9e9..38a67de9 100644 --- a/ginac/wildcard.cpp +++ b/ginac/wildcard.cpp @@ -3,7 +3,7 @@ * Implementation of GiNaC's wildcard objects. */ /* - * GiNaC Copyright (C) 1999-2003 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2007 Johannes Gutenberg University Mainz, Germany * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,25 +17,27 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include "wildcard.h" -#include "print.h" #include "archive.h" #include "utils.h" 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 ////////// -wildcard::wildcard() : inherited(TINFO_wildcard), label(0) +wildcard::wildcard() : inherited(&wildcard::tinfo_static), label(0) { setflag(status_flags::evaluated | status_flags::expanded); } @@ -44,7 +46,7 @@ wildcard::wildcard() : inherited(TINFO_wildcard), label(0) // other constructors ////////// -wildcard::wildcard(unsigned l) : inherited(TINFO_wildcard), label(l) +wildcard::wildcard(unsigned l) : inherited(&wildcard::tinfo_static), label(l) { setflag(status_flags::evaluated | status_flags::expanded); } @@ -82,16 +84,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 << ")" << " @" << this + << 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 @@ -99,7 +106,7 @@ unsigned wildcard::calchash() const // this is where the schoolbook method // (golden_ratio_hash(tinfo()) ^ label) // is not good enough yet... - hashvalue = golden_ratio_hash(golden_ratio_hash(tinfo()) ^ label); + hashvalue = golden_ratio_hash(golden_ratio_hash((p_int)tinfo()) ^ label); setflag(status_flags::hash_calculated); return hashvalue; } @@ -112,4 +119,14 @@ bool wildcard::match(const ex & pattern, lst & repl_lst) const return is_equal(ex_to(pattern)); } +bool haswild(const ex & x) +{ + if (is_a(x)) + return true; + for (size_t i=0; i