3 * Implementation of GiNaC's wildcard objects. */
6 * GiNaC Copyright (C) 1999-2001 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(wildcard, basic)
34 // default constructor, destructor, copy constructor assignment operator and helpers
37 wildcard::wildcard() : label(0)
39 debugmsg("wildcard default constructor", LOGLEVEL_CONSTRUCT);
40 tinfo_key = TINFO_wildcard;
43 void wildcard::copy(const wildcard & other)
45 inherited::copy(other);
49 DEFAULT_DESTROY(wildcard)
55 wildcard::wildcard(unsigned l) : label(l)
57 debugmsg("wildcard constructor from unsigned", LOGLEVEL_CONSTRUCT);
58 tinfo_key = TINFO_wildcard;
65 wildcard::wildcard(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
67 debugmsg("wildcard constructor from archive_node", LOGLEVEL_CONSTRUCT);
68 n.find_unsigned("label", label);
71 void wildcard::archive(archive_node &n) const
73 inherited::archive(n);
74 n.add_unsigned("label", label);
77 DEFAULT_UNARCHIVE(wildcard)
80 // functions overriding virtual functions from bases classes
83 int wildcard::compare_same_type(const basic & other) const
85 GINAC_ASSERT(is_of_type(other, wildcard));
86 const wildcard &o = static_cast<const wildcard &>(other);
91 return label < o.label ? -1 : 1;
94 void wildcard::print(const print_context & c, unsigned level = 0) const
96 debugmsg("wildcard print", LOGLEVEL_PRINT);
98 if (is_of_type(c, print_tree)) {
99 c.s << std::string(level, ' ') << class_name() << " (" << label << ")"
100 << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
106 unsigned wildcard::calchash(void) const
108 // this is where the schoolbook method
109 // (golden_ratio_hash(tinfo()) ^ label)
110 // is not good enough yet...
111 hashvalue = golden_ratio_hash(golden_ratio_hash(tinfo()) ^ label);
112 setflag(status_flags::hash_calculated);
116 bool wildcard::match(const ex & pattern, lst & repl_lst) const
118 // Wildcards must match exactly (this is required for subs() to work
119 // properly because in the final step it substitutes all wildcards by
120 // their matching expressions)
121 return is_equal(*pattern.bp);