00001 /*------------------------------------------------------------------------------ 00002 00003 Copyright (c) 2000 Tyrell Corporation. All rights reserved. 00004 00005 Tyrell DarkIce 00006 00007 File : Referable.h 00008 Version : $Revision: 1.2 $ 00009 Author : $Author: darkeye $ 00010 Location : $Source: /cvsroot/darkice/darkice/src/Referable.h,v $ 00011 00012 Copyright notice: 00013 00014 This program is free software; you can redistribute it and/or 00015 modify it under the terms of the GNU General Public License 00016 as published by the Free Software Foundation; either version 2 00017 of the License, or (at your option) any later version. 00018 00019 This program is distributed in the hope that it will be useful, 00020 but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 GNU General Public License for more details. 00023 00024 You should have received a copy of the GNU General Public License 00025 along with this program; if not, write to the Free Software 00026 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00027 00028 ------------------------------------------------------------------------------*/ 00029 #ifndef REFERABLE_H 00030 #define REFERABLE_H 00031 00032 #ifndef __cplusplus 00033 #error This is a C++ include file 00034 #endif 00035 00036 00037 /* ============================================================ include files */ 00038 00039 #include "Exception.h" 00040 00041 00042 /* ================================================================ constants */ 00043 00044 00045 /* =================================================================== macros */ 00046 00047 00048 /* =============================================================== data types */ 00049 00068 class Referable 00069 { 00070 private: 00071 00075 unsigned int referenceCount; 00076 00080 static const 00081 unsigned int maxCount = ~((unsigned int)0); 00082 00083 00084 protected: 00085 00089 inline 00090 Referable ( void ) throw () 00091 { 00092 referenceCount = 0; 00093 } 00094 00095 00101 inline virtual 00102 ~Referable ( void ) throw ( Exception ) 00103 { 00104 if ( referenceCount > 0 ) { 00105 throw Exception( __FILE__, __LINE__, 00106 "reference count positive in destructor", 00107 referenceCount); 00108 } 00109 } 00110 00111 00112 public: 00113 00120 inline unsigned int 00121 increaseReferenceCount ( void ) throw ( Exception ) 00122 { 00123 if ( referenceCount >= maxCount ) { 00124 throw Exception( __FILE__, 00125 __LINE__, 00126 "reference count overflow", 00127 referenceCount ); 00128 } 00129 return ++referenceCount; 00130 } 00131 00138 inline unsigned int 00139 decreaseReferenceCount ( void ) throw ( Exception ) 00140 { 00141 if ( referenceCount == 0 ) { 00142 throw Exception( __FILE__, __LINE__, 00143 "reference count underflow", 00144 referenceCount ); 00145 } 00146 return --referenceCount; 00147 } 00148 00154 inline unsigned int 00155 getReferenceCount ( void ) const throw () 00156 { 00157 return referenceCount; 00158 } 00159 }; 00160 00161 00162 /* ================================================= external data structures */ 00163 00164 00165 /* ====================================================== function prototypes */ 00166 00167 00168 00169 #endif /* REFERABLE_H */ 00170 00171 00172 /*------------------------------------------------------------------------------ 00173 00174 $Source: /cvsroot/darkice/darkice/src/Referable.h,v $ 00175 00176 $Log: Referable.h,v $ 00177 Revision 1.2 2000/11/11 12:33:13 darkeye 00178 added kdoc-style documentation 00179 00180 Revision 1.1.1.1 2000/11/05 10:05:54 darkeye 00181 initial version 00182 00183 00184 ------------------------------------------------------------------------------*/ 00185