]> www.ginac.de Git - ginac.git/blobdiff - ginac/wildcard.cpp
Univariate Hensel lifting now uses upoly.
[ginac.git] / ginac / wildcard.cpp
index 7ebc023e99eec6e86f08f304e90f8ef3a3789452..9409938d1e6de86a9b61f9fc7d9b22376f14ba92 100644 (file)
@@ -3,7 +3,7 @@
  *  Implementation of GiNaC's wildcard objects. */
 
 /*
- *  GiNaC Copyright (C) 1999-2004 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2008 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,7 +17,7 @@
  *
  *  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 <iostream>
@@ -37,7 +37,7 @@ GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(wildcard, basic,
 // default constructor
 //////////
 
-wildcard::wildcard() : inherited(TINFO_wildcard), label(0)
+wildcard::wildcard() : label(0)
 {
        setflag(status_flags::evaluated | status_flags::expanded);
 }
@@ -46,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) : label(l)
 {
        setflag(status_flags::evaluated | status_flags::expanded);
 }
@@ -55,11 +55,13 @@ wildcard::wildcard(unsigned l) : inherited(TINFO_wildcard), label(l)
 // archiving
 //////////
 
-wildcard::wildcard(const archive_node &n, lst &sym_lst) : inherited(n, sym_lst)
+void wildcard::read_archive(const archive_node& n, lst& sym_lst)
 {
+       inherited::read_archive(n, sym_lst);
        n.find_unsigned("label", label);
        setflag(status_flags::evaluated | status_flags::expanded);
 }
+GINAC_BIND_UNARCHIVER(wildcard);
 
 void wildcard::archive(archive_node &n) const
 {
@@ -67,8 +69,6 @@ void wildcard::archive(archive_node &n) const
        n.add_unsigned("label", label);
 }
 
-DEFAULT_UNARCHIVE(wildcard)
-
 //////////
 // functions overriding virtual functions from base classes
 //////////
@@ -104,14 +104,15 @@ void wildcard::do_print_python_repr(const print_python_repr & c, unsigned level)
 unsigned wildcard::calchash() const
 {
        // this is where the schoolbook method
-       // (golden_ratio_hash(tinfo()) ^ label)
+       // (golden_ratio_hash(typeid(*this).name()) ^ label)
        // is not good enough yet...
-       hashvalue = golden_ratio_hash(golden_ratio_hash(tinfo()) ^ label);
+       const void* this_tinfo = (const void*)typeid(*this).name();
+       hashvalue = golden_ratio_hash(golden_ratio_hash((p_int)this_tinfo) ^ label);
        setflag(status_flags::hash_calculated);
        return hashvalue;
 }
 
-bool wildcard::match(const ex & pattern, lst & repl_lst) const
+bool wildcard::match(const ex & pattern, exmap& repl_lst) const
 {
        // Wildcards must match each other exactly (this is required for
        // subs() to work properly because in the final step it substitutes
@@ -119,4 +120,14 @@ bool wildcard::match(const ex & pattern, lst & repl_lst) const
        return is_equal(ex_to<basic>(pattern));
 }
 
+bool haswild(const ex & x)
+{
+       if (is_a<wildcard>(x))
+               return true;
+       for (size_t i=0; i<x.nops(); ++i)
+               if (haswild(x.op(i)))
+                       return true;
+       return false;
+}
+
 } // namespace GiNaC