Mercurial > hg > octave-terminal
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 +++ b/liboctave/Array.h @@ -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 +++ b/liboctave/ChangeLog @@ -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 +++ b/liboctave/Makefile.am @@ -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 +++ b/liboctave/Sparse.h @@ -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 +++ b/liboctave/SparseCmplxQR.h @@ -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 +++ b/liboctave/SparseQR.h @@ -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 +++ b/liboctave/idx-vector.h @@ -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;
new file mode 100644 --- /dev/null +++ b/liboctave/oct-refcount.h @@ -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 +++ b/liboctave/oct-shlib.h @@ -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 +++ b/liboctave/sparse-base-chol.h @@ -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 +++ b/src/ChangeLog @@ -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 +++ b/src/gl-render.cc @@ -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 +++ b/src/oct-map.h @@ -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 +++ b/src/ov-base.h @@ -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: