diobjcou.h

00001 /*
00002  *
00003  *  Copyright (C) 1996-2005, OFFIS
00004  *
00005  *  This software and supporting documentation were developed by
00006  *
00007  *    Kuratorium OFFIS e.V.
00008  *    Healthcare Information and Communication Systems
00009  *    Escherweg 2
00010  *    D-26121 Oldenburg, Germany
00011  *
00012  *  THIS SOFTWARE IS MADE AVAILABLE,  AS IS,  AND OFFIS MAKES NO  WARRANTY
00013  *  REGARDING  THE  SOFTWARE,  ITS  PERFORMANCE,  ITS  MERCHANTABILITY  OR
00014  *  FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES  OR
00015  *  ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND
00016  *  PERFORMANCE OF THE SOFTWARE IS WITH THE USER.
00017  *
00018  *  Module:  dcmimgle
00019  *
00020  *  Author:  Joerg Riesmeier
00021  *
00022  *  Purpose: DicomObjectCounter (Header)
00023  *
00024  *  Last Update:      $Author: meichel $
00025  *  Update Date:      $Date: 2005/12/08 16:47:59 $
00026  *  CVS/RCS Revision: $Revision: 1.11 $
00027  *  Status:           $State: Exp $
00028  *
00029  *  CVS/RCS Log at end of file
00030  *
00031  */
00032 
00033 
00034 #ifndef DIOBJCOU_H
00035 #define DIOBJCOU_H
00036 
00037 #include "dcmtk/config/osconfig.h"
00038 
00039 #include "dcmtk/ofstd/ofthread.h"
00040 
00041 
00042 /*---------------------*
00043  *  class declaration  *
00044  *---------------------*/
00045 
00049 class DiObjectCounter
00050 {
00051 
00052  public:
00053 
00057     inline void addReference()
00058     {
00059 #ifdef _REENTRANT
00060         theMutex.lock();
00061 #endif
00062         ++Counter;
00063 #ifdef _REENTRANT
00064         theMutex.unlock();
00065 #endif
00066     }
00067 
00071     inline void removeReference()
00072     {
00073 #ifdef _REENTRANT
00074         theMutex.lock();
00075 #endif
00076         if (--Counter == 0)
00077         {
00078 #ifdef _REENTRANT
00079             theMutex.unlock();
00080 #endif
00081             delete this;
00082 #ifdef _REENTRANT
00083         } else {
00084             theMutex.unlock();
00085 #endif
00086         }
00087     }
00088 
00089 
00090  protected:
00091 
00095     DiObjectCounter()
00096       : Counter(1)
00097 #ifdef _REENTRANT
00098        ,theMutex()
00099 #endif
00100     {
00101     }
00102 
00105     virtual ~DiObjectCounter()
00106     {
00107     }
00108 
00109 
00110  private:
00111 
00113     unsigned long Counter;
00114 
00115 #ifdef _REENTRANT
00116 
00119     OFMutex theMutex;
00120 #endif
00121 };
00122 
00123 
00124 #endif
00125 
00126 
00127 /*
00128  *
00129  * CVS/RCS Log:
00130  * $Log: diobjcou.h,v $
00131  * Revision 1.11  2005/12/08 16:47:59  meichel
00132  * Changed include path schema for all DCMTK header files
00133  *
00134  * Revision 1.10  2003/12/23 15:53:22  joergr
00135  * Replaced post-increment/decrement operators by pre-increment/decrement
00136  * operators where appropriate (e.g. 'i++' by '++i').
00137  *
00138  * Revision 1.9  2003/12/08 19:30:16  joergr
00139  * Removed leading underscore characters from preprocessor symbols (reserved
00140  * symbols). Updated copyright header.
00141  *
00142  * Revision 1.8  2001/06/01 15:49:48  meichel
00143  * Updated copyright header
00144  *
00145  * Revision 1.7  2000/07/12 12:47:47  joergr
00146  * Correct bug in destructor of ObjectCounter class.
00147  *
00148  * Revision 1.6  2000/05/25 10:35:23  joergr
00149  * Added member variable to member initialization list (avoid compiler
00150  * warnings).
00151  *
00152  * Revision 1.5  2000/04/28 12:30:51  joergr
00153  * ObjectCounter uses now class OFMutex to be MT-safe.
00154  *
00155  * Revision 1.4  2000/03/08 16:24:21  meichel
00156  * Updated copyright header.
00157  *
00158  * Revision 1.3  1999/09/17 12:44:08  joergr
00159  * Added/changed/completed DOC++ style comments in the header files.
00160  *
00161  * Revision 1.2  1999/03/24 17:20:18  joergr
00162  * Added/Modified comments and formatting.
00163  *
00164  * Revision 1.1  1998/11/27 15:40:30  joergr
00165  * Added copyright message.
00166  *
00167  * Revision 1.3  1998/05/11 14:53:24  joergr
00168  * Added CVS/RCS header to each file.
00169  *
00170  *
00171  */


Generated on 20 Dec 2005 for OFFIS DCMTK Version 3.5.4 by Doxygen 1.4.5