ofglobal.h

00001 /*
00002  *
00003  *  Copyright (C) 1997-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:  ofstd
00019  *
00020  *  Author:  Marco Eichelberg
00021  *
00022  *  Purpose: OFGlobal is a template class intended for the declaration
00023  *           of global objects, access to which is protected by a Mutex
00024  *           for multi-thread applications.
00025  *           class T must have copy constructor and assignment operator.
00026  *
00027  *
00028  *  Last Update:      $Author: meichel $
00029  *  Update Date:      $Date: 2005/12/08 16:05:57 $
00030  *  CVS/RCS Revision: $Revision: 1.6 $
00031  *  Status:           $State: Exp $
00032  *
00033  *  CVS/RCS Log at end of file
00034  *
00035  */
00036 
00037 
00038 #ifndef OFGLOBAL_H
00039 #define OFGLOBAL_H
00040 
00041 #include "dcmtk/config/osconfig.h"
00042 #include "dcmtk/ofstd/ofthread.h"  /* for class OFBool */
00043 
00049 template <class T> class OFGlobal
00050 {
00051 public:
00052 
00056   OFGlobal(const T &arg)
00057   : val(arg)
00058 #ifdef _REENTRANT
00059   , theMutex()
00060 #endif
00061   {
00062   }
00063 
00066   virtual ~OFGlobal() { }
00067 
00072   void set(const T& arg)
00073   {
00074 #ifdef _REENTRANT
00075     theMutex.lock();
00076 #endif
00077     val = arg;
00078 #ifdef _REENTRANT
00079     theMutex.unlock();
00080 #endif
00081   }
00082 
00087   void xget(T& arg)
00088   {
00089 #ifdef _REENTRANT
00090     theMutex.lock();
00091 #endif
00092     arg = val;
00093 #ifdef _REENTRANT
00094     theMutex.unlock();
00095 #endif
00096   }
00097 
00103   T get()
00104   {
00105 #ifdef _REENTRANT
00106     theMutex.lock();
00107 #endif
00108     T result(val);
00109 #ifdef _REENTRANT
00110     theMutex.unlock();
00111 #endif
00112     return result;
00113   }
00114 
00115 private:
00116 
00119   T val;
00120 
00121 #ifdef _REENTRANT
00122 
00125   OFMutex theMutex;
00126 #endif
00127 
00129   OFGlobal();
00130 
00132   OFGlobal(const OFGlobal<T>& arg);
00133 
00135   const OFGlobal<T>& operator=(const OFGlobal<T>& arg);
00136 
00137 };
00138 
00139 
00140 #endif
00141 
00142 /*
00143  *
00144  * CVS/RCS Log:
00145  * $Log: ofglobal.h,v $
00146  * Revision 1.6  2005/12/08 16:05:57  meichel
00147  * Changed include path schema for all DCMTK header files
00148  *
00149  * Revision 1.5  2003/12/05 10:37:41  joergr
00150  * Removed leading underscore characters from preprocessor symbols (reserved
00151  * symbols). Updated copyright date where appropriate.
00152  *
00153  * Revision 1.4  2001/06/01 15:51:34  meichel
00154  * Updated copyright header
00155  *
00156  * Revision 1.3  2000/10/10 12:01:21  meichel
00157  * Created/updated doc++ comments
00158  *
00159  * Revision 1.2  2000/05/30 17:03:38  meichel
00160  * Added default constructor for Mutex to initializer list in OFGlobal.
00161  *
00162  * Revision 1.1  2000/04/14 15:17:48  meichel
00163  * Created new templace class OFGlobal which allows to easily implement
00164  *   mutex protected global flags.
00165  *
00166  *
00167  */


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