* 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
#ifndef __GINAC_EX_H__
#define __GINAC_EX_H__
-#include "basic.h"
-#include "operators.h"
-
+#include <iosfwd>
#include <functional>
+#include "basic.h"
+
namespace GiNaC {
/** Helper class to initialize the library. There must be one static object
// 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;
// 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;
// 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;
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> {