X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?a=blobdiff_plain;ds=sidebyside;f=ginac%2Fex.cpp;h=789911258b43cfd57f7098675ad05cebda23f91a;hb=7a473d58cbf2ec744ef230e0503a071f9ab7aeec;hp=6a7a0aa91bdf3b823bf48beda6cbd735948523a6;hpb=955cb185a85535ab328ffedbfccdc508ce80fa91;p=ginac.git diff --git a/ginac/ex.cpp b/ginac/ex.cpp index 6a7a0aa9..78991125 100644 --- a/ginac/ex.cpp +++ b/ginac/ex.cpp @@ -3,7 +3,7 @@ * 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 @@ -31,9 +31,9 @@ #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 @@ -62,7 +62,7 @@ ex::~ex() } } -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); @@ -70,7 +70,7 @@ ex::ex(ex const & other) : bp(other.bp) ++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); @@ -95,43 +95,45 @@ ex const & ex::operator=(ex const & other) // 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 ////////// @@ -248,7 +250,7 @@ bool ex::info(unsigned inf) const // polynomial^(int) * polynomial^(int) * ... is in normal form if (!is_ex_exactly_of_type(*this, mul)) return false; - for (int i=0; inops(); @@ -276,25 +278,25 @@ ex ex::expand(unsigned options) const 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); @@ -320,7 +322,7 @@ ex ex::numer(bool normalize) const if (!is_ex_exactly_of_type(n, mul)) return n; ex res = _ex1(); - for (int i=0; icollect(s); @@ -372,13 +374,13 @@ ex ex::evalf(int level) const 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); @@ -390,34 +392,34 @@ exvector ex::get_indices(void) const 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(); @@ -426,7 +428,7 @@ ex & ex::let_op(int const i) } #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); @@ -439,7 +441,7 @@ int ex::compare(ex const & other) const #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); @@ -469,17 +471,17 @@ unsigned ex::gethash(void) const 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); } @@ -492,20 +494,20 @@ void ex::makewriteable() 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); @@ -515,9 +517,9 @@ void ex::construct_from_basic(basic const & other) } } else { if (other.flags & status_flags::dynallocated) { - bp=&const_cast(other); + bp = &const_cast(other); } else { - bp=other.duplicate(); + bp = other.duplicate(); bp->setflag(status_flags::dynallocated); } GINAC_ASSERT(bp!=0); @@ -528,6 +530,143 @@ void ex::construct_from_basic(basic const & other) 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 ////////// @@ -547,6 +686,6 @@ void ex::construct_from_basic(basic const & other) // none -#ifndef NO_GINAC_NAMESPACE +#ifndef NO_NAMESPACE_GINAC } // namespace GiNaC -#endif // ndef NO_GINAC_NAMESPACE +#endif // ndef NO_NAMESPACE_GINAC