]> www.ginac.de Git - ginac.git/blobdiff - ginac/basic.cpp
Replace use of NULL by C++11 nullptr.
[ginac.git] / ginac / basic.cpp
index fa6e1d9679be426b90bd75acfee56c8babb4835b..563dd7d5b6455fe9453885111bb0aac7a4259ed9 100644 (file)
@@ -3,7 +3,7 @@
  *  Implementation of GiNaC's ABC. */
 
 /*
- *  GiNaC Copyright (C) 1999-2008 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2015 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 <iostream>
-#include <stdexcept>
-#include <typeinfo>
-
 #include "basic.h"
 #include "ex.h"
 #include "numeric.h"
 #include "wildcard.h"
 #include "archive.h"
 #include "utils.h"
+#include "hash_seed.h"
 #include "inifcns.h"
 
+#include <iostream>
+#include <stdexcept>
+#include <typeinfo>
+
 namespace GiNaC {
 
 GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(basic, void,
@@ -55,7 +56,7 @@ GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(basic, void,
 /** basic copy constructor: implicitly assumes that the other class is of
  *  the exact same type (as it's used by duplicate()), so it can copy the
  *  tinfo_key and the hash value. */
-basic::basic(const basic & other) : tinfo_key(other.tinfo_key), flags(other.flags & ~status_flags::dynallocated), hashvalue(other.hashvalue)
+basic::basic(const basic & other) : flags(other.flags & ~status_flags::dynallocated), hashvalue(other.hashvalue)
 {
 }
 
@@ -92,18 +93,8 @@ const basic & basic::operator=(const basic & other)
 //////////
 
 /** Construct object from archive_node. */
-basic::basic(const archive_node &n, lst &sym_lst) : flags(0)
-{
-       // Reconstruct tinfo_key from class name
-       std::string class_name;
-       if (n.find_string("class", class_name))
-               tinfo_key = find_tinfo_key(class_name);
-       else
-               throw (std::runtime_error("archive node contains no class name"));
-}
-
-/** Unarchive the object. */
-DEFAULT_UNARCHIVE(basic)
+void basic::read_archive(const archive_node& n, lst& syms)
+{ }
 
 /** Archive the object. */
 void basic::archive(archive_node &n) const
@@ -249,7 +240,7 @@ ex basic::op(size_t i) const
        throw(std::range_error(std::string("basic::op(): ") + class_name() + std::string(" has no operands")));
 }
 
-/** Return modifyable operand/member at position i. */
+/** Return modifiable operand/member at position i. */
 ex & basic::let_op(size_t i)
 {
        ensure_if_modifiable();
@@ -306,12 +297,12 @@ ex basic::map(map_function & f) const
        if (num == 0)
                return *this;
 
-       basic *copy = NULL;
+       basic *copy = nullptr;
        for (size_t i=0; i<num; i++) {
                const ex & o = op(i);
                const ex & n = f(o);
                if (!are_ex_trivially_equal(o, n)) {
-                       if (copy == NULL)
+                       if (copy == nullptr)
                                copy = duplicate();
                        copy->let_op(i) = n;
                }
@@ -774,9 +765,12 @@ unsigned basic::return_type() const
        return return_types::commutative;
 }
 
-tinfo_t basic::return_type_tinfo() const
+return_type_t basic::return_type_tinfo() const
 {
-       return tinfo_key;
+       return_type_t rt;
+       rt.tinfo = &typeid(*this);
+       rt.rl = 0;
+       return rt;
 }
 
 /** Compute the hash value of an object and if it makes sense to store it in
@@ -787,8 +781,7 @@ tinfo_t basic::return_type_tinfo() const
  *  would all end up with the same hashvalue. */
 unsigned basic::calchash() const
 {
-       const void* this_tinfo = (const void*)typeid(*this).name();
-       unsigned v = golden_ratio_hash((p_int)this_tinfo);
+       unsigned v = make_hash_seed(typeid(*this));
        for (size_t i=0; i<nops(); i++) {
                v = rotate_left(v);
                v ^= this->op(i).gethash();