]> www.ginac.de Git - ginac.git/blobdiff - ginac/ex.h
* Include the operators.h header file in the source files, not in ex.h.
[ginac.git] / ginac / ex.h
index e819d13f10544eb8f34e44bf370c3b2995299399..af5cac31d7cecc73b0f6012260a02dae3f8dbb96 100644 (file)
@@ -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
@@ -27,7 +27,6 @@
 #include <functional>
 
 #include "basic.h"
-#include "operators.h"
 
 namespace GiNaC {
 
@@ -97,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;
@@ -196,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;
@@ -457,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<ex>::iterator i1, std::vector<ex>::iterator i2)
+{ i1->swap(*i2); }
+
 
 /* Function objects for STL sort() etc. */
 struct ex_is_less : public std::binary_function<ex, ex, bool> {