]> www.ginac.de Git - ginac.git/blobdiff - ginac/symbol.cpp
Add support for Texinfo-5.0.
[ginac.git] / ginac / symbol.cpp
index aa8ebc0fc28a00f254c5209418a1f67883852da1..4d73c9eb4328b1ed232a3c95e5f3bf6c9aaa37a3 100644 (file)
@@ -3,7 +3,7 @@
  *  Implementation of GiNaC's symbolic objects. */
 
 /*
- *  GiNaC Copyright (C) 1999-2008 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2011 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
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include <string>
-#include <stdexcept>
-#include <map>
-
 #include "symbol.h"
 #include "lst.h"
 #include "archive.h"
 #include "tostring.h"
 #include "utils.h"
+#include "hash_seed.h"
 #include "inifcns.h"
 
+#include <map>
+#include <stdexcept>
+#include <string>
+
 namespace GiNaC {
 
 GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(symbol, basic,
@@ -108,6 +109,15 @@ void symbol::read_archive(const archive_node &n, lst &sym_lst)
        for (lst::const_iterator it = sym_lst.begin(); it != sym_lst.end(); ++it) {
                if (is_a<symbol>(*it) && (ex_to<symbol>(*it).name == tmp_name)) {
                        *this = ex_to<symbol>(*it);
+                       // XXX: This method is responsible for reading realsymbol
+                       // and possymbol objects too. But
+                       // basic::operator=(const basic& other)
+                       // resets status_flags::evaluated if other and *this are
+                       // of different types. Usually this is a good idea, but
+                       // doing this for symbols is wrong (for one, nothing is
+                       // going to set status_flags::evaluated, evaluation will
+                       // loop forever). Therefore we need to restore flags.
+                       setflag(status_flags::evaluated | status_flags::expanded);
                        return;
                }
        }
@@ -140,12 +150,21 @@ static const std::string& get_default_TeX_name(const std::string& name);
 
 // public
 
+std::string symbol::get_name() const
+{
+       if (name.empty()) {
+               std::ostringstream s;
+               s << "symbol" << serial;
+               name = s.str();
+       }
+       return name;
+}
+
+// protected
+
 void symbol::do_print(const print_context & c, unsigned level) const
 {
-       if (!name.empty())
-               c.s << name;
-       else
-               c.s << "symbol" << serial;
+       c.s << get_name();
 }
 
 void symbol::do_print_latex(const print_latex & c, unsigned level) const
@@ -253,8 +272,8 @@ bool symbol::is_equal_same_type(const basic & other) const
 
 unsigned symbol::calchash() const
 {
-       const void* this_tinfo = (const void*)typeid(*this).name();
-       hashvalue = golden_ratio_hash((p_int)this_tinfo ^ serial);
+       unsigned seed = make_hash_seed(typeid(*this));
+       hashvalue = golden_ratio_hash(seed ^ serial);
        setflag(status_flags::hash_calculated);
        return hashvalue;
 }