]> www.ginac.de Git - ginac.git/blobdiff - ginac/ex.h
- Banned exZERO(), exONE(), exMINUSHALF() and all this from the interface.
[ginac.git] / ginac / ex.h
index a2517a50601a4ded86af1e6632f5aa55a4aa43a8..f8d2970c101aa0aee7c756abcc371a2676d75ff2 100644 (file)
@@ -27,7 +27,9 @@
 #include <ginac/basic.h>
 #include <ginac/operators.h>
 
+#ifndef NO_GINAC_NAMESPACE
 namespace GiNaC {
+#endif // ndef NO_GINAC_NAMESPACE
 
 class ex;
 class expand_options;
@@ -36,17 +38,9 @@ class status_flags;
 class symbol;
 class lst;
 
-typedef vector<ex> exvector;
+extern ex const & _ex0(void);  /* FIXME: should this pollute headers? */
 
-// enum definitions
-
-ex const & exZERO(void);
-ex const & exONE(void);
-ex const & exTWO(void);
-ex const & exTHREE(void);
-ex const & exMINUSONE(void);
-ex const & exHALF(void);
-ex const & exMINUSHALF(void);
+// typedef vector<ex> exvector;
 
 #define INLINE_EX_CONSTRUCTORS
 
@@ -63,12 +57,15 @@ class ex
 public:
     ex()
 #ifdef INLINE_EX_CONSTRUCTORS
-    : bp(exZERO().bp)
+    : bp(_ex0().bp)
         {
-            GINAC_ASSERT(exZERO().bp!=0);
-            GINAC_ASSERT(exZERO().bp->flags & status_flags::dynallocated);
+            GINAC_ASSERT(_ex0().bp!=0);
+            GINAC_ASSERT(_ex0().bp->flags & status_flags::dynallocated);
             GINAC_ASSERT(bp!=0);
             ++bp->refcount;
+#ifdef OBSCURE_CINT_HACK
+            update_last_created_or_assigned_bp();
+#endif // def OBSCURE_CINT_HACK
         }
 #else
 ;
@@ -94,6 +91,9 @@ public:
             GINAC_ASSERT(bp!=0);
             GINAC_ASSERT((bp->flags) & status_flags::dynallocated);
             ++bp->refcount;
+#ifdef OBSCURE_CINT_HACK
+            update_last_created_or_assigned_bp();
+#endif // def OBSCURE_CINT_HACK
         }
 #else
 ;
@@ -112,6 +112,9 @@ public:
                 delete bp;
             }
             bp=tmpbp;
+#ifdef OBSCURE_CINT_HACK
+            update_last_created_or_assigned_bp();
+#endif // def OBSCURE_CINT_HACK
             return *this;
         }
 #else
@@ -122,9 +125,12 @@ public:
 public:
     ex(basic const & other)
 #ifdef INLINE_EX_CONSTRUCTORS
-    {
-        construct_from_basic(other);
-    }
+        {
+            construct_from_basic(other);
+#ifdef OBSCURE_CINT_HACK
+            update_last_created_or_assigned_bp();
+#endif // def OBSCURE_CINT_HACK
+        }
 #else
 ;
 #endif // def INLINE_EX_CONSTRUCTORS
@@ -210,7 +216,7 @@ public:
 #else
 ;
 #endif // def INLINE_EX_CONSTRUCTORS
-    bool is_zero(void) const {return compare(exZERO()) == 0;};
+    bool is_zero(void) const {return compare(_ex0())==0;};
         
     unsigned return_type(void) const;
     unsigned return_type_tinfo(void) const;
@@ -223,10 +229,39 @@ private:
     void construct_from_basic(basic const & other);
     void makewriteable();
 
+#ifdef OBSCURE_CINT_HACK
+public:
+    static bool last_created_or_assigned_bp_can_be_converted_to_ex(void)
+        {
+            if (last_created_or_assigned_bp==0) return false;
+            if ((last_created_or_assigned_bp->flags &
+                 status_flags::dynallocated)==0) return false;
+            if ((last_created_or_assigned_bp->flags &
+                 status_flags::evaluated)==0) return false;
+            return true;
+        }
+protected:
+    void update_last_created_or_assigned_bp(void)
+        {
+            if (last_created_or_assigned_bp!=0) {
+                if (--last_created_or_assigned_bp->refcount == 0) {
+                    delete last_created_or_assigned_bp;
+                }
+            }
+            last_created_or_assigned_bp=bp;
+            ++last_created_or_assigned_bp->refcount;
+            last_created_or_assigned_bp_modified=true;
+        }
+#endif // def OBSCURE_CINT_HACK
+
 // member variables
 
 public:
     basic *bp;
+#ifdef OBSCURE_CINT_HACK
+    static basic *last_created_or_assigned_bp;
+    static bool last_created_or_assigned_bp_modified;
+#endif // def OBSCURE_CINT_HACK
 };
 
 // utility functions
@@ -284,6 +319,9 @@ inline ex subs(ex const & thisex, lst const & ls, lst const & lr)
 inline void swap(ex & e1, ex & e2)
 { e1.swap(e2); }
 
+#ifndef NO_GINAC_NAMESPACE
 } // namespace GiNaC
+#endif // ndef NO_GINAC_NAMESPACE
 
 #endif // ndef __GINAC_EX_H__
+