Octave-Forge - Extra packages for GNU Octave | |
Home · Packages · Developers · Documentation · FAQ · Bugs · Mailing Lists · Links · Code |
00001 /* 00002 00003 Copyright (C) 2011 Jaroslav Hajek 00004 00005 This file is part of Octave. 00006 00007 Octave is free software; you can redistribute it and/or modify it 00008 under the terms of the GNU General Public License as published by the 00009 Free Software Foundation; either version 3 of the License, or (at your 00010 option) any later version. 00011 00012 Octave is distributed in the hope that it will be useful, but WITHOUT 00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00015 for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with Octave; see the file COPYING. If not, see 00019 <http://www.gnu.org/licenses/>. 00020 00021 */ 00022 00023 #if !defined (octave_refcount_h) 00024 #define octave_refcount_h 1 00025 00026 // Encapsulates a reference counter. 00027 template <class T> 00028 class octave_refcount 00029 { 00030 public: 00031 typedef T count_type; 00032 00033 octave_refcount(count_type initial_count) : count(initial_count) {} 00034 00035 // Increment/Decrement. int is postfix. 00036 count_type operator++(void) 00037 { 00038 return ++count; 00039 } 00040 00041 count_type operator++(int) 00042 { 00043 return count++; 00044 } 00045 00046 count_type operator--(void) 00047 { 00048 return --count; 00049 } 00050 00051 count_type operator--(int) 00052 { 00053 return count--; 00054 } 00055 00056 operator count_type (void) const { return count; } 00057 00058 // For low-level optimizations only. 00059 count_type& direct (void) const { return count; } 00060 00061 private: 00062 count_type count; 00063 }; 00064 00065 #endif