# HG changeset patch # User Jaroslav Hajek # Date 1295518227 -3600 # Node ID a21a3875ca8305d6196e29cfd28a045e97dc6cab # Parent cd82f5933c7363216c6ea69ddd69344961ef857f implement a common class for reference counts diff -r cd82f5933c73 -r a21a3875ca83 liboctave/Array.h --- 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 count; ArrayRep (T *d, octave_idx_type l) : data (no_ctor_new (l)), len (l), count (1) diff -r cd82f5933c73 -r a21a3875ca83 liboctave/ChangeLog --- 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 + + * 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 * oct-fftw.h (class octave_fftw_planner): Disallow copying diff -r cd82f5933c73 -r a21a3875ca83 liboctave/Makefile.am --- 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 \ diff -r cd82f5933c73 -r a21a3875ca83 liboctave/Sparse.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 count; SparseRep (void) : d (0), r (0), c (new octave_idx_type [1]), nzmx (0), nrows (0), ncols (0), count (1) { c[0] = 0; } diff -r cd82f5933c73 -r a21a3875ca83 liboctave/SparseCmplxQR.h --- 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 count; octave_idx_type nrows; #ifdef HAVE_CXSPARSE diff -r cd82f5933c73 -r a21a3875ca83 liboctave/SparseQR.h --- 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 count; octave_idx_type nrows; #ifdef HAVE_CXSPARSE diff -r cd82f5933c73 -r a21a3875ca83 liboctave/idx-vector.h --- 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 Array; template class Sparse; @@ -102,7 +103,7 @@ virtual Array as_array (void); - int count; + octave_refcount count; bool err; diff -r cd82f5933c73 -r a21a3875ca83 liboctave/oct-refcount.h --- /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 +. + +*/ + +#if !defined (octave_refcount_h) +#define octave_refcount_h 1 + +// Encapsulates a reference counter. +template +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 diff -r cd82f5933c73 -r a21a3875ca83 liboctave/oct-shlib.h --- 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 #include "oct-time.h" +#include "oct-refcount.h" class OCTAVE_API @@ -85,7 +86,7 @@ public: - int count; + octave_refcount count; protected: diff -r cd82f5933c73 -r a21a3875ca83 liboctave/sparse-base-chol.h --- 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 count; private: cholmod_sparse *Lsparse; @@ -132,7 +132,7 @@ double rcond (void) const { return cond; } - int count; + octave_refcount count; private: bool is_pd; diff -r cd82f5933c73 -r a21a3875ca83 src/ChangeLog --- 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 + + * 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 * ov-mex-fcn.h, txt-eng-ft.cc, mex.cc: diff -r cd82f5933c73 -r a21a3875ca83 src/gl-render.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 count; }; texture_rep *rep; @@ -351,7 +351,7 @@ float specular_exp; // reference counter - int count; + octave_refcount count; vertex_data_rep (void) : coords (), color (), normal (), alpha (), diff -r cd82f5933c73 -r a21a3875ca83 src/oct-map.h --- 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 (other), count (1) { } - int count; + octave_refcount count; private: fields_rep& operator = (const fields_rep&); // no assignment! diff -r cd82f5933c73 -r a21a3875ca83 src/ov-base.h --- 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 count; private: diff -r cd82f5933c73 -r a21a3875ca83 src/pt-mat.cc --- 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 count; dim_vector dv;