annotate liboctave/oct-refcount.h @ 12312:b10ea6efdc58 release-3-4-x ss-3-3-91

version is now 3.3.91
author John W. Eaton <jwe@octave.org>
date Mon, 31 Jan 2011 08:36:58 -0500
parents 23385f2c90b7
children 43cc49c7abd1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12125
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
1 /*
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
2
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
3 Copyright (C) 2011 Jaroslav Hajek
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
4
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
5 This file is part of Octave.
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
6
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
10 option) any later version.
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
11
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
15 for more details.
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
16
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, see
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>.
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
20
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
21 */
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
22
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
23 #if !defined (octave_refcount_h)
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
24 #define octave_refcount_h 1
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
25
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
26 // Encapsulates a reference counter.
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
27 template <class T>
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
28 class octave_refcount
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
29 {
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
30 public:
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
31 typedef T count_type;
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
32
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
33 octave_refcount(count_type initial_count) : count(initial_count) {}
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
34
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
35 // Increment/Decrement. int is postfix.
12254
23385f2c90b7 whitespace fixes
John W. Eaton <jwe@octave.org>
parents: 12125
diff changeset
36 count_type operator++(void)
23385f2c90b7 whitespace fixes
John W. Eaton <jwe@octave.org>
parents: 12125
diff changeset
37 {
23385f2c90b7 whitespace fixes
John W. Eaton <jwe@octave.org>
parents: 12125
diff changeset
38 return ++count;
12125
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
39 }
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
40
12254
23385f2c90b7 whitespace fixes
John W. Eaton <jwe@octave.org>
parents: 12125
diff changeset
41 count_type operator++(int)
23385f2c90b7 whitespace fixes
John W. Eaton <jwe@octave.org>
parents: 12125
diff changeset
42 {
23385f2c90b7 whitespace fixes
John W. Eaton <jwe@octave.org>
parents: 12125
diff changeset
43 return count++;
12125
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
44 }
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
45
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
46 count_type operator--(void)
12254
23385f2c90b7 whitespace fixes
John W. Eaton <jwe@octave.org>
parents: 12125
diff changeset
47 {
23385f2c90b7 whitespace fixes
John W. Eaton <jwe@octave.org>
parents: 12125
diff changeset
48 return --count;
12125
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
49 }
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
50
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
51 count_type operator--(int)
12254
23385f2c90b7 whitespace fixes
John W. Eaton <jwe@octave.org>
parents: 12125
diff changeset
52 {
23385f2c90b7 whitespace fixes
John W. Eaton <jwe@octave.org>
parents: 12125
diff changeset
53 return count--;
12125
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
54 }
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
55
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
56 operator count_type (void) const { return count; }
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
57
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
58 // For low-level optimizations only.
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
59 count_type& direct (void) const { return count; }
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
60
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
61 private:
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
62 count_type count;
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
63 };
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
64
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
65 #endif