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: Joerg Riesmeier 00021 * 00022 * Purpose: Template class for bit manipulations (Header) 00023 * 00024 * Last Update: $Author: meichel $ 00025 * Update Date: $Date: 2005/12/08 16:05:46 $ 00026 * CVS/RCS Revision: $Revision: 1.16 $ 00027 * Status: $State: Exp $ 00028 * 00029 * CVS/RCS Log at end of file 00030 * 00031 */ 00032 00033 00034 #ifndef OFBMANIP_H 00035 #define OFBMANIP_H 00036 00037 #include "dcmtk/config/osconfig.h" 00038 #include "dcmtk/ofstd/ofcast.h" 00039 00040 #define INCLUDE_CSTRING 00041 #include "dcmtk/ofstd/ofstdinc.h" 00042 00043 00044 #ifdef HAVE_BZERO 00045 #ifndef HAVE_PROTOTYPE_BZERO 00046 BEGIN_EXTERN_C 00047 extern void bzero(char* s, int len); 00048 END_EXTERN_C 00049 #endif 00050 #endif 00051 00052 00053 /*---------------------* 00054 * class declaration * 00055 *---------------------*/ 00056 00060 template<class T> 00061 class OFBitmanipTemplate 00062 { 00063 00064 public: 00065 00072 static void copyMem(const T *src, 00073 T *dest, 00074 const unsigned long count) 00075 { 00076 #ifdef HAVE_MEMCPY 00077 memcpy(OFstatic_cast(void *, dest), OFstatic_cast(const void *, src), OFstatic_cast(size_t, count) * sizeof(T)); 00078 #elif HAVE_BCOPY 00079 bcopy(OFstatic_cast(const void *, src), OFstatic_cast(void *, dest), OFstatic_cast(size_t, count) * sizeof(T)); 00080 #else 00081 register unsigned long i; 00082 register const T *p = src; 00083 register T *q = dest; 00084 for (i = count; i != 0; --i) 00085 *q++ = *p++; 00086 #endif 00087 } 00088 00089 00096 static void setMem(T *dest, 00097 const T value, 00098 const unsigned long count) 00099 { 00100 #ifdef HAVE_MEMSET 00101 if ((value == 0) || (sizeof(T) == sizeof(unsigned char))) 00102 memset(OFstatic_cast(void *, dest), OFstatic_cast(int, value), OFstatic_cast(size_t, count) * sizeof(T)); 00103 else 00104 #endif 00105 { 00106 register unsigned long i; 00107 register T *q = dest; 00108 for (i = count; i != 0; --i) 00109 *q++ = value; 00110 } 00111 } 00112 00113 00119 static void zeroMem(T *dest, 00120 const unsigned long count) 00121 { 00122 #ifdef HAVE_BZERO 00123 // some platforms, e.g. OSF1, require the first parameter to be char *. 00124 bzero(OFreinterpret_cast(char *, dest), OFstatic_cast(size_t, count) * sizeof(T)); 00125 #else 00126 #ifdef HAVE_MEMSET 00127 memset(OFstatic_cast(void *, dest), 0, OFstatic_cast(size_t, count) * sizeof(T)); 00128 #else 00129 register unsigned long i; 00130 register T *q = dest; 00131 for (i = count; i != 0; --i) 00132 *q++ = 0; 00133 #endif 00134 #endif 00135 } 00136 }; 00137 00138 00139 #endif 00140 00141 00142 /* 00143 * 00144 * CVS/RCS Log: 00145 * $Log: ofbmanip.h,v $ 00146 * Revision 1.16 2005/12/08 16:05:46 meichel 00147 * Changed include path schema for all DCMTK header files 00148 * 00149 * Revision 1.15 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.14 2003/08/29 07:54:52 joergr 00154 * Modified function zeroMem() to compile with MSVC again where bzero() is not 00155 * available. 00156 * 00157 * Revision 1.13 2003/08/14 09:01:18 meichel 00158 * Adapted type casts to new-style typecast operators defined in ofcast.h 00159 * 00160 * Revision 1.12 2002/11/27 11:23:04 meichel 00161 * Adapted module ofstd to use of new header file ofstdinc.h 00162 * 00163 * Revision 1.11 2001/06/01 15:51:31 meichel 00164 * Updated copyright header 00165 * 00166 * Revision 1.10 2000/03/08 16:36:00 meichel 00167 * Updated copyright header. 00168 * 00169 * Revision 1.9 2000/02/02 10:56:25 joergr 00170 * Removed space characters before preprocessor directives. 00171 * 00172 * Revision 1.8 1999/09/17 11:46:34 joergr 00173 * Enhanced efficiency of "for" loops. 00174 * 00175 * Revision 1.7 1999/08/25 16:44:44 joergr 00176 * Enhanced efficiency of inner loops (count loop variable down). 00177 * 00178 * Revision 1.6 1999/04/30 16:34:07 meichel 00179 * Added provision for systems which have bzero() but no prototype, e.g. SunOS 00180 * 00181 * Revision 1.5 1999/04/29 16:49:22 meichel 00182 * Changed first parameter in bzero() call to char *, required on OSF1. 00183 * 00184 * Revision 1.4 1999/04/26 16:07:52 joergr 00185 * Changed comments. 00186 * 00187 * Revision 1.3 1998/12/16 15:59:51 joergr 00188 * Corrected bug in setMem routine (expected 'value' parameter for system 00189 * function 'memset' is implicitely casted to 'unsigned char'). 00190 * 00191 * Revision 1.2 1998/12/02 12:52:05 joergr 00192 * Corrected bug in setMem routine (parameter 'value' was ignored). 00193 * 00194 * Revision 1.1 1998/11/27 12:29:20 joergr 00195 * First release of class for plaform independant memory operations. 00196 * 00197 * 00198 */