]> www.ginac.de Git - ginac.git/blobdiff - ginac/wildcard.cpp
Finalize 1.7.6 release.
[ginac.git] / ginac / wildcard.cpp
index f203c5f09d8d56b1ab5d5f6d8e8c667a5105644d..cdfa2ab475f84a5898ff7b72c197a59349b6d4cf 100644 (file)
@@ -3,7 +3,7 @@
  *  Implementation of GiNaC's wildcard objects. */
 
 /*
- *  GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2019 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
  *
  *  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 "wildcard.h"
-#include "print.h"
 #include "archive.h"
 #include "utils.h"
-#include "debugmsg.h"
+#include "hash_seed.h"
+
+#include <iostream>
 
 namespace GiNaC {
 
-GINAC_IMPLEMENT_REGISTERED_CLASS(wildcard, basic)
+GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(wildcard, basic,
+  print_func<print_context>(&wildcard::do_print).
+  print_func<print_tree>(&wildcard::do_print_tree).
+  print_func<print_python_repr>(&wildcard::do_print_python_repr))
 
 //////////
-// default constructor, destructor, copy constructor assignment operator and helpers
+// default constructor
 //////////
 
 wildcard::wildcard() : label(0)
 {
-       debugmsg("wildcard default constructor", LOGLEVEL_CONSTRUCT);
-       tinfo_key = TINFO_wildcard;
-}
-
-void wildcard::copy(const wildcard & other)
-{
-       inherited::copy(other);
-       label = other.label;
+       setflag(status_flags::evaluated | status_flags::expanded);
 }
 
-DEFAULT_DESTROY(wildcard)
-
 //////////
 // other constructors
 //////////
 
 wildcard::wildcard(unsigned l) : label(l)
 {
-       debugmsg("wildcard constructor from unsigned", LOGLEVEL_CONSTRUCT);
-       tinfo_key = TINFO_wildcard;
+       setflag(status_flags::evaluated | status_flags::expanded);
 }
 
 //////////
 // archiving
 //////////
 
-wildcard::wildcard(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
+void wildcard::read_archive(const archive_node& n, lst& sym_lst)
 {
-       debugmsg("wildcard constructor from archive_node", LOGLEVEL_CONSTRUCT);
+       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
 {
@@ -74,8 +70,6 @@ void wildcard::archive(archive_node &n) const
        n.add_unsigned("label", label);
 }
 
-DEFAULT_UNARCHIVE(wildcard)
-
 //////////
 // functions overriding virtual functions from base classes
 //////////
@@ -91,29 +85,35 @@ 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
 {
-       debugmsg("wildcard print", LOGLEVEL_PRINT);
-
-       if (is_a<print_tree>(c)) {
-               c.s << std::string(level, ' ') << class_name() << " (" << label << ")"
-                   << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
-                   << std::endl;
-       } else
-               c.s << "$" << label;
+       c.s << "$" << label;
 }
 
-unsigned wildcard::calchash(void) const
+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
 {
        // 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);
+       unsigned seed = make_hash_seed(typeid(*this));
+       hashvalue = golden_ratio_hash(seed ^ 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
@@ -121,4 +121,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