changeset 12125:a21a3875ca83

implement a common class for reference counts
author Jaroslav Hajek <highegg@gmail.com>
date Thu, 20 Jan 2011 11:10:27 +0100
parents cd82f5933c73
children 85f9a5b211fd
files liboctave/Array.h liboctave/ChangeLog liboctave/Makefile.am liboctave/Sparse.h liboctave/SparseCmplxQR.h liboctave/SparseQR.h liboctave/idx-vector.h liboctave/oct-refcount.h liboctave/oct-shlib.h liboctave/sparse-base-chol.h src/ChangeLog src/gl-render.cc src/oct-map.h src/ov-base.h src/pt-mat.cc
diffstat 15 files changed, 102 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/Array.h	Sat Jan 22 03:18:31 2011 -0500
+++ b/liboctave/Array.h	Thu Jan 20 11:10:27 2011 +0100
@@ -39,6 +39,7 @@
 #include "oct-sort.h"
 #include "quit.h"
 #include "oct-mem.h"
+#include "oct-refcount.h"
 
 // One dimensional array class.  Handles the reference counting for
 // all the derived classes.
@@ -59,7 +60,7 @@
 
     T *data;
     octave_idx_type len;
-    int count;
+    octave_refcount<int> count;
 
     ArrayRep (T *d, octave_idx_type l)
       : data (no_ctor_new<T> (l)), len (l), count (1)
--- a/liboctave/ChangeLog	Sat Jan 22 03:18:31 2011 -0500
+++ b/liboctave/ChangeLog	Thu Jan 20 11:10:27 2011 +0100
@@ -1,3 +1,16 @@
+2011-01-22  Jaroslav Hajek  <highegg@gmail.com>
+
+	* oct-refcount.h: New source.
+	* Makefile.am: Add it here.
+
+	* Array.h: Use octave_refcount for refcounting.
+	* Sparse.h: Ditto.
+	* SparseCmplxQR.h: Ditto.
+	* SparseQR.h: Ditto.
+	* idx-vector.h: Ditto.
+	* oct-shlib.h: Ditto.
+	* sparse-base-chol.h: Ditto.
+
 2011-01-21  Pascal Dupuis <Pascal.Dupuis@worldonline.be>
 
 	* oct-fftw.h (class octave_fftw_planner): Disallow copying
--- a/liboctave/Makefile.am	Sat Jan 22 03:18:31 2011 -0500
+++ b/liboctave/Makefile.am	Thu Jan 20 11:10:27 2011 +0100
@@ -228,6 +228,7 @@
   oct-openmp.h \
   oct-passwd.h \
   oct-rand.h \
+  oct-refcount.h \
   oct-rl-edit.h \
   oct-rl-hist.h \
   oct-shlib.h \
--- a/liboctave/Sparse.h	Sat Jan 22 03:18:31 2011 -0500
+++ b/liboctave/Sparse.h	Thu Jan 20 11:10:27 2011 +0100
@@ -68,7 +68,7 @@
     octave_idx_type nzmx;
     octave_idx_type nrows;
     octave_idx_type ncols;
-    int count;
+    octave_refcount<int> count;
 
     SparseRep (void) : d (0), r (0), c (new octave_idx_type [1]), nzmx (0), nrows (0),
                        ncols (0), count (1) { c[0] = 0; }
--- a/liboctave/SparseCmplxQR.h	Sat Jan 22 03:18:31 2011 -0500
+++ b/liboctave/SparseCmplxQR.h	Thu Jan 20 11:10:27 2011 +0100
@@ -65,7 +65,7 @@
 
     ComplexMatrix Q (void) const;
 
-    int count;
+    octave_refcount<int> count;
 
     octave_idx_type nrows;
 #ifdef HAVE_CXSPARSE
--- a/liboctave/SparseQR.h	Sat Jan 22 03:18:31 2011 -0500
+++ b/liboctave/SparseQR.h	Thu Jan 20 11:10:27 2011 +0100
@@ -65,7 +65,7 @@
 
     Matrix Q (void) const;
 
-    int count;
+    octave_refcount<int> count;
 
     octave_idx_type nrows;
 #ifdef HAVE_CXSPARSE
--- a/liboctave/idx-vector.h	Sat Jan 22 03:18:31 2011 -0500
+++ b/liboctave/idx-vector.h	Thu Jan 20 11:10:27 2011 +0100
@@ -34,6 +34,7 @@
 #include "oct-inttypes.h"
 #include "oct-alloc.h"
 #include "oct-mem.h"
+#include "oct-refcount.h"
 
 template<class T> class Array;
 template<class T> class Sparse;
@@ -102,7 +103,7 @@
 
     virtual Array<octave_idx_type> as_array (void);
 
-    int count;
+    octave_refcount<int> count;
 
     bool err;
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/liboctave/oct-refcount.h	Thu Jan 20 11:10:27 2011 +0100
@@ -0,0 +1,65 @@
+/*
+
+Copyright (C) 2011 Jaroslav Hajek
+
+This file is part of Octave.
+
+Octave is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+Octave is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Octave; see the file COPYING.  If not, see
+<http://www.gnu.org/licenses/>.
+
+*/
+
+#if !defined (octave_refcount_h)
+#define octave_refcount_h 1
+
+// Encapsulates a reference counter.
+template <class T>
+class octave_refcount
+{
+public:
+  typedef T count_type;
+
+  octave_refcount(count_type initial_count) : count(initial_count) {}
+
+  // Increment/Decrement. int is postfix.
+  count_type operator++(void) 
+    { 
+      return ++count; 
+    }
+
+  count_type operator++(int) 
+    { 
+      return count++; 
+    }
+
+  count_type operator--(void)
+    { 
+      return --count; 
+    }
+
+  count_type operator--(int)
+    { 
+      return count--; 
+    }
+
+  operator count_type (void) const { return count; }
+
+  // For low-level optimizations only.
+  count_type& direct (void) const { return count; }
+
+private:
+  count_type count;
+};
+
+#endif
--- a/liboctave/oct-shlib.h	Sat Jan 22 03:18:31 2011 -0500
+++ b/liboctave/oct-shlib.h	Thu Jan 20 11:10:27 2011 +0100
@@ -28,6 +28,7 @@
 #include <map>
 
 #include "oct-time.h"
+#include "oct-refcount.h"
 
 class
 OCTAVE_API
@@ -85,7 +86,7 @@
 
   public:
 
-    int count;
+    octave_refcount<int> count;
 
   protected:
 
--- a/liboctave/sparse-base-chol.h	Sat Jan 22 03:18:31 2011 -0500
+++ b/liboctave/sparse-base-chol.h	Thu Jan 20 11:10:27 2011 +0100
@@ -78,7 +78,7 @@
 
     double rcond (void) const { return cond; }
 
-    int count;
+    octave_refcount<int> count;
 
   private:
     cholmod_sparse *Lsparse;
@@ -132,7 +132,7 @@
 
     double rcond (void) const { return cond; }
 
-    int count;
+    octave_refcount<int> count;
 
   private:
     bool is_pd;
--- a/src/ChangeLog	Sat Jan 22 03:18:31 2011 -0500
+++ b/src/ChangeLog	Thu Jan 20 11:10:27 2011 +0100
@@ -1,3 +1,10 @@
+2011-01-22  Jaroslav Hajek  <highegg@gmail.com>
+
+	* gl-render.cc: Use octave_refcount for refcounting.
+	* oct-map.h: Ditto.
+	* ov-base.h: Ditto.
+	* pt-mat.cc: Ditto.
+
 2011-01-22  Pascal Dupuis <Pascal.Dupuis@worldonline.be>
 
 	* ov-mex-fcn.h, txt-eng-ft.cc, mex.cc:
--- a/src/gl-render.cc	Sat Jan 22 03:18:31 2011 -0500
+++ b/src/gl-render.cc	Thu Jan 20 11:10:27 2011 +0100
@@ -90,7 +90,7 @@
     int tw, th;
     double tx, ty;
     bool valid;
-    int count;
+    octave_refcount<int> count;
   };
 
   texture_rep *rep;
@@ -351,7 +351,7 @@
     float specular_exp;
 
     // reference counter
-    int count;
+    octave_refcount<int> count;
 
     vertex_data_rep (void)
       : coords (), color (), normal (), alpha (),
--- a/src/oct-map.h	Sat Jan 22 03:18:31 2011 -0500
+++ b/src/oct-map.h	Thu Jan 20 11:10:27 2011 +0100
@@ -43,7 +43,7 @@
     fields_rep (const fields_rep& other)
       : std::map<std::string, octave_idx_type> (other), count (1) { }
 
-    int count;
+    octave_refcount<int> count;
 
   private:
     fields_rep& operator = (const fields_rep&); // no assignment!
--- a/src/ov-base.h	Sat Jan 22 03:18:31 2011 -0500
+++ b/src/ov-base.h	Thu Jan 20 11:10:27 2011 +0100
@@ -776,7 +776,7 @@
   // NOTE: the declaration is octave_idx_type because with 64-bit indexing,
   // it is well possible to have more than MAX_INT copies of a single value
   // (think of an empty cell array with >2G elements).
-  octave_idx_type count;
+  octave_refcount<octave_idx_type> count;
 
 private:
 
--- a/src/pt-mat.cc	Sat Jan 22 03:18:31 2011 -0500
+++ b/src/pt-mat.cc	Thu Jan 20 11:10:27 2011 +0100
@@ -81,7 +81,7 @@
 
     ~tm_row_const_rep (void) { }
 
-    int count;
+    octave_refcount<int> count;
 
     dim_vector dv;