00001 /* 00002 * 00003 * Copyright (C) 1996-2010, OFFIS e.V. 00004 * All rights reserved. See COPYRIGHT file for details. 00005 * 00006 * This software and supporting documentation were developed by 00007 * 00008 * OFFIS e.V. 00009 * R&D Division Health 00010 * Escherweg 2 00011 * D-26121 Oldenburg, Germany 00012 * 00013 * 00014 * Module: dcmimgle 00015 * 00016 * Author: Joerg Riesmeier 00017 * 00018 * Purpose: DicomObjectCounter (Header) 00019 * 00020 * Last Update: $Author: joergr $ 00021 * Update Date: $Date: 2010-10-14 13:16:26 $ 00022 * CVS/RCS Revision: $Revision: 1.14 $ 00023 * Status: $State: Exp $ 00024 * 00025 * CVS/RCS Log at end of file 00026 * 00027 */ 00028 00029 00030 #ifndef DIOBJCOU_H 00031 #define DIOBJCOU_H 00032 00033 #include "dcmtk/config/osconfig.h" 00034 00035 #ifdef WITH_THREADS 00036 #include "dcmtk/ofstd/ofthread.h" 00037 #endif 00038 00039 00040 /*---------------------* 00041 * class declaration * 00042 *---------------------*/ 00043 00047 class DiObjectCounter 00048 { 00049 00050 public: 00051 00055 inline void addReference() 00056 { 00057 #ifdef WITH_THREADS 00058 theMutex.lock(); 00059 #endif 00060 ++Counter; 00061 #ifdef WITH_THREADS 00062 theMutex.unlock(); 00063 #endif 00064 } 00065 00069 inline void removeReference() 00070 { 00071 #ifdef WITH_THREADS 00072 theMutex.lock(); 00073 #endif 00074 if (--Counter == 0) 00075 { 00076 #ifdef WITH_THREADS 00077 theMutex.unlock(); 00078 #endif 00079 delete this; 00080 #ifdef WITH_THREADS 00081 } else { 00082 theMutex.unlock(); 00083 #endif 00084 } 00085 } 00086 00087 00088 protected: 00089 00093 DiObjectCounter() 00094 : Counter(1) 00095 #ifdef WITH_THREADS 00096 ,theMutex() 00097 #endif 00098 { 00099 } 00100 00103 virtual ~DiObjectCounter() 00104 { 00105 } 00106 00107 00108 private: 00109 00111 unsigned long Counter; 00112 00113 #ifdef WITH_THREADS 00114 00117 OFMutex theMutex; 00118 #endif 00119 }; 00120 00121 00122 #endif 00123 00124 00125 /* 00126 * 00127 * CVS/RCS Log: 00128 * $Log: diobjcou.h,v $ 00129 * Revision 1.14 2010-10-14 13:16:26 joergr 00130 * Updated copyright header. Added reference to COPYRIGHT file. 00131 * 00132 * Revision 1.13 2010-10-04 14:44:45 joergr 00133 * Replaced "#ifdef _REENTRANT" by "#ifdef WITH_THREADS" where appropriate (i.e. 00134 * in all cases where OFMutex, OFReadWriteLock, etc. are used). 00135 * 00136 * Revision 1.12 2010-03-01 09:08:47 uli 00137 * Removed some unnecessary include directives in the headers. 00138 * 00139 * Revision 1.11 2005-12-08 16:47:59 meichel 00140 * Changed include path schema for all DCMTK header files 00141 * 00142 * Revision 1.10 2003/12/23 15:53:22 joergr 00143 * Replaced post-increment/decrement operators by pre-increment/decrement 00144 * operators where appropriate (e.g. 'i++' by '++i'). 00145 * 00146 * Revision 1.9 2003/12/08 19:30:16 joergr 00147 * Removed leading underscore characters from preprocessor symbols (reserved 00148 * symbols). Updated copyright header. 00149 * 00150 * Revision 1.8 2001/06/01 15:49:48 meichel 00151 * Updated copyright header 00152 * 00153 * Revision 1.7 2000/07/12 12:47:47 joergr 00154 * Correct bug in destructor of ObjectCounter class. 00155 * 00156 * Revision 1.6 2000/05/25 10:35:23 joergr 00157 * Added member variable to member initialization list (avoid compiler 00158 * warnings). 00159 * 00160 * Revision 1.5 2000/04/28 12:30:51 joergr 00161 * ObjectCounter uses now class OFMutex to be MT-safe. 00162 * 00163 * Revision 1.4 2000/03/08 16:24:21 meichel 00164 * Updated copyright header. 00165 * 00166 * Revision 1.3 1999/09/17 12:44:08 joergr 00167 * Added/changed/completed DOC++ style comments in the header files. 00168 * 00169 * Revision 1.2 1999/03/24 17:20:18 joergr 00170 * Added/Modified comments and formatting. 00171 * 00172 * Revision 1.1 1998/11/27 15:40:30 joergr 00173 * Added copyright message. 00174 * 00175 * Revision 1.3 1998/05/11 14:53:24 joergr 00176 * Added CVS/RCS header to each file. 00177 * 00178 * 00179 */