gdcmUtil.h

Go to the documentation of this file.
00001 /*=========================================================================
00002                                                                                 
00003   Program:   gdcm
00004   Module:    $RCSfile: gdcmUtil.h,v $
00005   Language:  C++
00006   Date:      $Date: 2007/08/22 16:14:05 $
00007   Version:   $Revision: 1.69 $
00008                                                                                 
00009   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
00010   l'Image). All rights reserved. See Doc/License.txt or
00011   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
00012                                                                                 
00013      This software is distributed WITHOUT ANY WARRANTY; without even
00014      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00015      PURPOSE.  See the above copyright notices for more information.
00016                                                                                 
00017 =========================================================================*/
00018 
00019 #ifndef _GDCMUTIL_H_
00020 #define _GDCMUTIL_H_
00021 
00022 #include "gdcmCommon.h"
00023 #include <vector>
00024 #include <string>
00025 
00026 namespace GDCM_NAME_SPACE 
00027 {
00034 //-----------------------------------------------------------------------------
00035 
00036 class GDCM_EXPORT Util
00037 {
00038 public:
00039    static std::string Format(const char *format, ...);
00040    static void        Tokenize (const std::string &str,
00041                                 std::vector<std::string> &tokens,
00042                                 const std::string &delimiters = " ");
00043    static int         CountSubstring (const std::string &str,
00044                                       const std::string &subStr);
00045 
00046    static std::string CreateCleanString(std::string const &s);
00047    static std::string CreateCleanString(uint8_t *s, int l);
00048    static bool IsCleanString(std::string const &s);
00049    static bool IsCleanArea(uint8_t *s, int l);
00050    static std::string NormalizePath(std::string const &name);
00051    static std::string GetPath(std::string const &fullName);
00052    static std::string GetName(std::string const &fullName);
00053    static std::string GetCurrentDate();
00054    static std::string GetCurrentTime();
00055    static std::string GetCurrentDateTime();
00057    static std::string GetVersion() 
00058                       { return GDCM_VERSION;}
00059    static unsigned int GetCurrentThreadID();
00060    static unsigned int GetCurrentProcessID();
00061    static bool         IsCurrentProcessorBigEndian();
00062 
00063    static std::string DicomString(const char *s, size_t l);
00064    static std::string DicomString(const char *s);
00065    static bool        DicomStringEqual(const std::string &s1, const char *s2);
00066    static bool        CompareDicomString(const std::string &s1, 
00067                                          const char *s2, int op);
00068    static std::string GetMACAddress();
00069 
00070    static std::string CreateUniqueUID(const std::string &root = "");
00071    static void SetRootUID(const std::string &root = "");
00072    static const std::string &GetRootUID();
00073 
00074    static const uint8_t *GetFileMetaInformationVersion() 
00075                      { return FileMetaInformationVersion;}
00076    static void SetFileMetaInformationVersion( uint16_t fmiv )
00077                      { FileMetaInformationVersion = (uint8_t *)&fmiv; }
00078 
00079 // ----------------- to be removed later --------------------------     
00080 //To perform a full check of inline functions on all the platforms, 
00081 // we put here the two 'static' functions
00082 // hifpswap and  hNoifpswap in a .h
00083 // They will be remove ASAP
00084 
00085    inline void hifpswap(double *a, double *b)     
00086    {
00087       double tmp;
00088       tmp = *a;
00089       *a = *b;
00090       *b = tmp;
00091    }
00092    void hNoifpswap(double *a, double *b)    
00093    {
00094       double tmp;
00095       tmp = *a;
00096       *a = *b;
00097       *b = tmp;
00098    }    
00099    void hfpswap(double *a, double *b);   
00100    static inline void sthifpswap(double *a, double *b)     
00101    {
00102       double tmp;
00103       tmp = *a;
00104       *a = *b;
00105       *b = tmp;
00106    }
00107    static void sthNoifpswap(double *a, double *b)    
00108    {
00109       double tmp;
00110       tmp = *a;
00111       *a = *b;
00112       *b = tmp;
00113    }    
00114 // ------------ end of functions to remove --------------------
00115 
00116 // For MD5
00117 static std::string ConvertToMD5 (std::string &stringToCrypt);
00118 
00119 private:
00120    static std::string GetIPAddress(); //Do not expose this method
00121 
00122    static std::string RootUID;
00123    static const std::string GDCM_UID;
00124    static uint8_t *FileMetaInformationVersion;
00125    static const uint16_t FMIV;
00126    static std::string GDCM_MAC_ADRESS;
00127 
00128 // For MD5
00129 
00130 /*
00131   Copyright (C) 1999, 2002 Aladdin Enterprises.  All rights reserved.
00132   This software is provided 'as-is', without any express or implied
00133   warranty.  In no event will the authors be held liable for any damages
00134   arising from the use of this software.
00135 
00136   Permission is granted to anyone to use this software for any purpose,
00137   including commercial applications, and to alter it and redistribute it
00138   freely, subject to the following restrictions:
00139 
00140   1. The origin of this software must not be misrepresented; you must not
00141      claim that you wrote the original software. If you use this software
00142      in a product, an acknowledgment in the product documentation would be
00143      appreciated but is not required.
00144   2. Altered source versions must be plainly marked as such, and must not be
00145      misrepresented as being the original software.
00146   3. This notice may not be removed or altered from any source distribution.
00147 
00148   L. Peter Deutsch
00149   ghost@aladdin.com
00150 */
00151 
00152 /* $Id: gdcmUtil.h,v 1.69 2007/08/22 16:14:05 jpr Exp $ */
00153 /*
00154   Independent implementation of MD5 (RFC 1321).
00155   This code implements the MD5 Algorithm defined in RFC 1321, whose
00156   text is available at
00157  http://www.ietf.org/rfc/rfc1321.txt
00158   The code is derived from the text of the RFC, including the test suite
00159   (section A.5) but excluding the rest of Appendix A.  It does not include
00160   any code or documentation that is identified in the RFC as being
00161   copyrighted.
00162   The original and principal author of md5.h is L. Peter Deutsch
00163   <ghost@aladdin.com>.  Other authors are noted in the change history
00164   that follows (in reverse chronological order):
00165   2002-04-13 lpd Removed support for non-ANSI compilers; removed
00166        references to Ghostscript; clarified derivation from RFC 1321;
00167        now handles byte order either statically or dynamically.
00168   1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
00169   1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
00170        added conditionalization for C++ compilation from 
00171        Martin Purschke <purschke@bnl.gov>.
00172   1999-05-03 lpd Original version.
00173  */
00174 
00175 /*
00176  * This package supports both compile-time and run-time determination of CPU
00177  * byte order.  If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be
00178  * compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is
00179  * defined as non-zero, the code will be compiled to run only on big-endian
00180  * CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to
00181  * run on either big- or little-endian CPUs, but will run slightly less
00182  * efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined.
00183  */
00184 
00185 /* Define the state of the MD5 Algorithm. */
00186 typedef struct md5_state_s {
00187     uint32_t count[2];   /* message length in bits, lsw first */
00188     uint32_t abcd[4];    /* digest buffer    */
00189     uint8_t buf[64];     /* accumulate block */
00190 } md5_state_t;
00191 
00192    static void md5_process(md5_state_t *pms, const uint8_t *data /*[64]*/);
00193    /* Initialize the algorithm. */
00194    static void md5_init(md5_state_t *pms);
00195    /* Append a string to the message. */
00196    static void md5_append(md5_state_t *pms, const uint8_t *data, int nbytes);
00197    /* Finish the message and return the digest. */
00198    static void md5_finish(md5_state_t *pms, uint8_t digest[16]);
00199 
00200 };
00201 
00202 GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const uint16_t &val);
00203 GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const uint32_t &val);
00204 GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const double &val);
00205 GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const char *val);
00206 GDCM_EXPORT std::ostream &binary_write(std::ostream &os, std::string const &val);
00207 GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const uint8_t *val, size_t len);
00208 GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const uint16_t *val, size_t len);
00209 
00210 } // end namespace gdcm
00211 //-----------------------------------------------------------------------------
00212 #endif

Generated on Fri Aug 24 12:59:32 2007 for gdcm by  doxygen 1.4.6