]> www.ginac.de Git - ginac.git/blobdiff - ginac/basic.cpp
- Importing new files for packaging Debian GNU/Linux packages.
[ginac.git] / ginac / basic.cpp
index 8317f8129adb7134b2a5b625d96ba93862befa2c..a8f2baa02b2f532d83b073b091416a306a2ecb91 100644 (file)
@@ -1,8 +1,9 @@
 /** @file basic.cpp
  *
- *  Implementation of GiNaC's ABC.
- *
- *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
+ *  Implementation of GiNaC's ABC. */
+
+/*
+ *  GiNaC Copyright (C) 1999-2000 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
 #include <typeinfo>
 #include <stdexcept>
 
-#include "ginac.h"
+#include "basic.h"
+#include "ex.h"
+#include "numeric.h"
+#include "power.h"
+#include "symbol.h"
+#include "lst.h"
+#include "ncmul.h"
 #include "utils.h"
+#include "debugmsg.h"
+
+#ifndef NO_GINAC_NAMESPACE
+namespace GiNaC {
+#endif // ndef NO_GINAC_NAMESPACE
 
 //////////
 // default constructor, destructor, copy constructor assignment operator and helpers
@@ -43,7 +55,7 @@ basic::~basic()
 {
     debugmsg("basic destructor",LOGLEVEL_DESTRUCT);
     destroy(0);
-    ASSERT((!(flags & status_flags::dynallocated))||(refcount==0));
+    GINAC_ASSERT((!(flags & status_flags::dynallocated))||(refcount==0));
 }
 
 basic::basic(basic const & other) : flags(0), refcount(0), tinfo_key(TINFO_BASIC)
@@ -98,6 +110,59 @@ basic::basic(unsigned ti) : flags(0), refcount(0), tinfo_key(ti)
 
 // public
 
+/** Output to stream formatted to be useful as ginsh input. */
+void basic::print(ostream & os, unsigned upper_precedence) const
+{
+    debugmsg("basic print",LOGLEVEL_PRINT);
+    os << "[basic object]";
+}
+
+/** Output to stream in ugly raw format, so brave developers can have a look
+ * at the underlying structure. */
+void basic::printraw(ostream & os) const
+{
+    debugmsg("basic printraw",LOGLEVEL_PRINT);
+    os << "[basic object]";
+}
+
+/** Output to stream formatted in tree- (indented-) form, so developers can
+ *  have a look at the underlying structure. */
+void basic::printtree(ostream & os, unsigned indent) const
+{
+    debugmsg("basic printtree",LOGLEVEL_PRINT);
+    os << string(indent,' ') << "type=" << typeid(*this).name()
+       << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
+       << ", flags=" << flags
+       << ", nops=" << nops() << endl;
+    for (unsigned i=0; i<nops(); ++i) {
+        op(i).printtree(os,indent+delta_indent);
+    }
+}
+
+/** Output to stream formatted as C-source.
+ *
+ *  @param os a stream for output
+ *  @param type variable type (one of the csrc_types)
+ *  @param upper_precedence operator precedence of caller
+ *  @see ex::printcsrc */
+void basic::printcsrc(ostream & os, unsigned type, unsigned upper_precedence) const
+{
+    debugmsg("basic print csrc", LOGLEVEL_PRINT);
+}
+
+/** Little wrapper arount print to be called within a debugger. */
+void basic::dbgprint(void) const
+{
+    print(cerr);
+    cerr << endl;
+}
+
+/** Little wrapper arount printtree to be called within a debugger. */
+void basic::dbgprinttree(void) const
+{
+    printtree(cerr,0);
+}
+
 basic * basic::duplicate() const
 {
     debugmsg("basic duplicate",LOGLEVEL_DUPLICATE);
@@ -109,7 +174,7 @@ bool basic::info(unsigned inf) const
     return false; // all possible properties are false for basic objects
 }
 
-int basic::nops() const
+unsigned basic::nops() const
 {
     return 0;
 }
@@ -139,10 +204,10 @@ ex basic::operator[](int const i) const
 
 bool basic::has(ex const & other) const
 {
-    ASSERT(other.bp!=0);
+    GINAC_ASSERT(other.bp!=0);
     if (is_equal(*other.bp)) return true;
     if (nops()>0) {
-        for (int i=0; i<nops(); i++) {
+        for (unsigned i=0; i<nops(); i++) {
             if (op(i).has(other)) return true;
         }
     }
@@ -161,7 +226,7 @@ int basic::ldegree(symbol const & s) const
 
 ex basic::coeff(symbol const & s, int const n) const
 {
-    return n==0 ? *this : exZERO();
+    return n==0 ? *this : _ex0();
 }
 
 ex basic::collect(symbol const & s) const
@@ -225,7 +290,7 @@ unsigned basic::return_type_tinfo(void) const
 unsigned basic::calchash(void) const
 {
     unsigned v=golden_ratio_hash(tinfo());
-    for (int i=0; i<nops(); i++) {
+    for (unsigned i=0; i<nops(); i++) {
         v=rotate_left_31(v);
         v ^= (const_cast<basic *>(this))->let_op(i).gethash();
     }
@@ -267,7 +332,7 @@ ex basic::subs(ex const & e) const
     }
     lst ls;
     lst lr;
-    for (int i=0; i<e.nops(); i++) {
+    for (unsigned i=0; i<e.nops(); i++) {
         if (!e.op(i).info(info_flags::relation_equal)) {
             throw(std::invalid_argument("basic::subs(ex): argument must be a list or equations"));
         }
@@ -282,28 +347,9 @@ ex basic::subs(ex const & e) const
     return subs(ls,lr);
 }
 
-// compare functions to sort expressions canonically
-// all compare functions return: -1 for *this less than other, 0 equal, 1 greater
-
-/*
-int basic::compare(basic const & other) const
-{
-    const type_info & typeid_this = typeid(*this);
-    const type_info & typeid_other = typeid(other);
-
-    if (typeid_this==typeid_other) {
-        return compare_same_type(other);
-    }
-
-    // special rule: sort numeric() to end
-    if (typeid_this==typeid_numeric) return 1;
-    if (typeid_other==typeid_numeric) return -1;
-
-    // otherwise: sort according to type_info order (arbitrary, but well defined)
-    return typeid_this.before(typeid_other) ? -1 : 1;
-}
-*/
-
+/** Compare objects to establish canonical order.
+ *  All compare functions return: -1 for *this less than other, 0 equal,
+ *  1 greater. */
 int basic::compare(basic const & other) const
 {
     unsigned hash_this = gethash();
@@ -338,7 +384,7 @@ int basic::compare(basic const & other) const
         return 1;
     }
 
-    ASSERT(typeid(*this)==typeid(other));
+    GINAC_ASSERT(typeid(*this)==typeid(other));
 
     int cmpval=compare_same_type(other);
     if ((cmpval!=0)&&(hash_this<0x80000000U)) {
@@ -366,7 +412,7 @@ bool basic::is_equal(basic const & other) const
 
     if (typeid_this!=typeid_other) return false;
 
-    ASSERT(typeid(*this)==typeid(other));
+    GINAC_ASSERT(typeid(*this)==typeid(other));
 
     return is_equal_same_type(other);
 }
@@ -406,3 +452,7 @@ type_info const & typeid_basic=typeid(some_basic);
 //////////
 
 int max_recursion_level=1024;
+
+#ifndef NO_GINAC_NAMESPACE
+} // namespace GiNaC
+#endif // ndef NO_GINAC_NAMESPACE