ofstd/include/dcmtk/ofstd/ofbmanip.h

00001 /*
00002  *
00003  *  Copyright (C) 1997-2010, OFFIS e.V.
00004  *  All rights reserved.  See COPYRIGHT file for details.
00005  *
00006  *  This software and supporting documentation were developed by
00007  *
00008  *    OFFIS e.V.
00009  *    R&D Division Health
00010  *    Escherweg 2
00011  *    D-26121 Oldenburg, Germany
00012  *
00013  *
00014  *  Module:  ofstd
00015  *
00016  *  Author:  Joerg Riesmeier
00017  *
00018  *  Purpose: Template class for bit manipulations (Header)
00019  *
00020  *  Last Update:      $Author: joergr $
00021  *  Update Date:      $Date: 2010-10-14 13:15:50 $
00022  *  CVS/RCS Revision: $Revision: 1.19 $
00023  *  Status:           $State: Exp $
00024  *
00025  *  CVS/RCS Log at end of file
00026  *
00027  */
00028 
00029 
00030 #ifndef OFBMANIP_H
00031 #define OFBMANIP_H
00032 
00033 #include "dcmtk/config/osconfig.h"
00034 #include "dcmtk/ofstd/ofcast.h"
00035 #include "dcmtk/ofstd/ofdefine.h"
00036 
00037 #define INCLUDE_CSTRING
00038 #include "dcmtk/ofstd/ofstdinc.h"
00039 
00040 /*---------------------*
00041  *  class declaration  *
00042  *---------------------*/
00043 
00047 template<class T>
00048 class OFBitmanipTemplate
00049 {
00050 
00051  public:
00052 
00061     static void copyMem(const T *src,
00062                         T *dest,
00063                         const unsigned long count)
00064     {
00065 #ifdef HAVE_MEMCPY
00066         memcpy(OFstatic_cast(void *, dest), OFstatic_cast(const void *, src), OFstatic_cast(size_t, count) * sizeof(T));
00067 #else
00068         register unsigned long i;
00069         register const T *p = src;
00070         register T *q = dest;
00071         for (i = count; i != 0; --i)
00072             *q++ = *p++;
00073 #endif
00074     }
00075 
00076 
00086     static void moveMem(const T *src,
00087                         T *dest,
00088                         unsigned long count)
00089     {
00090 #ifdef HAVE_MEMMOVE
00091         memmove(OFstatic_cast(void *, dest), OFstatic_cast(const void *, src), OFstatic_cast(size_t, count) * sizeof(T));
00092 #else
00093         if (src == dest)
00094             return;
00095 
00096         register unsigned long i;
00097         register const T *p = src;
00098         register T *q = dest;
00099         if (src > dest)
00100         {
00101             // src is above dest in memory, we start copying from the start
00102             for (i = count; i != 0; --i)
00103                 *q++ = *p++;
00104         }
00105         else
00106         {
00107             // src is below dest in memory, we start copying from the end
00108             q += count - 1;
00109             p += count - 1;
00110             for (i = count; i != 0; --i)
00111                 *q-- = *p--;
00112         }
00113 #endif
00114     }
00115 
00116 
00123     static void setMem(T *dest,
00124                        const T value,
00125                        const unsigned long count)
00126     {
00127 #ifdef HAVE_MEMSET
00128         if ((value == 0) || (sizeof(T) == sizeof(unsigned char)))
00129             memset(OFstatic_cast(void *, dest), OFstatic_cast(int, value), OFstatic_cast(size_t, count) * sizeof(T));
00130         else
00131 #endif
00132         {
00133             register unsigned long i;
00134             register T *q = dest;
00135             for (i = count; i != 0; --i)
00136                 *q++ = value;
00137         }
00138     }
00139 
00140 
00146     static void zeroMem(T *dest,
00147                         const unsigned long count)
00148     {
00149 #ifdef HAVE_MEMZERO
00150         memzero(dest, OFstatic_cast(size_t, count) * sizeof(T));
00151 #else
00152         register unsigned long i;
00153         register T *q = dest;
00154         for (i = count; i != 0; --i)
00155             *q++ = 0;
00156 #endif
00157     }
00158 };
00159 
00160 
00161 #endif
00162 
00163 
00164 /*
00165  *
00166  * CVS/RCS Log:
00167  * $Log: ofbmanip.h,v $
00168  * Revision 1.19  2010-10-14 13:15:50  joergr
00169  * Updated copyright header. Added reference to COPYRIGHT file.
00170  *
00171  * Revision 1.18  2009-09-28 12:19:37  joergr
00172  * Simplified code based on the new header file "ofdefine.h".
00173  *
00174  * Revision 1.17  2009-09-25 09:42:52  joergr
00175  * Introduced new general helper function moveMem() which allows for copying
00176  * overlapping memory areas.
00177  *
00178  * Revision 1.16  2005-12-08 16:05:46  meichel
00179  * Changed include path schema for all DCMTK header files
00180  *
00181  * Revision 1.15  2003/12/05 10:37:41  joergr
00182  * Removed leading underscore characters from preprocessor symbols (reserved
00183  * symbols). Updated copyright date where appropriate.
00184  *
00185  * Revision 1.14  2003/08/29 07:54:52  joergr
00186  * Modified function zeroMem() to compile with MSVC again where bzero() is not
00187  * available.
00188  *
00189  * Revision 1.13  2003/08/14 09:01:18  meichel
00190  * Adapted type casts to new-style typecast operators defined in ofcast.h
00191  *
00192  * Revision 1.12  2002/11/27 11:23:04  meichel
00193  * Adapted module ofstd to use of new header file ofstdinc.h
00194  *
00195  * Revision 1.11  2001/06/01 15:51:31  meichel
00196  * Updated copyright header
00197  *
00198  * Revision 1.10  2000/03/08 16:36:00  meichel
00199  * Updated copyright header.
00200  *
00201  * Revision 1.9  2000/02/02 10:56:25  joergr
00202  * Removed space characters before preprocessor directives.
00203  *
00204  * Revision 1.8  1999/09/17 11:46:34  joergr
00205  * Enhanced efficiency of "for" loops.
00206  *
00207  * Revision 1.7  1999/08/25 16:44:44  joergr
00208  * Enhanced efficiency of inner loops (count loop variable down).
00209  *
00210  * Revision 1.6  1999/04/30 16:34:07  meichel
00211  * Added provision for systems which have bzero() but no prototype, e.g. SunOS
00212  *
00213  * Revision 1.5  1999/04/29 16:49:22  meichel
00214  * Changed first parameter in bzero() call to char *, required on OSF1.
00215  *
00216  * Revision 1.4  1999/04/26 16:07:52  joergr
00217  * Changed comments.
00218  *
00219  * Revision 1.3  1998/12/16 15:59:51  joergr
00220  * Corrected bug in setMem routine (expected 'value' parameter for system
00221  * function 'memset' is implicitely casted to 'unsigned char').
00222  *
00223  * Revision 1.2  1998/12/02 12:52:05  joergr
00224  * Corrected bug in setMem routine (parameter 'value' was ignored).
00225  *
00226  * Revision 1.1  1998/11/27 12:29:20  joergr
00227  * First release of class for plaform independant memory operations.
00228  *
00229  *
00230  */


Generated on 6 Jan 2011 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.5.1