From: Richard Kreckel Date: Wed, 22 Aug 2001 20:11:48 +0000 (+0000) Subject: - Cleanups: My evil plot of making ex::bp private may finally be carried X-Git-Tag: release_0-9-4~11 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=d448856f20cb58f939ddbf636e7f72e3599b1468 - Cleanups: My evil plot of making ex::bp private may finally be carried out, provided one changes all the is_of_type(obj,type) to is_a(obj) which we don't do right now because it would degrade performance on gcc-2.95.x. Also, ex_to_type(obj) has gone for good now, we have been having ex_to(obj) long enough. ex_to_nonconst_type(obj) have gone as well, since they are almost never used and one can always cast aways the constness explicitly if need should arise. --- diff --git a/NEWS b/NEWS index 6bbe8f54..6c882d72 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,8 @@ This file records noteworthy changes. +0.9.4 () +* interface cleanups and bugfixes. + 0.9.3 (16 August 2001) * series expansion now much more consistent for small order expansion. * lsolve() accepts algorithmic hint as parameter. diff --git a/ginac/add.cpp b/ginac/add.cpp index c14c1587..4cb11825 100644 --- a/ginac/add.cpp +++ b/ginac/add.cpp @@ -328,10 +328,10 @@ ex add::eval(int level) const #ifdef DO_GINAC_ASSERT epvector::const_iterator i = seq.begin(), end = seq.end(); while (i != end) { - GINAC_ASSERT(!is_ex_exactly_of_type(i->rest,add)); + GINAC_ASSERT(!is_exactly_a(i->rest)); if (is_ex_exactly_of_type(i->rest,numeric)) dbgprint(); - GINAC_ASSERT(!is_ex_exactly_of_type(i->rest,numeric)); + GINAC_ASSERT(!is_exactly_a(i->rest)); ++i; } #endif // def DO_GINAC_ASSERT @@ -470,7 +470,7 @@ expair add::split_ex_to_pair(const ex & e) const expair add::combine_ex_with_coeff_to_pair(const ex & e, const ex & c) const { - GINAC_ASSERT(is_ex_exactly_of_type(c, numeric)); + GINAC_ASSERT(is_exactly_a(c)); if (is_ex_exactly_of_type(e, mul)) { const mul &mulref(ex_to(e)); ex numfactor = mulref.overall_coeff; @@ -496,8 +496,8 @@ expair add::combine_ex_with_coeff_to_pair(const ex & e, expair add::combine_pair_with_coeff_to_pair(const expair & p, const ex & c) const { - GINAC_ASSERT(is_ex_exactly_of_type(p.coeff,numeric)); - GINAC_ASSERT(is_ex_exactly_of_type(c,numeric)); + GINAC_ASSERT(is_exactly_a(p.coeff)); + GINAC_ASSERT(is_exactly_a(c)); if (is_ex_exactly_of_type(p.rest,numeric)) { GINAC_ASSERT(ex_to(p.coeff).is_equal(_num1())); // should be normalized diff --git a/ginac/add.h b/ginac/add.h index fe8d20b7..74000568 100644 --- a/ginac/add.h +++ b/ginac/add.h @@ -79,13 +79,6 @@ protected: // utility functions -/** Return the add object handled by an ex. Deprecated: use ex_to(). - * This is unsafe: you need to check the type first. */ -inline const add &ex_to_add(const ex &e) -{ - return static_cast(*e.bp); -} - /** Specialization of is_exactly_a(obj) for add objects. */ template<> inline bool is_exactly_a(const basic & obj) { diff --git a/ginac/basic.cpp b/ginac/basic.cpp index 1aff2e16..2065eac8 100644 --- a/ginac/basic.cpp +++ b/ginac/basic.cpp @@ -34,6 +34,7 @@ #include "lst.h" #include "ncmul.h" #include "relational.h" +#include "wildcard.h" #include "print.h" #include "archive.h" #include "utils.h" @@ -213,9 +214,8 @@ ex basic::operator[](int i) const * but e.has(x+y) is false. */ bool basic::has(const ex & pattern) const { - GINAC_ASSERT(pattern.bp!=0); lst repl_lst; - if (match(*pattern.bp, repl_lst)) + if (match(pattern, repl_lst)) return true; for (unsigned i=0; i(repl_lst.op(i).op(1))); } repl_lst.append(pattern == *this); return true; @@ -479,7 +479,7 @@ bool basic::match(const ex & pattern, lst & repl_lst) const } else { // Expression must be of the same type as the pattern - if (tinfo() != pattern.bp->tinfo()) + if (tinfo() != ex_to(pattern).tinfo()) return false; // Number of subexpressions must match @@ -489,10 +489,10 @@ bool basic::match(const ex & pattern, lst & repl_lst) const // No subexpressions? Then just compare the objects (there can't be // wildcards in the pattern) if (nops() == 0) - return is_equal_same_type(*pattern.bp); + return is_equal_same_type(ex_to(pattern)); // Check whether attributes that are not subexpressions match - if (!match_same_type(*pattern.bp)) + if (!match_same_type(ex_to(pattern))) return false; // Otherwise the subexpressions must match one-to-one @@ -513,14 +513,14 @@ ex basic::subs(const lst & ls, const lst & lr, bool no_pattern) const if (no_pattern) { for (unsigned i=0; i(ls.op(i)))) return lr.op(i); } } else { for (unsigned i=0; isubs(repl_lst, true); // avoid infinite recursion when re-substituting the wildcards + if (match(ex_to(ls.op(i)), repl_lst)) + return lr.op(i).subs(repl_lst, true); // avoid infinite recursion when re-substituting the wildcards } } @@ -675,7 +675,7 @@ ex basic::expand(unsigned options) const return (options == 0) ? setflag(status_flags::expanded) : *this; else { expand_map_function map_expand(options); - return map(map_expand).bp->setflag(options == 0 ? status_flags::expanded : 0); + return ex_to(map(map_expand)).setflag(options == 0 ? status_flags::expanded : 0); } } diff --git a/ginac/basic.h b/ginac/basic.h index b319e0d5..1268d002 100644 --- a/ginac/basic.h +++ b/ginac/basic.h @@ -179,7 +179,7 @@ extern int max_recursion_level; /** Check if obj is a T, including base classes. */ template -inline bool is_a(const basic & obj) +inline bool is_a(const basic &obj) { return dynamic_cast(&obj)!=0; } @@ -188,28 +188,29 @@ inline bool is_a(const basic & obj) * inefficient default. It should in all time-critical cases be overridden * by template specializations that don't create a temporary. */ template -inline bool is_exactly_a(const class basic & obj) +inline bool is_exactly_a(const class basic &obj) { const T foo; return foo.tinfo()==obj.tinfo(); } /** Check if ex is a handle to a T, including base classes. */ template -inline bool is_a(const ex & obj) +inline bool is_a(const ex &obj) { return is_a(*obj.bp); } /** Check if ex is a handle to a T, not including base classes. */ template -inline bool is_exactly_a(const ex & obj) +inline bool is_exactly_a(const ex &obj) { return is_exactly_a(*obj.bp); } /** Return a reference to the basic-derived class T object embedded in an * expression. This is fast but unsafe: the result is undefined if the - * expression does not contain a T object at its top level. + * expression does not contain a T object at its top level. Hence, you + * should generally check the type of e first. * * @param e expression * @return reference to pseries object diff --git a/ginac/clifford.cpp b/ginac/clifford.cpp index bee4618d..d488d3ba 100644 --- a/ginac/clifford.cpp +++ b/ginac/clifford.cpp @@ -129,7 +129,7 @@ DEFAULT_ARCHIVING(diracgamma5) int clifford::compare_same_type(const basic & other) const { - GINAC_ASSERT(is_of_type(other, clifford)); + GINAC_ASSERT(is_a(other)); const clifford &o = static_cast(other); if (representation_label != o.representation_label) { @@ -142,7 +142,7 @@ int clifford::compare_same_type(const basic & other) const bool clifford::match_same_type(const basic & other) const { - GINAC_ASSERT(is_of_type(other, clifford)); + GINAC_ASSERT(is_a(other)); const clifford &o = static_cast(other); return representation_label == o.representation_label; diff --git a/ginac/clifford.h b/ginac/clifford.h index 50a0c70c..b6c88d9e 100644 --- a/ginac/clifford.h +++ b/ginac/clifford.h @@ -106,13 +106,6 @@ public: // global functions -/** Return the clifford object handled by an ex. Deprecated: use ex_to(). - * This is unsafe: you need to check the type first. */ -inline const clifford &ex_to_clifford(const ex &e) -{ - return static_cast(*e.bp); -} - /** Specialization of is_exactly_a(obj) for clifford objects. */ template<> inline bool is_exactly_a(const basic & obj) { diff --git a/ginac/color.cpp b/ginac/color.cpp index 561f88b1..3c316d41 100644 --- a/ginac/color.cpp +++ b/ginac/color.cpp @@ -28,6 +28,7 @@ #include "ncmul.h" #include "symmetry.h" #include "numeric.h" +#include "mul.h" #include "power.h" // for sqrt() #include "symbol.h" #include "print.h" @@ -129,7 +130,7 @@ DEFAULT_ARCHIVING(su3d) int color::compare_same_type(const basic & other) const { - GINAC_ASSERT(is_of_type(other, color)); + GINAC_ASSERT(is_a(other)); const color &o = static_cast(other); if (representation_label != o.representation_label) { @@ -142,7 +143,7 @@ int color::compare_same_type(const basic & other) const bool color::match_same_type(const basic & other) const { - GINAC_ASSERT(is_of_type(other, color)); + GINAC_ASSERT(is_a(other)); const color &o = static_cast(other); return representation_label == o.representation_label; @@ -223,9 +224,9 @@ static ex permute_free_index_to_front(const exvector & iv3, const exvector & iv2 /** Automatic symbolic evaluation of indexed symmetric structure constant. */ ex su3d::eval_indexed(const basic & i) const { - GINAC_ASSERT(is_of_type(i, indexed)); + GINAC_ASSERT(is_a(i)); GINAC_ASSERT(i.nops() == 4); - GINAC_ASSERT(is_ex_of_type(i.op(0), su3d)); + GINAC_ASSERT(is_a(i.op(0))); // Convolutions are zero if (!(static_cast(i).get_dummy_indices().empty())) @@ -268,9 +269,9 @@ ex su3d::eval_indexed(const basic & i) const /** Automatic symbolic evaluation of indexed antisymmetric structure constant. */ ex su3f::eval_indexed(const basic & i) const { - GINAC_ASSERT(is_of_type(i, indexed)); + GINAC_ASSERT(is_a(i)); GINAC_ASSERT(i.nops() == 4); - GINAC_ASSERT(is_ex_of_type(i.op(0), su3f)); + GINAC_ASSERT(is_a(i.op(0))); // Numeric evaluation if (static_cast(i).all_index_values_are(info_flags::nonnegint)) { @@ -306,10 +307,10 @@ ex su3f::eval_indexed(const basic & i) const /** Contraction of generator with something else. */ bool su3t::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const { - GINAC_ASSERT(is_ex_of_type(*self, indexed)); - GINAC_ASSERT(is_ex_of_type(*other, indexed)); + GINAC_ASSERT(is_a(*self)); + GINAC_ASSERT(is_a(*other)); GINAC_ASSERT(self->nops() == 2); - GINAC_ASSERT(is_ex_of_type(self->op(0), su3t)); + GINAC_ASSERT(is_a(self->op(0))); unsigned char rl = ex_to(*self).get_representation_label(); if (is_ex_exactly_of_type(other->op(0), su3t)) { @@ -356,10 +357,10 @@ bool su3t::contract_with(exvector::iterator self, exvector::iterator other, exve /** Contraction of an indexed symmetric structure constant with something else. */ bool su3d::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const { - GINAC_ASSERT(is_ex_of_type(*self, indexed)); - GINAC_ASSERT(is_ex_of_type(*other, indexed)); + GINAC_ASSERT(is_a(*self)); + GINAC_ASSERT(is_a(*other)); GINAC_ASSERT(self->nops() == 4); - GINAC_ASSERT(is_ex_of_type(self->op(0), su3d)); + GINAC_ASSERT(is_a(self->op(0))); if (is_ex_exactly_of_type(other->op(0), su3d)) { @@ -415,10 +416,10 @@ bool su3d::contract_with(exvector::iterator self, exvector::iterator other, exve /** Contraction of an indexed antisymmetric structure constant with something else. */ bool su3f::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const { - GINAC_ASSERT(is_ex_of_type(*self, indexed)); - GINAC_ASSERT(is_ex_of_type(*other, indexed)); + GINAC_ASSERT(is_a(*self)); + GINAC_ASSERT(is_a(*other)); GINAC_ASSERT(self->nops() == 4); - GINAC_ASSERT(is_ex_of_type(self->op(0), su3f)); + GINAC_ASSERT(is_a(self->op(0))); if (is_ex_exactly_of_type(other->op(0), su3f)) { // f*d is handled by su3d class diff --git a/ginac/color.h b/ginac/color.h index 03b9d8d3..cc7ac31e 100644 --- a/ginac/color.h +++ b/ginac/color.h @@ -117,13 +117,6 @@ public: // global functions -/** Return the color object handled by an ex. Deprecated: use ex_to(). - * This is unsafe: you need to check the type first. */ -inline const color &ex_to_color(const ex &e) -{ - return static_cast(*e.bp); -} - /** Specialization of is_exactly_a(obj) for color objects. */ template<> inline bool is_exactly_a(const basic & obj) { diff --git a/ginac/constant.cpp b/ginac/constant.cpp index 844a08a2..d2a74b2d 100644 --- a/ginac/constant.cpp +++ b/ginac/constant.cpp @@ -190,7 +190,7 @@ ex constant::derivative(const symbol & s) const int constant::compare_same_type(const basic & other) const { - GINAC_ASSERT(is_exactly_of_type(other, constant)); + GINAC_ASSERT(is_exactly_a(other)); const constant &o = static_cast(other); if (serial == o.serial) @@ -201,7 +201,7 @@ int constant::compare_same_type(const basic & other) const bool constant::is_equal_same_type(const basic & other) const { - GINAC_ASSERT(is_exactly_of_type(other, constant)); + GINAC_ASSERT(is_exactly_a(other)); const constant &o = static_cast(other); return serial == o.serial; diff --git a/ginac/constant.h b/ginac/constant.h index bdd8d69e..c43465ae 100644 --- a/ginac/constant.h +++ b/ginac/constant.h @@ -81,13 +81,6 @@ extern const constant Euler; // utility functions -/** Return the constant object handled by an ex. Deprecated: use ex_to(). - * This is unsafe: you need to check the type first. */ -inline const constant &ex_to_constant(const ex &e) -{ - return static_cast(*e.bp); -} - /** Specialization of is_exactly_a(obj) for constant objects. */ template<> inline bool is_exactly_a(const basic & obj) { diff --git a/ginac/container.pl b/ginac/container.pl index 8374b9b9..8004383a 100755 --- a/ginac/container.pl +++ b/ginac/container.pl @@ -271,24 +271,12 @@ protected: // utility functions -/** Return the ${CONTAINER} object handled by an ex. Deprecated: use ex_to<${CONTAINER}>(). - * This is unsafe: you need to check the type first. */ -inline const ${CONTAINER} &ex_to_${CONTAINER}(const ex &e) -{ - return static_cast(*e.bp); -} - /** Specialization of is_exactly_a<${CONTAINER}>(obj) for ${CONTAINER} objects. */ template<> inline bool is_exactly_a<${CONTAINER}>(const basic & obj) { return obj.tinfo()==TINFO_${CONTAINER}; } -inline ${CONTAINER} &ex_to_nonconst_${CONTAINER}(const ex &e) -{ - return static_cast<${CONTAINER} &>(*e.bp); -} - } // namespace GiNaC #endif // ndef __GINAC_${CONTAINER_UC}_H__ @@ -495,7 +483,7 @@ ex ${CONTAINER}::subs(const lst & ls, const lst & lr, bool no_pattern) const { ${STLT} *vp = subschildren(ls, lr, no_pattern); if (vp) - return this${CONTAINER}(vp).bp->basic::subs(ls, lr, no_pattern); + return ex_to(this${CONTAINER}(vp)).basic::subs(ls, lr, no_pattern); else return basic::subs(ls, lr, no_pattern); } diff --git a/ginac/ex.cpp b/ginac/ex.cpp index b6b96859..0d0657a5 100644 --- a/ginac/ex.cpp +++ b/ginac/ex.cpp @@ -215,7 +215,7 @@ void ex::makewriteable() void ex::construct_from_basic(const basic & other) { if (!(other.flags & status_flags::evaluated)) { - const ex & 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->flags & status_flags::dynallocated); ++bp->refcount; diff --git a/ginac/ex.h b/ginac/ex.h index aefb6af7..e9f72bbe 100644 --- a/ginac/ex.h +++ b/ginac/ex.h @@ -46,7 +46,11 @@ class scalar_products; * a thing a proxy class.) */ class ex { - friend class basic; + friend class archive_node; + friend bool are_ex_trivially_equal(const ex &, const ex &); + template friend const T &ex_to(const ex &); + template friend bool is_a(const ex &); + template friend bool is_exactly_a(const ex &); // member functions @@ -172,7 +176,7 @@ protected: // member variables public: - basic *bp; ///< pointer to basic object managed by this + basic *bp; ///< pointer to basic object managed by this, direct manipulation deprecated #ifdef OBSCURE_CINT_HACK static basic * last_created_or_assigned_bp; static basic * dummy_bp; diff --git a/ginac/expairseq.cpp b/ginac/expairseq.cpp index 5f3dd290..c2dfc6a5 100644 --- a/ginac/expairseq.cpp +++ b/ginac/expairseq.cpp @@ -26,7 +26,10 @@ #include "expairseq.h" #include "lst.h" +#include "mul.h" +#include "power.h" #include "relational.h" +#include "wildcard.h" #include "print.h" #include "archive.h" #include "debugmsg.h" @@ -38,6 +41,7 @@ namespace GiNaC { + GINAC_IMPLEMENT_REGISTERED_CLASS_NO_CTORS(expairseq, basic) ////////// @@ -188,7 +192,7 @@ basic *expairseq::duplicate() const return new expairseq(*this); } -void expairseq::print(const print_context & c, unsigned level) const +void expairseq::print(const print_context &c, unsigned level) const { debugmsg("expairseq print",LOGLEVEL_PRINT); @@ -300,7 +304,7 @@ ex &expairseq::let_op(int i) throw(std::logic_error("let_op not defined for expairseq and derived classes (add,mul,...)")); } -ex expairseq::map(map_function & f) const +ex expairseq::map(map_function &f) const { epvector *v = new epvector; v->reserve(seq.size()); @@ -335,7 +339,7 @@ bool expairseq::match(const ex & pattern, lst & repl_lst) const // This differs from basic::match() because we want "a+b+c+d" to // match "d+*+b" with "*" being "a+c", and we want to honor commutativity - if (tinfo() == pattern.bp->tinfo()) { + if (this->tinfo() == ex_to(pattern).tinfo()) { // Check whether global wildcard (one that matches the "rest of the // expression", like "*" above) is present @@ -389,7 +393,7 @@ found: ; ex rest = thisexpairseq(vp, default_overall_coeff()); for (unsigned i=0; ibasic::subs(ls, lr, no_pattern); + return ex_to(thisexpairseq(vp, overall_coeff)).basic::subs(ls, lr, no_pattern); else return basic::subs(ls, lr, no_pattern); } @@ -417,7 +421,7 @@ ex expairseq::subs(const lst &ls, const lst &lr, bool no_pattern) const int expairseq::compare_same_type(const basic &other) const { - GINAC_ASSERT(is_of_type(other, expairseq)); + GINAC_ASSERT(is_a(other)); const expairseq &o = static_cast(other); int cmpval; @@ -552,7 +556,7 @@ unsigned expairseq::return_type(void) const unsigned expairseq::calchash(void) const { - unsigned v = golden_ratio_hash(tinfo()); + unsigned v = golden_ratio_hash(this->tinfo()); epvector::const_iterator i = seq.begin(), end = seq.end(); while (i != end) { #if !EXPAIRSEQ_USE_HASHTAB @@ -615,9 +619,9 @@ ex expairseq::thisexpairseq(epvector *vp, const ex &oc) const void expairseq::printpair(const print_context & c, const expair & p, unsigned upper_precedence) const { c.s << "[["; - p.rest.bp->print(c, precedence()); + p.rest.print(c, precedence()); c.s << ","; - p.coeff.bp->print(c, precedence()); + p.coeff.print(c, precedence()); c.s << "]]"; } @@ -654,7 +658,7 @@ expair expairseq::split_ex_to_pair(const ex &e) const expair expairseq::combine_ex_with_coeff_to_pair(const ex &e, const ex &c) const { - GINAC_ASSERT(is_ex_exactly_of_type(c,numeric)); + GINAC_ASSERT(is_exactly_a(c)); return expair(e,c); } @@ -663,8 +667,8 @@ expair expairseq::combine_ex_with_coeff_to_pair(const ex &e, expair expairseq::combine_pair_with_coeff_to_pair(const expair &p, const ex &c) const { - GINAC_ASSERT(is_ex_exactly_of_type(p.coeff,numeric)); - GINAC_ASSERT(is_ex_exactly_of_type(c,numeric)); + GINAC_ASSERT(is_exactly_a(p.coeff)); + GINAC_ASSERT(is_exactly_a(c)); return expair(p.rest,ex_to(p.coeff).mul_dyn(ex_to(c))); } @@ -692,16 +696,16 @@ ex expairseq::default_overall_coeff(void) const void expairseq::combine_overall_coeff(const ex &c) { - GINAC_ASSERT(is_ex_exactly_of_type(overall_coeff,numeric)); - GINAC_ASSERT(is_ex_exactly_of_type(c,numeric)); + GINAC_ASSERT(is_exactly_a(overall_coeff)); + GINAC_ASSERT(is_exactly_a(c)); overall_coeff = ex_to(overall_coeff).add_dyn(ex_to(c)); } void expairseq::combine_overall_coeff(const ex &c1, const ex &c2) { - GINAC_ASSERT(is_ex_exactly_of_type(overall_coeff,numeric)); - GINAC_ASSERT(is_ex_exactly_of_type(c1,numeric)); - GINAC_ASSERT(is_ex_exactly_of_type(c2,numeric)); + GINAC_ASSERT(is_exactly_a(overall_coeff)); + GINAC_ASSERT(is_exactly_a(c1)); + GINAC_ASSERT(is_exactly_a(c2)); overall_coeff = ex_to(overall_coeff). add_dyn(ex_to(c1).mul(ex_to(c2))); } @@ -731,8 +735,8 @@ void expairseq::construct_from_2_ex_via_exvector(const ex &lh, const ex &rh) void expairseq::construct_from_2_ex(const ex &lh, const ex &rh) { - if (lh.bp->tinfo()==tinfo()) { - if (rh.bp->tinfo()==tinfo()) { + if (ex_to(lh).tinfo()==this->tinfo()) { + if (ex_to(rh).tinfo()==this->tinfo()) { #if EXPAIRSEQ_USE_HASHTAB unsigned totalsize = ex_to(lh).seq.size() + ex_to(rh).seq.size(); @@ -759,7 +763,7 @@ void expairseq::construct_from_2_ex(const ex &lh, const ex &rh) #endif // EXPAIRSEQ_USE_HASHTAB return; } - } else if (rh.bp->tinfo()==tinfo()) { + } else if (ex_to(rh).tinfo()==this->tinfo()) { #if EXPAIRSEQ_USE_HASHTAB unsigned totalsize=ex_to(rh).seq.size()+1; if (calc_hashtabsize(totalsize)!=0) { @@ -799,7 +803,7 @@ void expairseq::construct_from_2_ex(const ex &lh, const ex &rh) int cmpval = p1.rest.compare(p2.rest); if (cmpval==0) { - p1.coeff=ex_to(p1.coeff).add_dyn(ex_to(p2.coeff)); + p1.coeff = ex_to(p1.coeff).add_dyn(ex_to(p2.coeff)); if (!ex_to(p1.coeff).is_zero()) { // no further processing is necessary, since this // one element will usually be recombined in eval() @@ -838,10 +842,10 @@ void expairseq::construct_from_2_expairseq(const expairseq &s1, int cmpval = (*first1).rest.compare((*first2).rest); if (cmpval==0) { // combine terms - const numeric &newcoeff = ex_to((*first1).coeff). - add(ex_to((*first2).coeff)); + const numeric &newcoeff = ex_to(first1->coeff). + add(ex_to(first2->coeff)); if (!newcoeff.is_zero()) { - seq.push_back(expair((*first1).rest,newcoeff)); + seq.push_back(expair(first1->rest,newcoeff)); if (expair_needs_further_processing(seq.end()-1)) { needs_further_processing = true; } @@ -980,7 +984,7 @@ void expairseq::make_flat(const exvector &v) cit = v.begin(); while (cit!=v.end()) { - if (cit->bp->tinfo()==this->tinfo()) { + if (ex_to(*cit).tinfo()==this->tinfo()) { ++nexpairseqs; noperands += ex_to(*cit).seq.size(); } @@ -993,7 +997,7 @@ void expairseq::make_flat(const exvector &v) // copy elements and split off numerical part cit = v.begin(); while (cit!=v.end()) { - if (cit->bp->tinfo()==this->tinfo()) { + if (ex_to(*cit).tinfo()==this->tinfo()) { const expairseq &subseqref = ex_to(*cit); combine_overall_coeff(subseqref.overall_coeff); epvector::const_iterator cit_s = subseqref.seq.begin(); @@ -1024,7 +1028,7 @@ void expairseq::make_flat(const epvector &v) cit = v.begin(); while (cit!=v.end()) { - if (cit->rest.bp->tinfo()==this->tinfo()) { + if (ex_to(cit->rest).tinfo()==this->tinfo()) { ++nexpairseqs; noperands += ex_to(cit->rest).seq.size(); } @@ -1037,7 +1041,7 @@ void expairseq::make_flat(const epvector &v) // copy elements and split off numerical part cit = v.begin(); while (cit!=v.end()) { - if (cit->rest.bp->tinfo()==this->tinfo() && + if (ex_to(cit->rest).tinfo()==this->tinfo() && this->can_make_flat(*cit)) { const expairseq &subseqref = ex_to(cit->rest); combine_overall_coeff(ex_to(subseqref.overall_coeff), diff --git a/ginac/expairseq.h b/ginac/expairseq.h index 9fe72d57..5a24edd5 100644 --- a/ginac/expairseq.h +++ b/ginac/expairseq.h @@ -182,13 +182,6 @@ protected: // utility functions -/** Return the expairseq object handled by an ex. Deprecated: use ex_to(). - * This is unsafe: you need to check the type first. */ -inline const expairseq &ex_to_expairseq(const ex &e) -{ - return static_cast(*e.bp); -} - /** Specialization of is_exactly_a(obj) for expairseq objects. */ template<> inline bool is_exactly_a(const basic & obj) { diff --git a/ginac/fderivative.cpp b/ginac/fderivative.cpp index 7f40359b..23fc8376 100644 --- a/ginac/fderivative.cpp +++ b/ginac/fderivative.cpp @@ -198,7 +198,7 @@ ex fderivative::derivative(const symbol & s) const int fderivative::compare_same_type(const basic & other) const { - GINAC_ASSERT(is_of_type(other, fderivative)); + GINAC_ASSERT(is_a(other)); const fderivative & o = static_cast(other); if (parameter_set != o.parameter_set) @@ -209,7 +209,7 @@ int fderivative::compare_same_type(const basic & other) const bool fderivative::is_equal_same_type(const basic & other) const { - GINAC_ASSERT(is_of_type(other, fderivative)); + GINAC_ASSERT(is_a(other)); const fderivative & o = static_cast(other); if (parameter_set != o.parameter_set) @@ -220,7 +220,7 @@ bool fderivative::is_equal_same_type(const basic & other) const bool fderivative::match_same_type(const basic & other) const { - GINAC_ASSERT(is_of_type(other, fderivative)); + GINAC_ASSERT(is_a(other)); const fderivative & o = static_cast(other); return parameter_set == o.parameter_set; diff --git a/ginac/function.pl b/ginac/function.pl index 26f37afd..80f9c5e5 100755 --- a/ginac/function.pl +++ b/ginac/function.pl @@ -365,12 +365,6 @@ protected: }; // utility functions/macros -/** Return the object of type function handled by an ex. - * This is unsafe: you need to check the type first. */ -inline const function &ex_to_function(const ex &e) -{ - return static_cast(*e.bp); -} /** Specialization of is_exactly_a(obj) for objects of type function. */ template<> inline bool is_exactly_a(const basic & obj) @@ -379,7 +373,7 @@ template<> inline bool is_exactly_a(const basic & obj) } #define is_ex_the_function(OBJ, FUNCNAME) \\ - (is_exactly_a(OBJ) && static_cast(OBJ.bp)->get_serial() == function_index_##FUNCNAME) + (is_exactly_a(OBJ) && ex_to(OBJ).get_serial() == function_index_##FUNCNAME) } // namespace GiNaC @@ -707,17 +701,17 @@ ex function::expand(unsigned options) const int function::degree(const ex & s) const { - return is_equal(*s.bp) ? 1 : 0; + return is_equal(ex_to(s)) ? 1 : 0; } int function::ldegree(const ex & s) const { - return is_equal(*s.bp) ? 1 : 0; + return is_equal(ex_to(s)) ? 1 : 0; } ex function::coeff(const ex & s, int n) const { - if (is_equal(*s.bp)) + if (is_equal(ex_to(s))) return n==1 ? _ex1() : _ex0(); else return n==0 ? ex(*this) : _ex0(); diff --git a/ginac/idx.cpp b/ginac/idx.cpp index d704cbdd..9017a9ca 100644 --- a/ginac/idx.cpp +++ b/ginac/idx.cpp @@ -276,7 +276,7 @@ ex & idx::let_op(int i) * must be such that dummy indices lie next to each other. */ int idx::compare_same_type(const basic & other) const { - GINAC_ASSERT(is_of_type(other, idx)); + GINAC_ASSERT(is_a(other)); const idx &o = static_cast(other); int cmpval = value.compare(o.value); @@ -287,7 +287,7 @@ int idx::compare_same_type(const basic & other) const bool idx::match_same_type(const basic & other) const { - GINAC_ASSERT(is_of_type(other, idx)); + GINAC_ASSERT(is_a(other)); const idx &o = static_cast(other); return dim.is_equal(o.dim); @@ -295,7 +295,7 @@ bool idx::match_same_type(const basic & other) const int varidx::compare_same_type(const basic & other) const { - GINAC_ASSERT(is_of_type(other, varidx)); + GINAC_ASSERT(is_a(other)); const varidx &o = static_cast(other); int cmpval = inherited::compare_same_type(other); @@ -310,7 +310,7 @@ int varidx::compare_same_type(const basic & other) const bool varidx::match_same_type(const basic & other) const { - GINAC_ASSERT(is_of_type(other, varidx)); + GINAC_ASSERT(is_a(other)); const varidx &o = static_cast(other); if (covariant != o.covariant) @@ -320,7 +320,7 @@ bool varidx::match_same_type(const basic & other) const int spinidx::compare_same_type(const basic & other) const { - GINAC_ASSERT(is_of_type(other, spinidx)); + GINAC_ASSERT(is_a(other)); const spinidx &o = static_cast(other); // Check dottedness first so dummy indices will end up next to each other @@ -336,7 +336,7 @@ int spinidx::compare_same_type(const basic & other) const bool spinidx::match_same_type(const basic & other) const { - GINAC_ASSERT(is_of_type(other, spinidx)); + GINAC_ASSERT(is_a(other)); const spinidx &o = static_cast(other); if (dotted != o.dotted) @@ -357,7 +357,7 @@ ex idx::subs(const lst & ls, const lst & lr, bool no_pattern) const // First look for index substitutions for (unsigned i=0; i(ls.op(i)))) { // Substitution index->index if (is_ex_of_type(lr.op(i), idx)) diff --git a/ginac/idx.h b/ginac/idx.h index fd1ed47d..1ce32d2b 100644 --- a/ginac/idx.h +++ b/ginac/idx.h @@ -184,27 +184,6 @@ protected: // utility functions -/** Return the idx object handled by an ex. Deprecated: use ex_to(). - * This is unsafe: you need to check the type first. */ -inline const idx &ex_to_idx(const ex & e) -{ - return static_cast(*e.bp); -} - -/** Return the varidx object handled by an ex. Deprecated: use ex_to(). - * This is unsafe: you need to check the type first. */ -inline const varidx &ex_to_varidx(const ex & e) -{ - return static_cast(*e.bp); -} - -/** Return the spinidx object handled by an ex. Deprecated: use ex_to(). - * This is unsafe: you need to check the type first. */ -inline const spinidx &ex_to_spinidx(const ex & e) -{ - return static_cast(*e.bp); -} - /** Specialization of is_exactly_a(obj) for idx objects. */ template<> inline bool is_exactly_a(const basic & obj) { diff --git a/ginac/indexed.cpp b/ginac/indexed.cpp index bc6aa838..5759b24d 100644 --- a/ginac/indexed.cpp +++ b/ginac/indexed.cpp @@ -174,7 +174,7 @@ indexed::indexed(const archive_node &n, const lst &sym_lst) : inherited(n, sym_l symtree = sy_none(); break; } - ex_to_nonconst_symmetry(symtree).validate(seq.size() - 1); + const_cast(ex_to(symtree)).validate(seq.size() - 1); } } @@ -250,7 +250,7 @@ bool indexed::all_index_values_are(unsigned inf) const int indexed::compare_same_type(const basic & other) const { - GINAC_ASSERT(is_of_type(other, indexed)); + GINAC_ASSERT(is_a(other)); return inherited::compare_same_type(other); } @@ -277,7 +277,7 @@ ex indexed::eval(int level) const // Canonicalize indices according to the symmetry properties if (seq.size() > 2) { exvector v = seq; - GINAC_ASSERT(is_ex_exactly_of_type(symtree, symmetry)); + GINAC_ASSERT(is_exactly_a(symtree)); int sig = canonicalize(v.begin() + 1, ex_to(symtree)); if (sig != INT_MAX) { // Something has changed while sorting indices, more evaluations later @@ -288,22 +288,22 @@ ex indexed::eval(int level) const } // Let the class of the base object perform additional evaluations - return base.bp->eval_indexed(*this); + return ex_to(base).eval_indexed(*this); } int indexed::degree(const ex & s) const { - return is_equal(*s.bp) ? 1 : 0; + return is_equal(ex_to(s)) ? 1 : 0; } int indexed::ldegree(const ex & s) const { - return is_equal(*s.bp) ? 1 : 0; + return is_equal(ex_to(s)) ? 1 : 0; } ex indexed::coeff(const ex & s, int n) const { - if (is_equal(*s.bp)) + if (is_equal(ex_to(s))) return n==1 ? _ex1() : _ex0(); else return n==0 ? ex(*this) : _ex0(); @@ -406,7 +406,7 @@ void indexed::validate(void) const if (!symtree.is_zero()) { if (!is_ex_exactly_of_type(symtree, symmetry)) throw(std::invalid_argument("symmetry of indexed object must be of type symmetry")); - ex_to_nonconst_symmetry(symtree).validate(seq.size() - 1); + const_cast(ex_to(symtree)).validate(seq.size() - 1); } } @@ -669,12 +669,12 @@ try_again: } // Try to contract the first one with the second one - contracted = it1->op(0).bp->contract_with(it1, it2, v); + contracted = ex_to(it1->op(0)).contract_with(it1, it2, v); if (!contracted) { // That didn't work; maybe the second object knows how to // contract itself with the first one - contracted = it2->op(0).bp->contract_with(it2, it1, v); + contracted = ex_to(it2->op(0)).contract_with(it2, it1, v); } if (contracted) { contraction_done: @@ -745,7 +745,7 @@ contraction_done: // Product of indexed object with a scalar? if (is_ex_exactly_of_type(r, mul) && r.nops() == 2 && is_ex_exactly_of_type(r.op(1), numeric) && is_ex_of_type(r.op(0), indexed)) - return r.op(0).op(0).bp->scalar_mul_indexed(r.op(0), ex_to(r.op(1))); + return ex_to(r.op(0).op(0)).scalar_mul_indexed(r.op(0), ex_to(r.op(1))); else return r; } @@ -784,7 +784,7 @@ ex simplify_indexed(const ex & e, exvector & free_indices, exvector & dummy_indi if (!indices_consistent(free_indices, free_indices_of_term)) throw (std::runtime_error("simplify_indexed: inconsistent indices in sum")); if (is_ex_of_type(sum, indexed) && is_ex_of_type(term, indexed)) - sum = sum.op(0).bp->add_indexed(sum, term); + sum = ex_to(sum.op(0)).add_indexed(sum, term); else sum += term; } diff --git a/ginac/indexed.h b/ginac/indexed.h index b5a0dced..a2ee7494 100644 --- a/ginac/indexed.h +++ b/ginac/indexed.h @@ -235,13 +235,6 @@ private: // utility functions -/** Return the indexed object handled by an ex. Deprecated: use ex_to(). - * This is unsafe: you need to check the type first. */ -inline const indexed &ex_to_indexed(const ex &e) -{ - return static_cast(*e.bp); -} - /** Specialization of is_exactly_a(obj) for indexed objects. */ template<> inline bool is_exactly_a(const basic & obj) { diff --git a/ginac/inifcns.cpp b/ginac/inifcns.cpp index ebf04514..440354a1 100644 --- a/ginac/inifcns.cpp +++ b/ginac/inifcns.cpp @@ -407,10 +407,10 @@ static ex Order_eval(const ex & x) else return _ex0(); } else if (is_ex_exactly_of_type(x, mul)) { - mul *m = static_cast(x.bp); + const mul &m = ex_to(x); // O(c*expr) -> O(expr) - if (is_ex_exactly_of_type(m->op(m->nops() - 1), numeric)) - return Order(x / m->op(m->nops() - 1)).hold(); + if (is_ex_exactly_of_type(m.op(m.nops() - 1), numeric)) + return Order(x / m.op(m.nops() - 1)).hold(); } return Order(x).hold(); } @@ -419,7 +419,7 @@ static ex Order_series(const ex & x, const relational & r, int order, unsigned o { // Just wrap the function into a pseries object epvector new_seq; - GINAC_ASSERT(is_ex_exactly_of_type(r.lhs(),symbol)); + GINAC_ASSERT(is_exactly_a(r.lhs())); const symbol &s = ex_to(r.lhs()); new_seq.push_back(expair(Order(_ex1()), numeric(std::min(x.ldegree(s), order)))); return pseries(r, new_seq); @@ -444,7 +444,7 @@ ex lsolve(const ex &eqns, const ex &symbols, unsigned options) const ex sol = lsolve(lst(eqns),lst(symbols)); GINAC_ASSERT(sol.nops()==1); - GINAC_ASSERT(is_ex_exactly_of_type(sol.op(0),relational)); + GINAC_ASSERT(is_exactly_a(sol.op(0))); return sol.op(0).op(1); // return rhs of first solution } diff --git a/ginac/inifcns_gamma.cpp b/ginac/inifcns_gamma.cpp index ef0169b5..928a6b52 100644 --- a/ginac/inifcns_gamma.cpp +++ b/ginac/inifcns_gamma.cpp @@ -291,7 +291,7 @@ static ex beta_series(const ex & arg1, // tgamma series directly. const ex arg1_pt = arg1.subs(rel); const ex arg2_pt = arg2.subs(rel); - GINAC_ASSERT(is_ex_exactly_of_type(rel.lhs(),symbol)); + GINAC_ASSERT(is_exactly_a(rel.lhs())); const symbol &s = ex_to(rel.lhs()); ex arg1_ser, arg2_ser, arg1arg2_ser; if ((!arg1_pt.info(info_flags::integer) || arg1_pt.info(info_flags::positive)) && diff --git a/ginac/inifcns_trans.cpp b/ginac/inifcns_trans.cpp index 3b2608e6..507e18f5 100644 --- a/ginac/inifcns_trans.cpp +++ b/ginac/inifcns_trans.cpp @@ -146,7 +146,7 @@ static ex log_series(const ex &arg, int order, unsigned options) { - GINAC_ASSERT(is_ex_exactly_of_type(rel.lhs(),symbol)); + GINAC_ASSERT(is_exactly_a(rel.lhs())); ex arg_pt; bool must_expand_arg = false; // maybe substitution of rel into arg fails because of a pole @@ -460,7 +460,7 @@ static ex tan_series(const ex &x, int order, unsigned options) { - GINAC_ASSERT(is_ex_exactly_of_type(rel.lhs(),symbol)); + GINAC_ASSERT(is_exactly_a(rel.lhs())); // method: // Taylor series where there is no pole falls back to tan_deriv. // On a pole simply expand sin(x)/cos(x). @@ -626,7 +626,7 @@ static ex atan_series(const ex &arg, int order, unsigned options) { - GINAC_ASSERT(is_ex_exactly_of_type(rel.lhs(),symbol)); + GINAC_ASSERT(is_exactly_a(rel.lhs())); // method: // Taylor series where there is no pole or cut falls back to atan_deriv. // There are two branch cuts, one runnig from I up the imaginary axis and @@ -870,7 +870,7 @@ static ex tanh_series(const ex &x, int order, unsigned options) { - GINAC_ASSERT(is_ex_exactly_of_type(rel.lhs(),symbol)); + GINAC_ASSERT(is_exactly_a(rel.lhs())); // method: // Taylor series where there is no pole falls back to tanh_deriv. // On a pole simply expand sinh(x)/cosh(x). @@ -1011,7 +1011,7 @@ static ex atanh_series(const ex &arg, int order, unsigned options) { - GINAC_ASSERT(is_ex_exactly_of_type(rel.lhs(),symbol)); + GINAC_ASSERT(is_exactly_a(rel.lhs())); // method: // Taylor series where there is no pole or cut falls back to atanh_deriv. // There are two branch cuts, one runnig from 1 up the real axis and one diff --git a/ginac/input_parser.yy b/ginac/input_parser.yy index 5e29e482..bbc07647 100644 --- a/ginac/input_parser.yy +++ b/ginac/input_parser.yy @@ -89,13 +89,13 @@ exp : T_NUMBER {$$ = $1;} if (is_lexer_symbol_predefined($1)) $$ = $1.eval(); else - throw (std::runtime_error("unknown symbol '" + ex_to_symbol($1).get_name() + "'")); + throw (std::runtime_error("unknown symbol '" + ex_to($1).get_name() + "'")); } | T_LITERAL {$$ = $1;} | T_DIGITS {$$ = $1;} | T_SYMBOL '(' exprseq ')' { - unsigned i = function::find_function(ex_to_symbol($1).get_name(), $3.nops()); - $$ = function(i, static_cast(*($3.bp))).eval(1); + unsigned i = function::find_function(ex_to($1).get_name(), $3.nops()); + $$ = function(i, ex_to($3)).eval(1); } | exp T_EQUAL exp {$$ = $1 == $3;} | exp T_NOTEQ exp {$$ = $1 != $3;} @@ -113,11 +113,11 @@ exp : T_NUMBER {$$ = $1;} | exp '!' {$$ = factorial($1);} | '(' exp ')' {$$ = $2;} | '{' list_or_empty '}' {$$ = $2;} - | '[' matrix ']' {$$ = lst_to_matrix(ex_to_lst($2));} + | '[' matrix ']' {$$ = lst_to_matrix(ex_to($2));} ; exprseq : exp {$$ = exprseq($1);} - | exprseq ',' exp {exprseq es(static_cast(*($1.bp))); $$ = es.append($3);} + | exprseq ',' exp {exprseq es(ex_to($1)); $$ = es.append($3);} ; list_or_empty: /* empty */ {$$ = *new lst;} @@ -125,15 +125,15 @@ list_or_empty: /* empty */ {$$ = *new lst;} ; list : exp {$$ = lst($1);} - | list ',' exp {lst l(static_cast(*($1.bp))); $$ = l.append($3);} + | list ',' exp {lst l(ex_to($1)); $$ = l.append($3);} ; matrix : '[' row ']' {$$ = lst($2);} - | matrix ',' '[' row ']' {lst l(static_cast(*($1.bp))); $$ = l.append($4);} + | matrix ',' '[' row ']' {lst l(ex_to($1)); $$ = l.append($4);} ; row : exp {$$ = lst($1);} - | row ',' exp {lst l(static_cast(*($1.bp))); $$ = l.append($3);} + | row ',' exp {lst l(ex_to($1)); $$ = l.append($3);} ; diff --git a/ginac/matrix.cpp b/ginac/matrix.cpp index e9c68175..c48fb6b1 100644 --- a/ginac/matrix.cpp +++ b/ginac/matrix.cpp @@ -150,7 +150,7 @@ void matrix::print(const print_context & c, unsigned level) const { debugmsg("matrix print", LOGLEVEL_PRINT); - if (is_of_type(c, print_tree)) { + if (is_a(c)) { inherited::print(c, level); @@ -236,8 +236,8 @@ ex matrix::subs(const lst & ls, const lst & lr, bool no_pattern) const int matrix::compare_same_type(const basic & other) const { - GINAC_ASSERT(is_exactly_of_type(other, matrix)); - const matrix & o = static_cast(other); + GINAC_ASSERT(is_exactly_a(other)); + const matrix &o = static_cast(other); // compare number of rows if (row != o.rows()) @@ -261,7 +261,7 @@ int matrix::compare_same_type(const basic & other) const bool matrix::match_same_type(const basic & other) const { - GINAC_ASSERT(is_exactly_of_type(other, matrix)); + GINAC_ASSERT(is_exactly_a(other)); const matrix & o = static_cast(other); // The number of rows and columns must be the same. This is necessary to @@ -272,8 +272,8 @@ bool matrix::match_same_type(const basic & other) const /** Automatic symbolic evaluation of an indexed matrix. */ ex matrix::eval_indexed(const basic & i) const { - GINAC_ASSERT(is_of_type(i, indexed)); - GINAC_ASSERT(is_ex_of_type(i.op(0), matrix)); + GINAC_ASSERT(is_a(i)); + GINAC_ASSERT(is_a(i.op(0))); bool all_indices_unsigned = static_cast(i).all_index_values_are(info_flags::nonnegint); @@ -349,9 +349,9 @@ ex matrix::eval_indexed(const basic & i) const /** Sum of two indexed matrices. */ ex matrix::add_indexed(const ex & self, const ex & other) const { - GINAC_ASSERT(is_ex_of_type(self, indexed)); - GINAC_ASSERT(is_ex_of_type(self.op(0), matrix)); - GINAC_ASSERT(is_ex_of_type(other, indexed)); + GINAC_ASSERT(is_a(self)); + GINAC_ASSERT(is_a(self.op(0))); + GINAC_ASSERT(is_a(other)); GINAC_ASSERT(self.nops() == 2 || self.nops() == 3); // Only add two matrices @@ -385,8 +385,8 @@ ex matrix::add_indexed(const ex & self, const ex & other) const /** Product of an indexed matrix with a number. */ ex matrix::scalar_mul_indexed(const ex & self, const numeric & other) const { - GINAC_ASSERT(is_ex_of_type(self, indexed)); - GINAC_ASSERT(is_ex_of_type(self.op(0), matrix)); + GINAC_ASSERT(is_a(self)); + GINAC_ASSERT(is_a(self.op(0))); GINAC_ASSERT(self.nops() == 2 || self.nops() == 3); const matrix &self_matrix = ex_to(self.op(0)); @@ -400,10 +400,10 @@ ex matrix::scalar_mul_indexed(const ex & self, const numeric & other) const /** Contraction of an indexed matrix with something else. */ bool matrix::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const { - GINAC_ASSERT(is_ex_of_type(*self, indexed)); - GINAC_ASSERT(is_ex_of_type(*other, indexed)); + GINAC_ASSERT(is_a(*self)); + GINAC_ASSERT(is_a(*other)); GINAC_ASSERT(self->nops() == 2 || self->nops() == 3); - GINAC_ASSERT(is_ex_of_type(self->op(0), matrix)); + GINAC_ASSERT(is_a(self->op(0))); // Only contract with other matrices if (!is_ex_of_type(other->op(0), matrix)) @@ -1401,11 +1401,11 @@ int matrix::pivot(unsigned ro, unsigned co, bool symbolic) ++k; } else { // search largest element in column co beginning at row ro - GINAC_ASSERT(is_ex_of_type(this->m[k*col+co],numeric)); + GINAC_ASSERT(is_a(this->m[k*col+co])); unsigned kmax = k+1; numeric mmax = abs(ex_to(m[kmax*col+co])); while (kmaxm[kmax*col+co],numeric)); + GINAC_ASSERT(is_a(this->m[kmax*col+co])); numeric tmp = ex_to(this->m[kmax*col+co]); if (abs(tmp) > mmax) { mmax = tmp; diff --git a/ginac/matrix.h b/ginac/matrix.h index 59213742..acc52544 100644 --- a/ginac/matrix.h +++ b/ginac/matrix.h @@ -132,13 +132,6 @@ inline matrix inverse(const matrix & m) // utility functions -/** Return the matrix object handled by an ex. Deprecated: use ex_to(). - * This is unsafe: you need to check the type first. */ -inline const matrix &ex_to_matrix(const ex &e) -{ - return static_cast(*e.bp); -} - /** Specialization of is_exactly_a(obj) for matrix objects. */ template<> inline bool is_exactly_a(const basic & obj) { diff --git a/ginac/mul.cpp b/ginac/mul.cpp index 542e8023..da23307e 100644 --- a/ginac/mul.cpp +++ b/ginac/mul.cpp @@ -353,12 +353,12 @@ ex mul::eval(int level) const #ifdef DO_GINAC_ASSERT epvector::const_iterator i = seq.begin(), end = seq.end(); while (i != end) { - GINAC_ASSERT((!is_ex_exactly_of_type(i->rest, mul)) || + GINAC_ASSERT((!is_exactly_a(i->rest)) || (!(ex_to(i->coeff).is_integer()))); GINAC_ASSERT(!(i->is_canonical_numeric())); if (is_ex_exactly_of_type(recombine_pair_to_ex(*i), numeric)) print(print_tree(std::cerr)); - GINAC_ASSERT(!is_ex_exactly_of_type(recombine_pair_to_ex(*i), numeric)); + GINAC_ASSERT(!is_exactly_a(recombine_pair_to_ex(*i))); /* for paranoia */ expair p = split_ex_to_pair(recombine_pair_to_ex(*i)); GINAC_ASSERT(p.rest.is_equal(i->rest)); @@ -648,22 +648,22 @@ ex mul::default_overall_coeff(void) const void mul::combine_overall_coeff(const ex & c) { - GINAC_ASSERT(is_ex_exactly_of_type(overall_coeff,numeric)); - GINAC_ASSERT(is_ex_exactly_of_type(c,numeric)); + GINAC_ASSERT(is_exactly_a(overall_coeff)); + GINAC_ASSERT(is_exactly_a(c)); overall_coeff = ex_to(overall_coeff).mul_dyn(ex_to(c)); } void mul::combine_overall_coeff(const ex & c1, const ex & c2) { - GINAC_ASSERT(is_ex_exactly_of_type(overall_coeff,numeric)); - GINAC_ASSERT(is_ex_exactly_of_type(c1,numeric)); - GINAC_ASSERT(is_ex_exactly_of_type(c2,numeric)); + GINAC_ASSERT(is_exactly_a(overall_coeff)); + GINAC_ASSERT(is_exactly_a(c1)); + GINAC_ASSERT(is_exactly_a(c2)); overall_coeff = ex_to(overall_coeff).mul_dyn(ex_to(c1).power(ex_to(c2))); } bool mul::can_make_flat(const expair & p) const { - GINAC_ASSERT(is_ex_exactly_of_type(p.coeff,numeric)); + GINAC_ASSERT(is_exactly_a(p.coeff)); // this assertion will probably fail somewhere // it would require a more careful make_flat, obeying the power laws // probably should return true only if p.coeff is integer diff --git a/ginac/mul.h b/ginac/mul.h index 23e0e1f3..830c213a 100644 --- a/ginac/mul.h +++ b/ginac/mul.h @@ -91,13 +91,6 @@ protected: // utility functions -/** Return the mul object handled by an ex. Deprecated: use ex_to(). - * This is unsafe: you need to check the type first. */ -inline const mul &ex_to_mul(const ex &e) -{ - return static_cast(*e.bp); -} - /** Specialization of is_exactly_a(obj) for mul objects. */ template<> inline bool is_exactly_a(const basic & obj) { diff --git a/ginac/ncmul.cpp b/ginac/ncmul.cpp index eecafef4..473a1c9e 100644 --- a/ginac/ncmul.cpp +++ b/ginac/ncmul.cpp @@ -118,11 +118,11 @@ void ncmul::print(const print_context & c, unsigned level) const { debugmsg("ncmul print", LOGLEVEL_PRINT); - if (is_of_type(c, print_tree)) { + if (is_a(c)) { inherited::print(c, level); - } else if (is_of_type(c, print_csrc)) { + } else if (is_a(c)) { c.s << "ncmul("; exvector::const_iterator it = seq.begin(), itend = seq.end()-1; diff --git a/ginac/ncmul.h b/ginac/ncmul.h index 67d381bc..63696210 100644 --- a/ginac/ncmul.h +++ b/ginac/ncmul.h @@ -89,13 +89,6 @@ ex simplified_ncmul(const exvector & v); // utility functions -/** Return the ncmul object handled by an ex. Deprecated: use ex_to(). - * This is unsafe: you need to check the type first. */ -inline const ncmul &ex_to_ncmul(const ex &e) -{ - return static_cast (*e.bp); -} - /** Specialization of is_exactly_a(obj) for ncmul objects. */ template<> inline bool is_exactly_a(const basic & obj) { diff --git a/ginac/normal.cpp b/ginac/normal.cpp index c948680f..e9117c4d 100644 --- a/ginac/normal.cpp +++ b/ginac/normal.cpp @@ -322,12 +322,12 @@ numeric add::integer_content(void) const epvector::const_iterator itend = seq.end(); numeric c = _num0(); while (it != itend) { - GINAC_ASSERT(!is_ex_exactly_of_type(it->rest,numeric)); - GINAC_ASSERT(is_ex_exactly_of_type(it->coeff,numeric)); + GINAC_ASSERT(!is_exactly_a(it->rest)); + GINAC_ASSERT(is_exactly_a(it->coeff)); c = gcd(ex_to(it->coeff), c); it++; } - GINAC_ASSERT(is_ex_exactly_of_type(overall_coeff,numeric)); + GINAC_ASSERT(is_exactly_a(overall_coeff)); c = gcd(ex_to(overall_coeff),c); return c; } @@ -338,11 +338,11 @@ numeric mul::integer_content(void) const epvector::const_iterator it = seq.begin(); epvector::const_iterator itend = seq.end(); while (it != itend) { - GINAC_ASSERT(!is_ex_exactly_of_type(recombine_pair_to_ex(*it),numeric)); + GINAC_ASSERT(!is_exactly_a(recombine_pair_to_ex(*it))); ++it; } #endif // def DO_GINAC_ASSERT - GINAC_ASSERT(is_ex_exactly_of_type(overall_coeff,numeric)); + GINAC_ASSERT(is_exactly_a(overall_coeff)); return abs(ex_to(overall_coeff)); } @@ -1228,11 +1228,11 @@ numeric add::max_coefficient(void) const { epvector::const_iterator it = seq.begin(); epvector::const_iterator itend = seq.end(); - GINAC_ASSERT(is_ex_exactly_of_type(overall_coeff,numeric)); + GINAC_ASSERT(is_exactly_a(overall_coeff)); numeric cur_max = abs(ex_to(overall_coeff)); while (it != itend) { numeric a; - GINAC_ASSERT(!is_ex_exactly_of_type(it->rest,numeric)); + GINAC_ASSERT(!is_exactly_a(it->rest)); a = abs(ex_to(it->coeff)); if (a > cur_max) cur_max = a; @@ -1247,11 +1247,11 @@ numeric mul::max_coefficient(void) const epvector::const_iterator it = seq.begin(); epvector::const_iterator itend = seq.end(); while (it != itend) { - GINAC_ASSERT(!is_ex_exactly_of_type(recombine_pair_to_ex(*it),numeric)); + GINAC_ASSERT(!is_exactly_a(recombine_pair_to_ex(*it))); it++; } #endif // def DO_GINAC_ASSERT - GINAC_ASSERT(is_ex_exactly_of_type(overall_coeff,numeric)); + GINAC_ASSERT(is_exactly_a(overall_coeff)); return abs(ex_to(overall_coeff)); } @@ -1279,13 +1279,13 @@ ex add::smod(const numeric &xi) const epvector::const_iterator it = seq.begin(); epvector::const_iterator itend = seq.end(); while (it != itend) { - GINAC_ASSERT(!is_ex_exactly_of_type(it->rest,numeric)); + GINAC_ASSERT(!is_exactly_a(it->rest)); numeric coeff = GiNaC::smod(ex_to(it->coeff), xi); if (!coeff.is_zero()) newseq.push_back(expair(it->rest, coeff)); it++; } - GINAC_ASSERT(is_ex_exactly_of_type(overall_coeff,numeric)); + GINAC_ASSERT(is_exactly_a(overall_coeff)); numeric coeff = GiNaC::smod(ex_to(overall_coeff), xi); return (new add(newseq,coeff))->setflag(status_flags::dynallocated); } @@ -1296,12 +1296,12 @@ ex mul::smod(const numeric &xi) const epvector::const_iterator it = seq.begin(); epvector::const_iterator itend = seq.end(); while (it != itend) { - GINAC_ASSERT(!is_ex_exactly_of_type(recombine_pair_to_ex(*it),numeric)); + GINAC_ASSERT(!is_exactly_a(recombine_pair_to_ex(*it))); it++; } #endif // def DO_GINAC_ASSERT mul * mulcopyp = new mul(*this); - GINAC_ASSERT(is_ex_exactly_of_type(overall_coeff,numeric)); + GINAC_ASSERT(is_exactly_a(overall_coeff)); mulcopyp->overall_coeff = GiNaC::smod(ex_to(overall_coeff),xi); mulcopyp->clearflag(status_flags::evaluated); mulcopyp->clearflag(status_flags::hash_calculated); @@ -2030,7 +2030,7 @@ static ex frac_cancel(const ex &n, const ex &d) // as defined by get_first_symbol() is made positive) const symbol *x; if (get_first_symbol(den, x)) { - GINAC_ASSERT(is_ex_exactly_of_type(den.unit(*x),numeric)); + GINAC_ASSERT(is_exactly_a(den.unit(*x))); if (ex_to(den.unit(*x)).is_negative()) { num *= _ex_1(); den *= _ex_1(); @@ -2226,7 +2226,7 @@ ex ex::normal(int level) const lst sym_lst, repl_lst; ex e = bp->normal(sym_lst, repl_lst, level); - GINAC_ASSERT(is_ex_of_type(e, lst)); + GINAC_ASSERT(is_a(e)); // Re-insert replaced symbols if (sym_lst.nops() > 0) @@ -2247,7 +2247,7 @@ ex ex::numer(void) const lst sym_lst, repl_lst; ex e = bp->normal(sym_lst, repl_lst, 0); - GINAC_ASSERT(is_ex_of_type(e, lst)); + GINAC_ASSERT(is_a(e)); // Re-insert replaced symbols if (sym_lst.nops() > 0) @@ -2267,7 +2267,7 @@ ex ex::denom(void) const lst sym_lst, repl_lst; ex e = bp->normal(sym_lst, repl_lst, 0); - GINAC_ASSERT(is_ex_of_type(e, lst)); + GINAC_ASSERT(is_a(e)); // Re-insert replaced symbols if (sym_lst.nops() > 0) @@ -2287,7 +2287,7 @@ ex ex::numer_denom(void) const lst sym_lst, repl_lst; ex e = bp->normal(sym_lst, repl_lst, 0); - GINAC_ASSERT(is_ex_of_type(e, lst)); + GINAC_ASSERT(is_a(e)); // Re-insert replaced symbols if (sym_lst.nops() > 0) diff --git a/ginac/numeric.cpp b/ginac/numeric.cpp index bdd8903c..9d5f7f01 100644 --- a/ginac/numeric.cpp +++ b/ginac/numeric.cpp @@ -583,7 +583,7 @@ ex numeric::evalf(int level) const int numeric::compare_same_type(const basic &other) const { - GINAC_ASSERT(is_exactly_of_type(other, numeric)); + GINAC_ASSERT(is_exactly_a(other)); const numeric &o = static_cast(other); return this->compare(o); @@ -592,7 +592,7 @@ int numeric::compare_same_type(const basic &other) const bool numeric::is_equal_same_type(const basic &other) const { - GINAC_ASSERT(is_exactly_of_type(other,numeric)); + GINAC_ASSERT(is_exactly_a(other)); const numeric &o = static_cast(other); return this->is_equal(o); diff --git a/ginac/numeric.h b/ginac/numeric.h index 09f15233..6599ffbc 100644 --- a/ginac/numeric.h +++ b/ginac/numeric.h @@ -286,13 +286,6 @@ ex CatalanEvalf(void); // utility functions -/** Return the numeric object handled by an ex. Deprecated: use ex_to(). - * This is unsafe: you need to check the type first. */ -inline const numeric &ex_to_numeric(const ex &e) -{ - return static_cast(*e.bp); -} - /** Specialization of is_exactly_a(obj) for numeric objects. */ template<> inline bool is_exactly_a(const basic & obj) { diff --git a/ginac/power.cpp b/ginac/power.cpp index 66181941..33f572f9 100644 --- a/ginac/power.cpp +++ b/ginac/power.cpp @@ -551,7 +551,7 @@ ex power::derivative(const symbol & s) const int power::compare_same_type(const basic & other) const { - GINAC_ASSERT(is_exactly_of_type(other, power)); + GINAC_ASSERT(is_exactly_a(other)); const power &o = static_cast(other); int cmpval = basis.compare(o.basis); @@ -671,13 +671,13 @@ ex power::expand_add(const add & a, int n) const term.reserve(m+1); for (l=0; l(b).exponent,numeric) || + GINAC_ASSERT(!is_exactly_a(b)); + GINAC_ASSERT(!is_exactly_a(b) || + !is_exactly_a(ex_to(b).exponent) || !ex_to(ex_to(b).exponent).is_pos_integer() || - !is_ex_exactly_of_type(ex_to(b).basis,add) || - !is_ex_exactly_of_type(ex_to(b).basis,mul) || - !is_ex_exactly_of_type(ex_to(b).basis,power)); + !is_exactly_a(ex_to(b).basis) || + !is_exactly_a(ex_to(b).basis) || + !is_exactly_a(ex_to(b).basis)); if (is_ex_exactly_of_type(b,mul)) term.push_back(expand_mul(ex_to(b),numeric(k[l]))); else @@ -685,13 +685,13 @@ ex power::expand_add(const add & a, int n) const } const ex & b = a.op(l); - GINAC_ASSERT(!is_ex_exactly_of_type(b,add)); - GINAC_ASSERT(!is_ex_exactly_of_type(b,power) || - !is_ex_exactly_of_type(ex_to(b).exponent,numeric) || + GINAC_ASSERT(!is_exactly_a(b)); + GINAC_ASSERT(!is_exactly_a(b) || + !is_exactly_a(ex_to(b).exponent) || !ex_to(ex_to(b).exponent).is_pos_integer() || - !is_ex_exactly_of_type(ex_to(b).basis,add) || - !is_ex_exactly_of_type(ex_to(b).basis,mul) || - !is_ex_exactly_of_type(ex_to(b).basis,power)); + !is_exactly_a(ex_to(b).basis) || + !is_exactly_a(ex_to(b).basis) || + !is_exactly_a(ex_to(b).basis)); if (is_ex_exactly_of_type(b,mul)) term.push_back(expand_mul(ex_to(b),numeric(n-k_cum[m-2]))); else @@ -746,13 +746,13 @@ ex power::expand_add_2(const add & a) const const ex & r = cit0->rest; const ex & c = cit0->coeff; - GINAC_ASSERT(!is_ex_exactly_of_type(r,add)); - GINAC_ASSERT(!is_ex_exactly_of_type(r,power) || - !is_ex_exactly_of_type(ex_to(r).exponent,numeric) || + GINAC_ASSERT(!is_exactly_a(r)); + GINAC_ASSERT(!is_exactly_a(r) || + !is_exactly_a(ex_to(r).exponent) || !ex_to(ex_to(r).exponent).is_pos_integer() || - !is_ex_exactly_of_type(ex_to(r).basis,add) || - !is_ex_exactly_of_type(ex_to(r).basis,mul) || - !is_ex_exactly_of_type(ex_to(r).basis,power)); + !is_exactly_a(ex_to(r).basis) || + !is_exactly_a(ex_to(r).basis) || + !is_exactly_a(ex_to(r).basis)); if (are_ex_trivially_equal(c,_ex1())) { if (is_ex_exactly_of_type(r,mul)) { diff --git a/ginac/power.h b/ginac/power.h index 175fea05..06f9681e 100644 --- a/ginac/power.h +++ b/ginac/power.h @@ -90,13 +90,6 @@ protected: // utility functions -/** Return the power object handled by an ex. Deprecated: use ex_to(). - * This is unsafe: you need to check the type first. */ -inline const power &ex_to_power(const ex &e) -{ - return static_cast(*e.bp); -} - /** Efficient specialization of is_exactly_a(obj) for power objects. */ template<> inline bool is_exactly_a(const basic & obj) { diff --git a/ginac/pseries.cpp b/ginac/pseries.cpp index 441ee408..b348fd31 100644 --- a/ginac/pseries.cpp +++ b/ginac/pseries.cpp @@ -208,7 +208,7 @@ void pseries::print(const print_context & c, unsigned level) const int pseries::compare_same_type(const basic & other) const { - GINAC_ASSERT(is_of_type(other, pseries)); + GINAC_ASSERT(is_a(other)); const pseries &o = static_cast(other); // first compare the lengths of the series... diff --git a/ginac/pseries.h b/ginac/pseries.h index bd2db158..2ab9bfc9 100644 --- a/ginac/pseries.h +++ b/ginac/pseries.h @@ -101,17 +101,8 @@ protected: ex point; }; -/** Return a reference to the pseries object embedded in an expression. - * The result is undefined if the expression does not contain a pseries - * object at its top level. - * - * @param e expression - * @return reference to pseries object - * @see is_a<> */ -inline const pseries &ex_to_pseries(const ex &e) -{ - return static_cast(*e.bp); -} + +// utility functions /** Specialization of is_exactly_a(obj) for pseries objects. */ template<> inline bool is_exactly_a(const basic & obj) @@ -129,7 +120,7 @@ template<> inline bool is_exactly_a(const basic & obj) * @see pseries::convert_to_poly */ inline ex series_to_poly(const ex &e) { - return (static_cast(*e.bp).convert_to_poly(true)); + return (ex_to(e).convert_to_poly(true)); } inline bool is_terminating(const pseries & s) diff --git a/ginac/relational.cpp b/ginac/relational.cpp index c4e34ddf..6d51a563 100644 --- a/ginac/relational.cpp +++ b/ginac/relational.cpp @@ -101,7 +101,7 @@ void relational::print(const print_context & c, unsigned level) const { debugmsg("relational print",LOGLEVEL_PRINT); - if (is_of_type(c, print_tree)) { + if (is_a(c)) { inherited::print(c, level); @@ -192,7 +192,7 @@ ex relational::simplify_ncmul(const exvector & v) const int relational::compare_same_type(const basic & other) const { - GINAC_ASSERT(is_exactly_of_type(other, relational)); + GINAC_ASSERT(is_exactly_a(other)); const relational &oth = static_cast(other); if (o == oth.o) { @@ -207,7 +207,7 @@ int relational::compare_same_type(const basic & other) const bool relational::match_same_type(const basic & other) const { - GINAC_ASSERT(is_exactly_of_type(other, relational)); + GINAC_ASSERT(is_exactly_a(other)); const relational &oth = static_cast(other); return o == oth.o; diff --git a/ginac/relational.h b/ginac/relational.h index 40c799bf..fb111158 100644 --- a/ginac/relational.h +++ b/ginac/relational.h @@ -83,13 +83,6 @@ protected: // utility functions -/** Return the relational object handled by an ex. Deprecated: use ex_to(). - * This is unsafe: you need to check the type first. */ -inline const relational &ex_to_relational(const ex &e) -{ - return static_cast(*e.bp); -} - /** Specialization of is_exactly_a(obj) for relational objects. */ template<> inline bool is_exactly_a(const basic & obj) { diff --git a/ginac/structure.cpp b/ginac/structure.cpp index e1ea6d56..b094c09c 100644 --- a/ginac/structure.cpp +++ b/ginac/structure.cpp @@ -52,7 +52,7 @@ void structure::print(const print_context & c, unsigned level) const { debugmsg("structure print",LOGLEVEL_PRINT); - if (is_of_type(c, print_tree)) { + if (is_a(c)) { c.s << std::string(level, ' ') << class_name() << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec @@ -68,7 +68,7 @@ DEFAULT_COMPARE(structure) bool structure::is_equal_same_type(const basic & other) const { - GINAC_ASSERT(is_of_type(other, structure)); + GINAC_ASSERT(is_a(other)); return true; // all structures are the same } diff --git a/ginac/symbol.cpp b/ginac/symbol.cpp index 322a45c4..9d291686 100644 --- a/ginac/symbol.cpp +++ b/ginac/symbol.cpp @@ -153,14 +153,14 @@ void symbol::print(const print_context & c, unsigned level) const { debugmsg("symbol print", LOGLEVEL_PRINT); - if (is_of_type(c, print_tree)) { + if (is_a(c)) { c.s << std::string(level, ' ') << name << " (" << class_name() << ")" << ", serial=" << serial << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec << std::endl; - } else if (is_of_type(c, print_latex)) + } else if (is_a(c)) c.s << TeX_name; else c.s << name; @@ -230,7 +230,7 @@ ex symbol::derivative(const symbol & s) const int symbol::compare_same_type(const basic & other) const { - GINAC_ASSERT(is_of_type(other,symbol)); + GINAC_ASSERT(is_a(other)); const symbol *o = static_cast(&other); if (serial==o->serial) return 0; return serial < o->serial ? -1 : 1; @@ -238,7 +238,7 @@ int symbol::compare_same_type(const basic & other) const bool symbol::is_equal_same_type(const basic & other) const { - GINAC_ASSERT(is_of_type(other,symbol)); + GINAC_ASSERT(is_a(other)); const symbol *o = static_cast(&other); return serial==o->serial; } diff --git a/ginac/symbol.h b/ginac/symbol.h index 2d9ec3ba..fb4b99e1 100644 --- a/ginac/symbol.h +++ b/ginac/symbol.h @@ -113,18 +113,6 @@ private: // utility functions -/** Return the symbol object handled by an ex. Deprecated: use ex_to(). - * This is unsafe: you need to check the type first. */ -inline const symbol &ex_to_symbol(const ex &e) -{ - return static_cast(*e.bp); -} - -inline symbol &ex_to_nonconst_symbol(const ex &e) -{ - return static_cast(*e.bp); -} - /** Specialization of is_exactly_a(obj) for symbol objects. */ template<> inline bool is_exactly_a(const basic & obj) { diff --git a/ginac/symmetry.cpp b/ginac/symmetry.cpp index 2312526e..e0f1ba3e 100644 --- a/ginac/symmetry.cpp +++ b/ginac/symmetry.cpp @@ -154,7 +154,7 @@ DEFAULT_UNARCHIVE(symmetry) int symmetry::compare_same_type(const basic & other) const { - GINAC_ASSERT(is_of_type(other, symmetry)); + GINAC_ASSERT(is_a(other)); // All symmetry trees are equal. They are not supposed to appear in // ordinary expressions anyway... @@ -165,7 +165,7 @@ void symmetry::print(const print_context & c, unsigned level) const { debugmsg("symmetry print", LOGLEVEL_PRINT); - if (is_of_type(c, print_tree)) { + if (is_a(c)) { c.s << std::string(level, ' ') << class_name() << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec @@ -231,7 +231,7 @@ symmetry &symmetry::add(const symmetry &c) { // All children must have the same number of indices if (type != none && !children.empty()) { - GINAC_ASSERT(is_ex_exactly_of_type(children[0], symmetry)); + GINAC_ASSERT(is_exactly_a(children[0])); if (ex_to(children[0]).indices.size() != c.indices.size()) throw (std::logic_error("symmetry:add(): children must have same number of indices")); } @@ -272,8 +272,8 @@ public: bool operator() (const ex &lh, const ex &rh) const { - GINAC_ASSERT(is_ex_exactly_of_type(lh, symmetry)); - GINAC_ASSERT(is_ex_exactly_of_type(rh, symmetry)); + GINAC_ASSERT(is_exactly_a(lh)); + GINAC_ASSERT(is_exactly_a(rh)); GINAC_ASSERT(ex_to(lh).indices.size() == ex_to(rh).indices.size()); std::set::const_iterator ait = ex_to(lh).indices.begin(), aitend = ex_to(lh).indices.end(), bit = ex_to(rh).indices.begin(); while (ait != aitend) { @@ -298,8 +298,8 @@ public: void operator() (const ex &lh, const ex &rh) { - GINAC_ASSERT(is_ex_exactly_of_type(lh, symmetry)); - GINAC_ASSERT(is_ex_exactly_of_type(rh, symmetry)); + GINAC_ASSERT(is_exactly_a(lh)); + GINAC_ASSERT(is_exactly_a(rh)); GINAC_ASSERT(ex_to(lh).indices.size() == ex_to(rh).indices.size()); std::set::const_iterator ait = ex_to(lh).indices.begin(), aitend = ex_to(lh).indices.end(), bit = ex_to(rh).indices.begin(); while (ait != aitend) { @@ -321,7 +321,7 @@ int canonicalize(exvector::iterator v, const symmetry &symm) int sign = 1; exvector::const_iterator first = symm.children.begin(), last = symm.children.end(); while (first != last) { - GINAC_ASSERT(is_ex_exactly_of_type(*first, symmetry)); + GINAC_ASSERT(is_exactly_a(*first)); int child_sign = canonicalize(v, ex_to(*first)); if (child_sign == 0) return 0; diff --git a/ginac/symmetry.h b/ginac/symmetry.h index 21ab09fb..bdcd261a 100644 --- a/ginac/symmetry.h +++ b/ginac/symmetry.h @@ -99,10 +99,6 @@ private: // global functions -inline symmetry &ex_to_nonconst_symmetry(const ex &e) -{ - return static_cast(*e.bp); -} inline symmetry sy_none(void) { return symmetry(); } inline symmetry sy_none(const symmetry &c1, const symmetry &c2) { return symmetry(symmetry::none, c1, c2); } diff --git a/ginac/tensor.cpp b/ginac/tensor.cpp index 7b3d1417..8881425f 100644 --- a/ginac/tensor.cpp +++ b/ginac/tensor.cpp @@ -153,7 +153,7 @@ DEFAULT_COMPARE(spinmetric) int minkmetric::compare_same_type(const basic & other) const { - GINAC_ASSERT(is_of_type(other, minkmetric)); + GINAC_ASSERT(is_a(other)); const minkmetric &o = static_cast(other); if (pos_sig != o.pos_sig) @@ -164,7 +164,7 @@ int minkmetric::compare_same_type(const basic & other) const int tensepsilon::compare_same_type(const basic & other) const { - GINAC_ASSERT(is_of_type(other, tensepsilon)); + GINAC_ASSERT(is_a(other)); const tensepsilon &o = static_cast(other); if (minkowski != o.minkowski) @@ -184,9 +184,9 @@ DEFAULT_PRINT_LATEX(tensepsilon, "eps", "\\varepsilon") /** Automatic symbolic evaluation of an indexed delta tensor. */ ex tensdelta::eval_indexed(const basic & i) const { - GINAC_ASSERT(is_of_type(i, indexed)); + GINAC_ASSERT(is_a(i)); GINAC_ASSERT(i.nops() == 3); - GINAC_ASSERT(is_ex_of_type(i.op(0), tensdelta)); + GINAC_ASSERT(is_a(i.op(0))); const idx & i1 = ex_to(i.op(1)); const idx & i2 = ex_to(i.op(2)); @@ -211,11 +211,11 @@ ex tensdelta::eval_indexed(const basic & i) const /** Automatic symbolic evaluation of an indexed metric tensor. */ ex tensmetric::eval_indexed(const basic & i) const { - GINAC_ASSERT(is_of_type(i, indexed)); + GINAC_ASSERT(is_a(i)); GINAC_ASSERT(i.nops() == 3); - GINAC_ASSERT(is_ex_of_type(i.op(0), tensmetric)); - GINAC_ASSERT(is_ex_of_type(i.op(1), varidx)); - GINAC_ASSERT(is_ex_of_type(i.op(2), varidx)); + GINAC_ASSERT(is_a(i.op(0))); + GINAC_ASSERT(is_a(i.op(1))); + GINAC_ASSERT(is_a(i.op(2))); const varidx & i1 = ex_to(i.op(1)); const varidx & i2 = ex_to(i.op(2)); @@ -232,11 +232,11 @@ ex tensmetric::eval_indexed(const basic & i) const /** Automatic symbolic evaluation of an indexed Lorentz metric tensor. */ ex minkmetric::eval_indexed(const basic & i) const { - GINAC_ASSERT(is_of_type(i, indexed)); + GINAC_ASSERT(is_a(i)); GINAC_ASSERT(i.nops() == 3); - GINAC_ASSERT(is_ex_of_type(i.op(0), minkmetric)); - GINAC_ASSERT(is_ex_of_type(i.op(1), varidx)); - GINAC_ASSERT(is_ex_of_type(i.op(2), varidx)); + GINAC_ASSERT(is_a(i.op(0))); + GINAC_ASSERT(is_a(i.op(1))); + GINAC_ASSERT(is_a(i.op(2))); const varidx & i1 = ex_to(i.op(1)); const varidx & i2 = ex_to(i.op(2)); @@ -259,11 +259,11 @@ ex minkmetric::eval_indexed(const basic & i) const /** Automatic symbolic evaluation of an indexed metric tensor. */ ex spinmetric::eval_indexed(const basic & i) const { - GINAC_ASSERT(is_of_type(i, indexed)); + GINAC_ASSERT(is_a(i)); GINAC_ASSERT(i.nops() == 3); - GINAC_ASSERT(is_ex_of_type(i.op(0), spinmetric)); - GINAC_ASSERT(is_ex_of_type(i.op(1), spinidx)); - GINAC_ASSERT(is_ex_of_type(i.op(2), spinidx)); + GINAC_ASSERT(is_a(i.op(0))); + GINAC_ASSERT(is_a(i.op(1))); + GINAC_ASSERT(is_a(i.op(2))); const spinidx & i1 = ex_to(i.op(1)); const spinidx & i2 = ex_to(i.op(2)); @@ -290,9 +290,9 @@ ex spinmetric::eval_indexed(const basic & i) const /** Automatic symbolic evaluation of an indexed epsilon tensor. */ ex tensepsilon::eval_indexed(const basic & i) const { - GINAC_ASSERT(is_of_type(i, indexed)); + GINAC_ASSERT(is_a(i)); GINAC_ASSERT(i.nops() > 1); - GINAC_ASSERT(is_ex_of_type(i.op(0), tensepsilon)); + GINAC_ASSERT(is_a(i.op(0))); // Convolutions are zero if (!(static_cast(i).get_dummy_indices().empty())) @@ -333,10 +333,10 @@ ex tensepsilon::eval_indexed(const basic & i) const /** Contraction of an indexed delta tensor with something else. */ bool tensdelta::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const { - GINAC_ASSERT(is_ex_of_type(*self, indexed)); - GINAC_ASSERT(is_ex_of_type(*other, indexed)); + GINAC_ASSERT(is_a(*self)); + GINAC_ASSERT(is_a(*other)); GINAC_ASSERT(self->nops() == 3); - GINAC_ASSERT(is_ex_of_type(self->op(0), tensdelta)); + GINAC_ASSERT(is_a(self->op(0))); // Try to contract first index const idx *self_idx = &ex_to(self->op(1)); @@ -373,10 +373,10 @@ again: /** Contraction of an indexed metric tensor with something else. */ bool tensmetric::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const { - GINAC_ASSERT(is_ex_of_type(*self, indexed)); - GINAC_ASSERT(is_ex_of_type(*other, indexed)); + GINAC_ASSERT(is_a(*self)); + GINAC_ASSERT(is_a(*other)); GINAC_ASSERT(self->nops() == 3); - GINAC_ASSERT(is_ex_of_type(self->op(0), tensmetric)); + GINAC_ASSERT(is_a(self->op(0))); // If contracting with the delta tensor, let the delta do it // (don't raise/lower delta indices) @@ -418,10 +418,10 @@ again: /** Contraction of an indexed spinor metric with something else. */ bool spinmetric::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const { - GINAC_ASSERT(is_ex_of_type(*self, indexed)); - GINAC_ASSERT(is_ex_of_type(*other, indexed)); + GINAC_ASSERT(is_a(*self)); + GINAC_ASSERT(is_a(*other)); GINAC_ASSERT(self->nops() == 3); - GINAC_ASSERT(is_ex_of_type(self->op(0), spinmetric)); + GINAC_ASSERT(is_a(self->op(0))); // Contractions between spinor metrics if (is_ex_of_type(other->op(0), spinmetric)) { @@ -497,9 +497,9 @@ again: /** Contraction of epsilon tensor with something else. */ bool tensepsilon::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const { - GINAC_ASSERT(is_ex_of_type(*self, indexed)); - GINAC_ASSERT(is_ex_of_type(*other, indexed)); - GINAC_ASSERT(is_ex_of_type(self->op(0), tensepsilon)); + GINAC_ASSERT(is_a(*self)); + GINAC_ASSERT(is_a(*other)); + GINAC_ASSERT(is_a(self->op(0))); unsigned num = self->nops() - 1; if (is_ex_exactly_of_type(other->op(0), tensepsilon) && num+1 == other->nops()) { diff --git a/ginac/tensor.h b/ginac/tensor.h index e30a91a4..d3b27b60 100644 --- a/ginac/tensor.h +++ b/ginac/tensor.h @@ -139,13 +139,6 @@ private: // utility functions -/** Return the tensor object handled by an ex. Deprecated: use ex_to(). - * This is unsafe: you need to check the type first. */ -inline const tensor &ex_to_tensor(const ex &e) -{ - return static_cast(*e.bp); -} - /** Create a delta tensor with specified indices. The indices must be of class * idx or a subclass. The delta tensor is always symmetric and its trace is * the dimension of the index space. diff --git a/ginac/wildcard.cpp b/ginac/wildcard.cpp index c6dca58c..f203c5f0 100644 --- a/ginac/wildcard.cpp +++ b/ginac/wildcard.cpp @@ -82,7 +82,7 @@ DEFAULT_UNARCHIVE(wildcard) int wildcard::compare_same_type(const basic & other) const { - GINAC_ASSERT(is_of_type(other, wildcard)); + GINAC_ASSERT(is_a(other)); const wildcard &o = static_cast(other); if (label == o.label) @@ -95,7 +95,7 @@ void wildcard::print(const print_context & c, unsigned level) const { debugmsg("wildcard print", LOGLEVEL_PRINT); - if (is_of_type(c, print_tree)) { + if (is_a(c)) { c.s << std::string(level, ' ') << class_name() << " (" << label << ")" << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec << std::endl; diff --git a/ginac/wildcard.h b/ginac/wildcard.h index f787bcba..4b0e31f6 100644 --- a/ginac/wildcard.h +++ b/ginac/wildcard.h @@ -59,13 +59,6 @@ private: // utility functions -/** Return the wildcard object handled by an ex. Deprecated: use ex_to(). - * This is unsafe: you need to check the type first. */ -inline const wildcard &ex_to_wildcard(const ex &e) -{ - return static_cast(*e.bp); -} - /** Specialization of is_exactly_a(obj) for wildcard objects. */ template<> inline bool is_exactly_a(const basic & obj) { diff --git a/ginsh/ginsh_parser.yy b/ginsh/ginsh_parser.yy index 50d2a23b..bcd963b9 100644 --- a/ginsh/ginsh_parser.yy +++ b/ginsh/ginsh_parser.yy @@ -209,7 +209,7 @@ exp : T_NUMBER {$$ = $1;} } } | T_DIGITS '=' T_NUMBER {$$ = $3; Digits = ex_to($3).to_int();} - | T_SYMBOL '=' exp {$$ = $3; ex_to_nonconst_symbol($1).assign($3);} + | T_SYMBOL '=' exp {$$ = $3; const_cast(ex_to($1)).assign($3);} | exp T_EQUAL exp {$$ = $1 == $3;} | exp T_NOTEQ exp {$$ = $1 != $3;} | exp '<' exp {$$ = $1 < $3;} @@ -490,7 +490,7 @@ static ex f_transpose(const exprseq &e) static ex f_unassign(const exprseq &e) { CHECK_ARG(0, symbol, unassign); - ex_to_nonconst_symbol(e[0]).unassign(); + const_cast(ex_to(e[0])).unassign(); return e[0]; }