OFFIS DCMTK  Version 3.6.0
ofbmanip.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: Joerg Riesmeier
17  *
18  * Purpose: Template class for bit manipulations (Header)
19  *
20  * Last Update: $Author: joergr $
21  * Update Date: $Date: 2010-10-14 13:15:50 $
22  * CVS/RCS Revision: $Revision: 1.19 $
23  * Status: $State: Exp $
24  *
25  * CVS/RCS Log at end of file
26  *
27  */
28 
29 
30 #ifndef OFBMANIP_H
31 #define OFBMANIP_H
32 
33 #include "dcmtk/config/osconfig.h"
34 #include "dcmtk/ofstd/ofcast.h"
35 #include "dcmtk/ofstd/ofdefine.h"
36 
37 #define INCLUDE_CSTRING
38 #include "dcmtk/ofstd/ofstdinc.h"
39 
40 /*---------------------*
41  * class declaration *
42  *---------------------*/
43 
47 template<class T>
49 {
50 
51  public:
52 
61  static void copyMem(const T *src,
62  T *dest,
63  const unsigned long count)
64  {
65 #ifdef HAVE_MEMCPY
66  memcpy(OFstatic_cast(void *, dest), OFstatic_cast(const void *, src), OFstatic_cast(size_t, count) * sizeof(T));
67 #else
68  register unsigned long i;
69  register const T *p = src;
70  register T *q = dest;
71  for (i = count; i != 0; --i)
72  *q++ = *p++;
73 #endif
74  }
75 
76 
86  static void moveMem(const T *src,
87  T *dest,
88  unsigned long count)
89  {
90 #ifdef HAVE_MEMMOVE
91  memmove(OFstatic_cast(void *, dest), OFstatic_cast(const void *, src), OFstatic_cast(size_t, count) * sizeof(T));
92 #else
93  if (src == dest)
94  return;
95 
96  register unsigned long i;
97  register const T *p = src;
98  register T *q = dest;
99  if (src > dest)
100  {
101  // src is above dest in memory, we start copying from the start
102  for (i = count; i != 0; --i)
103  *q++ = *p++;
104  }
105  else
106  {
107  // src is below dest in memory, we start copying from the end
108  q += count - 1;
109  p += count - 1;
110  for (i = count; i != 0; --i)
111  *q-- = *p--;
112  }
113 #endif
114  }
115 
116 
123  static void setMem(T *dest,
124  const T value,
125  const unsigned long count)
126  {
127 #ifdef HAVE_MEMSET
128  if ((value == 0) || (sizeof(T) == sizeof(unsigned char)))
129  memset(OFstatic_cast(void *, dest), OFstatic_cast(int, value), OFstatic_cast(size_t, count) * sizeof(T));
130  else
131 #endif
132  {
133  register unsigned long i;
134  register T *q = dest;
135  for (i = count; i != 0; --i)
136  *q++ = value;
137  }
138  }
139 
140 
146  static void zeroMem(T *dest,
147  const unsigned long count)
148  {
149 #ifdef HAVE_MEMZERO
150  memzero(dest, OFstatic_cast(size_t, count) * sizeof(T));
151 #else
152  register unsigned long i;
153  register T *q = dest;
154  for (i = count; i != 0; --i)
155  *q++ = 0;
156 #endif
157  }
158 };
159 
160 
161 #endif
162 
163 
164 /*
165  *
166  * CVS/RCS Log:
167  * $Log: ofbmanip.h,v $
168  * Revision 1.19 2010-10-14 13:15:50 joergr
169  * Updated copyright header. Added reference to COPYRIGHT file.
170  *
171  * Revision 1.18 2009-09-28 12:19:37 joergr
172  * Simplified code based on the new header file "ofdefine.h".
173  *
174  * Revision 1.17 2009-09-25 09:42:52 joergr
175  * Introduced new general helper function moveMem() which allows for copying
176  * overlapping memory areas.
177  *
178  * Revision 1.16 2005-12-08 16:05:46 meichel
179  * Changed include path schema for all DCMTK header files
180  *
181  * Revision 1.15 2003/12/05 10:37:41 joergr
182  * Removed leading underscore characters from preprocessor symbols (reserved
183  * symbols). Updated copyright date where appropriate.
184  *
185  * Revision 1.14 2003/08/29 07:54:52 joergr
186  * Modified function zeroMem() to compile with MSVC again where bzero() is not
187  * available.
188  *
189  * Revision 1.13 2003/08/14 09:01:18 meichel
190  * Adapted type casts to new-style typecast operators defined in ofcast.h
191  *
192  * Revision 1.12 2002/11/27 11:23:04 meichel
193  * Adapted module ofstd to use of new header file ofstdinc.h
194  *
195  * Revision 1.11 2001/06/01 15:51:31 meichel
196  * Updated copyright header
197  *
198  * Revision 1.10 2000/03/08 16:36:00 meichel
199  * Updated copyright header.
200  *
201  * Revision 1.9 2000/02/02 10:56:25 joergr
202  * Removed space characters before preprocessor directives.
203  *
204  * Revision 1.8 1999/09/17 11:46:34 joergr
205  * Enhanced efficiency of "for" loops.
206  *
207  * Revision 1.7 1999/08/25 16:44:44 joergr
208  * Enhanced efficiency of inner loops (count loop variable down).
209  *
210  * Revision 1.6 1999/04/30 16:34:07 meichel
211  * Added provision for systems which have bzero() but no prototype, e.g. SunOS
212  *
213  * Revision 1.5 1999/04/29 16:49:22 meichel
214  * Changed first parameter in bzero() call to char *, required on OSF1.
215  *
216  * Revision 1.4 1999/04/26 16:07:52 joergr
217  * Changed comments.
218  *
219  * Revision 1.3 1998/12/16 15:59:51 joergr
220  * Corrected bug in setMem routine (expected 'value' parameter for system
221  * function 'memset' is implicitely casted to 'unsigned char').
222  *
223  * Revision 1.2 1998/12/02 12:52:05 joergr
224  * Corrected bug in setMem routine (parameter 'value' was ignored).
225  *
226  * Revision 1.1 1998/11/27 12:29:20 joergr
227  * First release of class for plaform independant memory operations.
228  *
229  *
230  */


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