]> www.ginac.de Git - ginac.git/blob - ginac/wildcard.cpp
mentioned ncpow()
[ginac.git] / ginac / wildcard.cpp
1 /** @file wildcard.cpp
2  *
3  *  Implementation of GiNaC's wildcard objects. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
7  *
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.
12  *
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.
17  *
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
21  */
22
23 #include "wildcard.h"
24 #include "print.h"
25 #include "archive.h"
26 #include "utils.h"
27 #include "debugmsg.h"
28
29 namespace GiNaC {
30
31 GINAC_IMPLEMENT_REGISTERED_CLASS(wildcard, basic)
32
33 //////////
34 // default constructor, destructor, copy constructor assignment operator and helpers
35 //////////
36
37 wildcard::wildcard() : label(0)
38 {
39         debugmsg("wildcard default constructor", LOGLEVEL_CONSTRUCT);
40         tinfo_key = TINFO_wildcard;
41 }
42
43 void wildcard::copy(const wildcard & other)
44 {
45         inherited::copy(other);
46         label = other.label;
47 }
48
49 DEFAULT_DESTROY(wildcard)
50
51 //////////
52 // other constructors
53 //////////
54
55 wildcard::wildcard(unsigned l) : label(l)
56 {
57         debugmsg("wildcard constructor from unsigned", LOGLEVEL_CONSTRUCT);
58         tinfo_key = TINFO_wildcard;
59 }
60
61 //////////
62 // archiving
63 //////////
64
65 wildcard::wildcard(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
66 {
67         debugmsg("wildcard constructor from archive_node", LOGLEVEL_CONSTRUCT);
68         n.find_unsigned("label", label);
69 }
70
71 void wildcard::archive(archive_node &n) const
72 {
73         inherited::archive(n);
74         n.add_unsigned("label", label);
75 }
76
77 DEFAULT_UNARCHIVE(wildcard)
78
79 //////////
80 // functions overriding virtual functions from bases classes
81 //////////
82
83 int wildcard::compare_same_type(const basic & other) const
84 {
85         GINAC_ASSERT(is_of_type(other, wildcard));
86         const wildcard &o = static_cast<const wildcard &>(other);
87
88         if (label == o.label)
89                 return 0;
90         else
91                 return label < o.label ? -1 : 1;
92 }
93
94 void wildcard::print(const print_context & c, unsigned level = 0) const
95 {
96         debugmsg("wildcard print", LOGLEVEL_PRINT);
97
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
101                     << std::endl;
102         } else
103                 c.s << "$" << label;
104 }
105
106 unsigned wildcard::calchash(void) const
107 {
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);
113         return hashvalue;
114 }
115
116 bool wildcard::match(const ex & pattern, lst & repl_lst) const
117 {
118         // Wildcards must match exactly (this is required for subs() to work
119         // properly because in the final step it substitues all wildcards by
120         // their matching expressions)
121         return is_equal(*pattern.bp);
122 }
123
124 } // namespace GiNaC