3 * Implementation of GiNaC's wildcard objects. */
6 * GiNaC Copyright (C) 1999-2004 Johannes Gutenberg University Mainz, Germany
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(wildcard, basic,
32 print_func<print_context>(&wildcard::do_print).
33 print_func<print_tree>(&wildcard::do_print_tree).
34 print_func<print_python_repr>(&wildcard::do_print_python_repr))
37 // default constructor
40 wildcard::wildcard() : inherited(TINFO_wildcard), label(0)
42 setflag(status_flags::evaluated | status_flags::expanded);
49 wildcard::wildcard(unsigned l) : inherited(TINFO_wildcard), label(l)
51 setflag(status_flags::evaluated | status_flags::expanded);
58 wildcard::wildcard(const archive_node &n, lst &sym_lst) : inherited(n, sym_lst)
60 n.find_unsigned("label", label);
61 setflag(status_flags::evaluated | status_flags::expanded);
64 void wildcard::archive(archive_node &n) const
66 inherited::archive(n);
67 n.add_unsigned("label", label);
70 DEFAULT_UNARCHIVE(wildcard)
73 // functions overriding virtual functions from base classes
76 int wildcard::compare_same_type(const basic & other) const
78 GINAC_ASSERT(is_a<wildcard>(other));
79 const wildcard &o = static_cast<const wildcard &>(other);
84 return label < o.label ? -1 : 1;
87 void wildcard::do_print(const print_context & c, unsigned level) const
92 void wildcard::do_print_tree(const print_tree & c, unsigned level) const
94 c.s << std::string(level, ' ') << class_name() << "(" << label << ")" << " @" << this
95 << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
99 void wildcard::do_print_python_repr(const print_python_repr & c, unsigned level) const
101 c.s << class_name() << '(' << label << ')';
104 unsigned wildcard::calchash() const
106 // this is where the schoolbook method
107 // (golden_ratio_hash(tinfo()) ^ label)
108 // is not good enough yet...
109 hashvalue = golden_ratio_hash(golden_ratio_hash(tinfo()) ^ label);
110 setflag(status_flags::hash_calculated);
114 bool wildcard::match(const ex & pattern, lst & repl_lst) const
116 // Wildcards must match each other exactly (this is required for
117 // subs() to work properly because in the final step it substitutes
118 // all wildcards by their matching expressions)
119 return is_equal(ex_to<basic>(pattern));