OFFIS DCMTK  Version 3.6.0
ofglobal.h
1 /*
2  *
3  * Copyright (C) 1997-2010, OFFIS e.V.
4  * All rights reserved. See COPYRIGHT file for details.
5  *
6  * This software and supporting documentation were developed by
7  *
8  * OFFIS e.V.
9  * R&D Division Health
10  * Escherweg 2
11  * D-26121 Oldenburg, Germany
12  *
13  *
14  * Module: ofstd
15  *
16  * Author: Marco Eichelberg
17  *
18  * Purpose: OFGlobal is a template class intended for the declaration
19  * of global objects, access to which is protected by a Mutex
20  * for multi-thread applications.
21  * class T must have copy constructor and assignment operator.
22  *
23  *
24  * Last Update: $Author: joergr $
25  * Update Date: $Date: 2010-10-14 13:15:50 $
26  * CVS/RCS Revision: $Revision: 1.8 $
27  * Status: $State: Exp $
28  *
29  * CVS/RCS Log at end of file
30  *
31  */
32 
33 
34 #ifndef OFGLOBAL_H
35 #define OFGLOBAL_H
36 
37 #include "dcmtk/config/osconfig.h"
38 #include "dcmtk/ofstd/ofthread.h" /* for class OFBool */
39 
45 template <class T> class OFGlobal
46 {
47 public:
48 
52  OFGlobal(const T &arg)
53  : val(arg)
54 #ifdef WITH_THREADS
55  , theMutex()
56 #endif
57  {
58  }
59 
62  virtual ~OFGlobal() { }
63 
68  void set(const T& arg)
69  {
70 #ifdef WITH_THREADS
71  theMutex.lock();
72 #endif
73  val = arg;
74 #ifdef WITH_THREADS
75  theMutex.unlock();
76 #endif
77  }
78 
83  void xget(T& arg)
84  {
85 #ifdef WITH_THREADS
86  theMutex.lock();
87 #endif
88  arg = val;
89 #ifdef WITH_THREADS
90  theMutex.unlock();
91 #endif
92  }
93 
99  T get()
100  {
101 #ifdef WITH_THREADS
102  theMutex.lock();
103 #endif
104  T result(val);
105 #ifdef WITH_THREADS
106  theMutex.unlock();
107 #endif
108  return result;
109  }
110 
111 private:
112 
115  T val;
116 
117 #ifdef WITH_THREADS
118 
121  OFMutex theMutex;
122 #endif
123 
125  OFGlobal();
126 
128  OFGlobal(const OFGlobal<T>& arg);
129 
131  const OFGlobal<T>& operator=(const OFGlobal<T>& arg);
132 
133 };
134 
135 
136 #endif
137 
138 /*
139  *
140  * CVS/RCS Log:
141  * $Log: ofglobal.h,v $
142  * Revision 1.8 2010-10-14 13:15:50 joergr
143  * Updated copyright header. Added reference to COPYRIGHT file.
144  *
145  * Revision 1.7 2010-10-04 14:44:47 joergr
146  * Replaced "#ifdef _REENTRANT" by "#ifdef WITH_THREADS" where appropriate (i.e.
147  * in all cases where OFMutex, OFReadWriteLock, etc. are used).
148  *
149  * Revision 1.6 2005/12/08 16:05:57 meichel
150  * Changed include path schema for all DCMTK header files
151  *
152  * Revision 1.5 2003/12/05 10:37:41 joergr
153  * Removed leading underscore characters from preprocessor symbols (reserved
154  * symbols). Updated copyright date where appropriate.
155  *
156  * Revision 1.4 2001/06/01 15:51:34 meichel
157  * Updated copyright header
158  *
159  * Revision 1.3 2000/10/10 12:01:21 meichel
160  * Created/updated doc++ comments
161  *
162  * Revision 1.2 2000/05/30 17:03:38 meichel
163  * Added default constructor for Mutex to initializer list in OFGlobal.
164  *
165  * Revision 1.1 2000/04/14 15:17:48 meichel
166  * Created new templace class OFGlobal which allows to easily implement
167  * mutex protected global flags.
168  *
169  *
170  */


Generated on Thu Dec 20 2012 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.8.2