/** @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
{
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)
// 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);
return false; // all possible properties are false for basic objects
}
-int basic::nops() const
+unsigned basic::nops() const
{
return 0;
}
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;
}
}
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
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();
}
}
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"));
}
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();
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)) {
if (typeid_this!=typeid_other) return false;
- ASSERT(typeid(*this)==typeid(other));
+ GINAC_ASSERT(typeid(*this)==typeid(other));
return is_equal_same_type(other);
}
//////////
int max_recursion_level=1024;
+
+#ifndef NO_GINAC_NAMESPACE
+} // namespace GiNaC
+#endif // ndef NO_GINAC_NAMESPACE