* Implementation of GiNaC's light-weight expression handles. */
/*
- * GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
+ * 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 "debugmsg.h"
#include "utils.h"
-#ifndef NO_GINAC_NAMESPACE
+#ifndef NO_NAMESPACE_GINAC
namespace GiNaC {
-#endif // ndef NO_GINAC_NAMESPACE
+#endif // ndef NO_NAMESPACE_GINAC
//////////
// default constructor, destructor, copy constructor assignment operator and helpers
}
}
-ex::ex(ex const & other) : bp(other.bp)
+ex::ex(const ex & other) : bp(other.bp)
{
debugmsg("ex copy constructor",LOGLEVEL_CONSTRUCT);
GINAC_ASSERT(bp!=0);
++bp->refcount;
}
-ex const & ex::operator=(ex const & other)
+const ex & ex::operator=(const ex & other)
{
debugmsg("ex operator=",LOGLEVEL_ASSIGNMENT);
GINAC_ASSERT(bp!=0);
// public
#ifndef INLINE_EX_CONSTRUCTORS
-ex::ex(basic const & other)
+
+ex::ex(const basic & other)
{
debugmsg("ex constructor from basic",LOGLEVEL_CONSTRUCT);
construct_from_basic(other);
}
-#endif
-ex::ex(int const i)
+ex::ex(int i)
{
debugmsg("ex constructor from int",LOGLEVEL_CONSTRUCT);
- construct_from_basic(numeric(i));
+ construct_from_int(i);
}
-ex::ex(unsigned int const i)
+ex::ex(unsigned int i)
{
debugmsg("ex constructor from unsigned int",LOGLEVEL_CONSTRUCT);
- construct_from_basic(numeric(i));
+ construct_from_uint(i);
}
-ex::ex(long const i)
+ex::ex(long i)
{
debugmsg("ex constructor from long",LOGLEVEL_CONSTRUCT);
- construct_from_basic(numeric(i));
+ construct_from_long(i);
}
-ex::ex(unsigned long const i)
+ex::ex(unsigned long i)
{
debugmsg("ex constructor from unsigned long",LOGLEVEL_CONSTRUCT);
- construct_from_basic(numeric(i));
+ construct_from_ulong(i);
}
ex::ex(double const d)
{
debugmsg("ex constructor from double",LOGLEVEL_CONSTRUCT);
- construct_from_basic(numeric(d));
+ construct_from_double(d);
}
-
+
+#endif // ndef INLINE_EX_CONSTRUCTORS
+
//////////
// functions overriding virtual functions from bases classes
//////////
// polynomial^(int) * polynomial^(int) * ... is in normal form
if (!is_ex_exactly_of_type(*this, mul))
return false;
- for (int i=0; i<nops(); i++) {
+ for (unsigned i=0; i<nops(); i++) {
if (is_ex_exactly_of_type(op(i), power)) {
if (!op(i).op(1).info(info_flags::integer))
return false;
}
}
-int ex::nops() const
+unsigned ex::nops() const
{
GINAC_ASSERT(bp!=0);
return bp->nops();
return bp->expand(options);
}
-bool ex::has(ex const & other) const
+bool ex::has(const ex & other) const
{
GINAC_ASSERT(bp!=0);
return bp->has(other);
}
-int ex::degree(symbol const & s) const
+int ex::degree(const symbol & s) const
{
GINAC_ASSERT(bp!=0);
return bp->degree(s);
}
-int ex::ldegree(symbol const & s) const
+int ex::ldegree(const symbol & s) const
{
GINAC_ASSERT(bp!=0);
return bp->ldegree(s);
}
-ex ex::coeff(symbol const & s, int const n) const
+ex ex::coeff(const symbol & s, int n) const
{
GINAC_ASSERT(bp!=0);
return bp->coeff(s,n);
if (!is_ex_exactly_of_type(n, mul))
return n;
ex res = _ex1();
- for (int i=0; i<n.nops(); i++) {
+ for (unsigned i=0; i<n.nops(); i++) {
if (!is_ex_exactly_of_type(n.op(i), power) || !n.op(i).op(1).info(info_flags::negint))
res *= n.op(i);
}
if (!is_ex_exactly_of_type(n, mul))
return _ex1();
ex res = _ex1();
- for (int i=0; i<n.nops(); i++) {
+ for (unsigned i=0; i<n.nops(); i++) {
if (is_ex_exactly_of_type(n.op(i), power) && n.op(i).op(1).info(info_flags::negint))
res *= power(n.op(i), -1);
}
return res;
}
-ex ex::collect(symbol const & s) const
+ex ex::collect(const symbol & s) const
{
GINAC_ASSERT(bp!=0);
return bp->collect(s);
return bp->evalf(level);
}
-ex ex::subs(lst const & ls, lst const & lr) const
+ex ex::subs(const lst & ls, const lst & lr) const
{
GINAC_ASSERT(bp!=0);
return bp->subs(ls,lr);
}
-ex ex::subs(ex const & e) const
+ex ex::subs(const ex & e) const
{
GINAC_ASSERT(bp!=0);
return bp->subs(e);
return bp->get_indices();
}
-ex ex::simplify_ncmul(exvector const & v) const
+ex ex::simplify_ncmul(const exvector & v) const
{
GINAC_ASSERT(bp!=0);
return bp->simplify_ncmul(v);
}
-ex ex::operator[](ex const & index) const
+ex ex::operator[](const ex & index) const
{
debugmsg("ex operator[ex]",LOGLEVEL_OPERATOR);
GINAC_ASSERT(bp!=0);
return (*bp)[index];
}
-ex ex::operator[](int const i) const
+ex ex::operator[](int i) const
{
debugmsg("ex operator[int]",LOGLEVEL_OPERATOR);
GINAC_ASSERT(bp!=0);
return (*bp)[i];
}
-ex ex::op(int const i) const
+ex ex::op(int i) const
{
debugmsg("ex op()",LOGLEVEL_MEMBER_FUNCTION);
GINAC_ASSERT(bp!=0);
return bp->op(i);
}
-ex & ex::let_op(int const i)
+ex & ex::let_op(int i)
{
debugmsg("ex let_op()",LOGLEVEL_MEMBER_FUNCTION);
makewriteable();
}
#ifndef INLINE_EX_CONSTRUCTORS
-int ex::compare(ex const & other) const
+int ex::compare(const ex & other) const
{
GINAC_ASSERT(bp!=0);
GINAC_ASSERT(other.bp!=0);
#endif // ndef INLINE_EX_CONSTRUCTORS
#ifndef INLINE_EX_CONSTRUCTORS
-bool ex::is_equal(ex const & other) const
+bool ex::is_equal(const ex & other) const
{
GINAC_ASSERT(bp!=0);
GINAC_ASSERT(other.bp!=0);
return bp->gethash();
}
-ex ex::exadd(ex const & rh) const
+ex ex::exadd(const ex & rh) const
{
return (new add(*this,rh))->setflag(status_flags::dynallocated);
}
-ex ex::exmul(ex const & rh) const
+ex ex::exmul(const ex & rh) const
{
return (new mul(*this,rh))->setflag(status_flags::dynallocated);
}
-ex ex::exncmul(ex const & rh) const
+ex ex::exncmul(const ex & rh) const
{
return (new ncmul(*this,rh))->setflag(status_flags::dynallocated);
}
GINAC_ASSERT(bp!=0);
GINAC_ASSERT(bp->flags & status_flags::dynallocated);
if (bp->refcount > 1) {
- basic * bp2=bp->duplicate();
+ basic * bp2 = bp->duplicate();
++bp2->refcount;
bp2->setflag(status_flags::dynallocated);
--bp->refcount;
- bp=bp2;
+ bp = bp2;
}
GINAC_ASSERT(bp->refcount == 1);
-}
+}
-void ex::construct_from_basic(basic const & other)
+void ex::construct_from_basic(const basic & other)
{
if ((other.flags & status_flags::evaluated)==0) {
// cf. copy constructor
- ex const & tmpex = other.eval(1); // evaluate only one (top) level
+ const ex & tmpex = other.eval(1); // evaluate only one (top) level
bp = tmpex.bp;
GINAC_ASSERT(bp!=0);
GINAC_ASSERT(bp->flags & status_flags::dynallocated);
}
} else {
if (other.flags & status_flags::dynallocated) {
- bp=&const_cast<basic &>(other);
+ bp = &const_cast<basic &>(other);
} else {
- bp=other.duplicate();
+ bp = other.duplicate();
bp->setflag(status_flags::dynallocated);
}
GINAC_ASSERT(bp!=0);
GINAC_ASSERT(bp->flags & status_flags::dynallocated);
}
+void ex::construct_from_int(int i)
+{
+ switch (i) { // some tiny efficiency-hack
+ case -2:
+ bp = _ex_2().bp;
+ ++bp->refcount;
+ break;
+ case -1:
+ bp = _ex_1().bp;
+ ++bp->refcount;
+ break;
+ case 0:
+ bp = _ex0().bp;
+ ++bp->refcount;
+ break;
+ case 1:
+ bp = _ex1().bp;
+ ++bp->refcount;
+ break;
+ case 2:
+ bp = _ex2().bp;
+ ++bp->refcount;
+ break;
+ default:
+ bp = new numeric(i);
+ bp->setflag(status_flags::dynallocated);
+ ++bp->refcount;
+ GINAC_ASSERT((bp->flags) & status_flags::dynallocated);
+ GINAC_ASSERT(bp->refcount=1);
+ }
+}
+
+void ex::construct_from_uint(unsigned int i)
+{
+ switch (i) { // some tiny efficiency-hack
+ case -2:
+ bp = _ex_2().bp;
+ ++bp->refcount;
+ break;
+ case -1:
+ bp = _ex_1().bp;
+ ++bp->refcount;
+ break;
+ case 0:
+ bp = _ex0().bp;
+ ++bp->refcount;
+ break;
+ case 1:
+ bp = _ex1().bp;
+ ++bp->refcount;
+ break;
+ case 2:
+ bp = _ex2().bp;
+ ++bp->refcount;
+ break;
+ default:
+ bp = new numeric(i);
+ bp->setflag(status_flags::dynallocated);
+ ++bp->refcount;
+ GINAC_ASSERT((bp->flags) & status_flags::dynallocated);
+ GINAC_ASSERT(bp->refcount=1);
+ }
+}
+
+void ex::construct_from_long(long i)
+{
+ switch (i) { // some tiny efficiency-hack
+ case -2:
+ bp = _ex_2().bp;
+ ++bp->refcount;
+ break;
+ case -1:
+ bp = _ex_1().bp;
+ ++bp->refcount;
+ break;
+ case 0:
+ bp = _ex0().bp;
+ ++bp->refcount;
+ break;
+ case 1:
+ bp = _ex1().bp;
+ ++bp->refcount;
+ break;
+ case 2:
+ bp = _ex2().bp;
+ ++bp->refcount;
+ break;
+ default:
+ bp = new numeric(i);
+ bp->setflag(status_flags::dynallocated);
+ ++bp->refcount;
+ GINAC_ASSERT((bp->flags) & status_flags::dynallocated);
+ GINAC_ASSERT(bp->refcount=1);
+ }
+}
+
+void ex::construct_from_ulong(unsigned long i)
+{
+ switch (i) { // some tiny efficiency-hack
+ case -2:
+ bp = _ex_2().bp;
+ ++bp->refcount;
+ break;
+ case -1:
+ bp = _ex_1().bp;
+ ++bp->refcount;
+ break;
+ case 0:
+ bp = _ex0().bp;
+ ++bp->refcount;
+ break;
+ case 1:
+ bp = _ex1().bp;
+ ++bp->refcount;
+ break;
+ case 2:
+ bp = _ex2().bp;
+ ++bp->refcount;
+ break;
+ default:
+ bp = new numeric(i);
+ bp->setflag(status_flags::dynallocated);
+ ++bp->refcount;
+ GINAC_ASSERT((bp->flags) & status_flags::dynallocated);
+ GINAC_ASSERT(bp->refcount=1);
+ }
+}
+
+void ex::construct_from_double(double d)
+{
+ bp = new numeric(d);
+ bp->setflag(status_flags::dynallocated);
+ ++bp->refcount;
+ GINAC_ASSERT((bp->flags) & status_flags::dynallocated);
+ GINAC_ASSERT(bp->refcount=1);
+}
+
//////////
// static member variables
//////////
// none
-#ifndef NO_GINAC_NAMESPACE
+#ifndef NO_NAMESPACE_GINAC
} // namespace GiNaC
-#endif // ndef NO_GINAC_NAMESPACE
+#endif // ndef NO_NAMESPACE_GINAC