]> www.ginac.de Git - ginac.git/blobdiff - ginac/basic.cpp
- Banned exZERO(), exONE(), exMINUSHALF() and all this from the interface.
[ginac.git] / ginac / basic.cpp
index eb4a72e034192e9e53cb478cfe0650b91a9f00be..7b6a6fbeb5b2ffda4ebeb267d32d8ddf6bcef82b 100644 (file)
@@ -34,7 +34,9 @@
 #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
@@ -108,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 (int 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);
@@ -171,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
@@ -292,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();
@@ -417,4 +453,6 @@ type_info const & typeid_basic=typeid(some_basic);
 
 int max_recursion_level=1024;
 
+#ifndef NO_GINAC_NAMESPACE
 } // namespace GiNaC
+#endif // ndef NO_GINAC_NAMESPACE