]> www.ginac.de Git - ginac.git/blobdiff - ginac/basic.cpp
added example for namespace bracing
[ginac.git] / ginac / basic.cpp
index 725f28a2e6b0ea40965ebbc45d50e6ca9d5e7a98..01a29011152a9c9ff7b58620e7a0da71c7561d75 100644 (file)
@@ -55,7 +55,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), refcount(0)
+basic::basic(const basic & other) : tinfo_key(other.tinfo_key), flags(other.flags & ~status_flags::dynallocated), hashvalue(other.hashvalue)
 {
        GINAC_ASSERT(typeid(*this) == typeid(other));
 }
@@ -68,13 +68,13 @@ const basic & basic::operator=(const basic & other)
                // The other object is of a derived class, so clear the flags as they
                // might no longer apply (especially hash_calculated). Oh, and don't
                // copy the tinfo_key: it is already set correctly for this object.
-               flags = 0;
+               fl &= ~(status_flags::evaluated | status_flags::expanded | status_flags::hash_calculated);
        } else {
                // The objects are of the exact same class, so copy the hash value.
                hashvalue = other.hashvalue;
        }
        flags = fl;
-       refcount = 0;
+       set_refcount(0);
        return *this;
 }
 
@@ -93,7 +93,7 @@ const basic & basic::operator=(const basic & other)
 //////////
 
 /** Construct object from archive_node. */
-basic::basic(const archive_node &n, lst &sym_lst) : flags(0), refcount(0)
+basic::basic(const archive_node &n, lst &sym_lst) : flags(0)
 {
        // Reconstruct tinfo_key from class name
        std::string class_name;
@@ -140,11 +140,9 @@ void basic::print_dispatch(const registered_class_info & ri, const print_context
        const print_context_class_info * pc_info = &c.get_class_info();
 
 next_class:
-std::clog << "searching class " << reg_info->options.get_name() << std::endl;
        const std::vector<print_functor> & pdt = reg_info->options.get_print_dispatch_table();
 
 next_context:
-std::clog << "searching context " << pc_info->options.get_name() << ", ID " << pc_info->options.get_id() << std::endl;
        unsigned id = pc_info->options.get_id();
        if (id >= pdt.size() || !(pdt[id].is_valid())) {
 
@@ -173,8 +171,6 @@ std::clog << "searching context " << pc_info->options.get_name() << ", ID " << p
        } else {
 
                // Call method
-std::clog << "method found, calling" << std::endl;
-std::clog << " this = " << class_name() << ", context = " << c.class_name() << std::endl;
                pdt[id](*this, c, level);
        }
 }
@@ -188,10 +184,11 @@ void basic::do_print(const print_context & c, unsigned level) const
 /** Tree output to stream. */
 void basic::do_print_tree(const print_tree & c, unsigned level) const
 {
-       c.s << std::string(level, ' ') << class_name()
-           << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
-           << ", nops=" << nops()
-           << std::endl;
+       c.s << std::string(level, ' ') << class_name() << " @" << this
+           << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec;
+       if (nops())
+               c.s << ", nops=" << nops();
+       c.s << std::endl;
        for (size_t i=0; i<nops(); ++i)
                op(i).print(c, level + c.delta_indent);
 }
@@ -869,7 +866,7 @@ const basic & basic::hold() const
  *  is not the case. */
 void basic::ensure_if_modifiable() const
 {
-       if (refcount > 1)
+       if (get_refcount() > 1)
                throw(std::runtime_error("cannot modify multiply referenced object"));
        clearflag(status_flags::hash_calculated | status_flags::evaluated);
 }