X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fex.h;h=d16bdbc1998c5b31de414f232b42c8e675baa97a;hp=b9360416018296a349b967b2c1c130e24ec793f9;hb=757406e244f4f257aafaa0f355d5376122cea10e;hpb=201fc92bfd5806596a5a75a5ae0586d7302c0897 diff --git a/ginac/ex.h b/ginac/ex.h index b9360416..d16bdbc1 100644 --- a/ginac/ex.h +++ b/ginac/ex.h @@ -555,6 +555,36 @@ inline ex ex::map(ex f(const ex &)) const return bp->map(fcn); } +// convenience type checker template functions + +/** Check if ex is a handle to a T, including base classes. */ +template +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) +{ + 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. Hence, you + * should generally check the type of e first. + * + * @param e expression + * @return reference to object of class T + * @see is_exactly_a() */ +template +inline const T &ex_to(const ex &e) +{ + GINAC_ASSERT(is_a(e)); + return static_cast(*e.bp); +} } // namespace GiNaC