X-Git-Url: https://ginac.de/ginac.git//ginac.git?a=blobdiff_plain;f=ginac%2Fex.h;h=af5cac31d7cecc73b0f6012260a02dae3f8dbb96;hb=09f37bdbd46f469b3a8a902a43d0f795c41a89bf;hp=c76290ff1ceb0a04a2dbdc21597d1e49ecffa8ca;hpb=cfea748404dec5fb2f2e3310d36eeb6640f13824;p=ginac.git diff --git a/ginac/ex.h b/ginac/ex.h index c76290ff..af5cac31 100644 --- a/ginac/ex.h +++ b/ginac/ex.h @@ -3,7 +3,7 @@ * Interface to GiNaC's light-weight expression handles. */ /* - * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2002 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 @@ -23,11 +23,11 @@ #ifndef __GINAC_EX_H__ #define __GINAC_EX_H__ -#include "basic.h" -#include "operators.h" - +#include #include +#include "basic.h" + namespace GiNaC { /** Helper class to initialize the library. There must be one static object @@ -96,7 +96,19 @@ public: // non-virtual functions in this class public: - void swap(ex & other); + /** Efficiently swap the contents of two expressions. */ + void swap(ex & other) + { + GINAC_ASSERT(bp!=0); + GINAC_ASSERT(bp->flags & status_flags::dynallocated); + GINAC_ASSERT(other.bp!=0); + GINAC_ASSERT(other.bp->flags & status_flags::dynallocated); + + basic * tmpbp = bp; + bp = other.bp; + other.bp = tmpbp; + } + void print(const print_context & c, unsigned level = 0) const; void printtree(std::ostream & os) const; void dbgprint(void) const; @@ -195,9 +207,10 @@ protected: // member variables -public: - basic *bp; ///< pointer to basic object managed by this, direct manipulation deprecated +private: + basic *bp; ///< pointer to basic object managed by this #ifdef OBSCURE_CINT_HACK +public: static basic * last_created_or_assigned_bp; static basic * dummy_bp; static long last_created_or_assigned_exp; @@ -343,6 +356,11 @@ bool ex::is_equal(const ex & other) const // utility functions + +/** Compare two objects of class quickly without doing a deep tree traversal. + * @return "true" if they are equal + * "false" if equality cannot be established quickly (e1 and e2 may + * still be equal, in this case. */ inline bool are_ex_trivially_equal(const ex &e1, const ex &e2) { return e1.bp == e2.bp; @@ -451,6 +469,10 @@ inline bool is_zero(const ex & thisex) inline void swap(ex & e1, ex & e2) { e1.swap(e2); } +// This makes STL algorithms use the more efficient swap operation for ex objects +inline void iter_swap(std::vector::iterator i1, std::vector::iterator i2) +{ i1->swap(*i2); } + /* Function objects for STL sort() etc. */ struct ex_is_less : public std::binary_function {