]> www.ginac.de Git - ginac.git/blobdiff - ginac/expairseq.cpp
basic, expairseq: use standard C++ RTTI in compare(), is_equal(), match(), etc.
[ginac.git] / ginac / expairseq.cpp
index 788f7834f4a5fc82a1a713e1f770ecaa194abdb0..120672f74498f3d44915ee77d71e91e48af6f1a6 100644 (file)
@@ -3,7 +3,7 @@
  *  Implementation of sequences of expression pairs. */
 
 /*
- *  GiNaC Copyright (C) 1999-2007 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
@@ -391,12 +391,12 @@ bool expairseq::is_polynomial(const ex & var) const
        return true;
 }
 
-bool expairseq::match(const ex & pattern, lst & repl_lst) const
+bool expairseq::match(const ex & pattern, exmap & repl_lst) const
 {
        // This differs from basic::match() because we want "a+b+c+d" to
        // match "d+*+b" with "*" being "a+c", and we want to honor commutativity
 
-       if (this->tinfo() == ex_to<basic>(pattern).tinfo()) {
+       if (typeid(*this) == typeid(ex_to<basic>(pattern))) {
 
                // Check whether global wildcard (one that matches the "rest of the
                // expression", like "*" above) is present
@@ -427,20 +427,10 @@ bool expairseq::match(const ex & pattern, lst & repl_lst) const
                                continue;
                        exvector::iterator it = ops.begin(), itend = ops.end();
                        while (it != itend) {
-                               lst::const_iterator last_el = repl_lst.end();
-                               --last_el;
                                if (it->match(p, repl_lst)) {
                                        ops.erase(it);
                                        goto found;
                                }
-                               while(true) {
-                                       lst::const_iterator next_el = last_el;
-                                       ++next_el;
-                                       if(next_el == repl_lst.end())
-                                               break;
-                                       else
-                                               repl_lst.remove_last();
-                               }
                                ++it;
                        }
                        return false; // no match found
@@ -458,11 +448,11 @@ found:            ;
                        for (size_t i=0; i<num; i++)
                                vp->push_back(split_ex_to_pair(ops[i]));
                        ex rest = thisexpairseq(vp, default_overall_coeff());
-                       for (lst::const_iterator it = repl_lst.begin(); it != repl_lst.end(); ++it) {
-                               if (it->op(0).is_equal(global_wildcard))
-                                       return rest.is_equal(it->op(1));
+                       for (exmap::const_iterator it = repl_lst.begin(); it != repl_lst.end(); ++it) {
+                               if (it->first.is_equal(global_wildcard))
+                                       return rest.is_equal(it->second);
                        }
-                       repl_lst.append(global_wildcard == rest);
+                       repl_lst[global_wildcard] = rest;
                        return true;
 
                } else {
@@ -803,8 +793,8 @@ void expairseq::construct_from_2_ex_via_exvector(const ex &lh, const ex &rh)
 
 void expairseq::construct_from_2_ex(const ex &lh, const ex &rh)
 {
-       if (ex_to<basic>(lh).tinfo()==this->tinfo()) {
-               if (ex_to<basic>(rh).tinfo()==this->tinfo()) {
+       if (typeid(ex_to<basic>(lh)) == typeid(*this)) {
+               if (typeid(ex_to<basic>(rh)) == typeid(*this)) {
 #if EXPAIRSEQ_USE_HASHTAB
                        unsigned totalsize = ex_to<expairseq>(lh).seq.size() +
                                             ex_to<expairseq>(rh).seq.size();
@@ -838,7 +828,7 @@ void expairseq::construct_from_2_ex(const ex &lh, const ex &rh)
 #endif // EXPAIRSEQ_USE_HASHTAB
                        return;
                }
-       } else if (ex_to<basic>(rh).tinfo()==this->tinfo()) {
+       } else if (typeid(ex_to<basic>(rh)) == typeid(*this)) {
 #if EXPAIRSEQ_USE_HASHTAB
                unsigned totalsize=ex_to<expairseq>(rh).seq.size()+1;
                if (calc_hashtabsize(totalsize)!=0) {
@@ -1061,7 +1051,7 @@ void expairseq::make_flat(const exvector &v)
        
        cit = v.begin();
        while (cit!=v.end()) {
-               if (ex_to<basic>(*cit).tinfo()==this->tinfo()) {
+               if (typeid(ex_to<basic>(*cit)) == typeid(*this)) {
                        ++nexpairseqs;
                        noperands += ex_to<expairseq>(*cit).seq.size();
                }
@@ -1078,7 +1068,7 @@ void expairseq::make_flat(const exvector &v)
        make_flat_inserter mf(v, do_idx_rename);
        cit = v.begin();
        while (cit!=v.end()) {
-               if (ex_to<basic>(*cit).tinfo()==this->tinfo()) {
+               if (typeid(ex_to<basic>(*cit)) == typeid(*this)) {
                        ex newfactor = mf.handle_factor(*cit, _ex1);
                        const expairseq &subseqref = ex_to<expairseq>(newfactor);
                        combine_overall_coeff(subseqref.overall_coeff);
@@ -1113,7 +1103,7 @@ void expairseq::make_flat(const epvector &v, bool do_index_renaming)
        
        cit = v.begin();
        while (cit!=v.end()) {
-               if (ex_to<basic>(cit->rest).tinfo()==this->tinfo()) {
+               if (typeid(ex_to<basic>(cit->rest)) == typeid(*this)) {
                        ++nexpairseqs;
                        noperands += ex_to<expairseq>(cit->rest).seq.size();
                }
@@ -1131,7 +1121,7 @@ void expairseq::make_flat(const epvector &v, bool do_index_renaming)
        // copy elements and split off numerical part
        cit = v.begin();
        while (cit!=v.end()) {
-               if (ex_to<basic>(cit->rest).tinfo()==this->tinfo() &&
+               if ((typeid(ex_to<basic>(cit->rest)) == typeid(*this)) &&
                    this->can_make_flat(*cit)) {
                        ex newrest = mf.handle_factor(cit->rest, cit->coeff);
                        const expairseq &subseqref = ex_to<expairseq>(newrest);