]> Creatis software - gdcm.git/blob - src/gdcmUtil.h
BUG: map<>::mapped_type is not part of the STL. Should fix issue on VS* compiler
[gdcm.git] / src / gdcmUtil.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmUtil.h,v $
5   Language:  C++
6   Date:      $Date: 2007/10/01 09:25:06 $
7   Version:   $Revision: 1.70 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18
19 #ifndef _GDCMUTIL_H_
20 #define _GDCMUTIL_H_
21
22 #include "gdcmCommon.h"
23 #include <vector>
24 #include <string>
25
26 namespace GDCM_NAME_SPACE 
27 {
28 /**
29  * \brief    Here are some utility functions, belonging to the gdcm::Util class,
30  *           dealing with strings, file names... that can be called
31  *           from anywhere by whomsoever they can help.
32  */
33
34 //-----------------------------------------------------------------------------
35
36 class GDCM_EXPORT Util
37 {
38 public:
39    static std::string Format(const char *format, ...);
40    static void        Tokenize (const std::string &str,
41                                 std::vector<std::string> &tokens,
42                                 const std::string &delimiters = " ");
43    static int         CountSubstring (const std::string &str,
44                                       const std::string &subStr);
45
46    static std::string CreateCleanString(std::string const &s);
47    static std::string CreateCleanString(uint8_t *s, int l);
48    static bool IsCleanString(std::string const &s);
49    static bool IsCleanArea(uint8_t *s, int l);
50    static void ReplaceSpecChar(std::string &s, std::string &rep);
51    static std::string NormalizePath(std::string const &name);
52    static std::string GetPath(std::string const &fullName);
53    static std::string GetName(std::string const &fullName);
54    static std::string GetCurrentDate();
55    static std::string GetCurrentTime();
56    static std::string GetCurrentDateTime();
57    /// Provides a simple static GetVersion() function
58    static std::string GetVersion() 
59                       { return GDCM_VERSION;}
60    static unsigned int GetCurrentThreadID();
61    static unsigned int GetCurrentProcessID();
62    static bool         IsCurrentProcessorBigEndian();
63
64    static std::string DicomString(const char *s, size_t l);
65    static std::string DicomString(const char *s);
66    static bool        DicomStringEqual(const std::string &s1, const char *s2);
67    static bool        CompareDicomString(const std::string &s1, 
68                                          const char *s2, int op);
69    static std::string GetMACAddress();
70
71    static std::string CreateUniqueUID(const std::string &root = "");
72    static void SetRootUID(const std::string &root = "");
73    static const std::string &GetRootUID();
74
75    static const uint8_t *GetFileMetaInformationVersion() 
76                      { return FileMetaInformationVersion;}
77    static void SetFileMetaInformationVersion( uint16_t fmiv )
78                      { FileMetaInformationVersion = (uint8_t *)&fmiv; }
79
80 // ----------------- to be removed later --------------------------     
81 //To perform a full check of inline functions on all the platforms, 
82 // we put here the two 'static' functions
83 // hifpswap and  hNoifpswap in a .h
84 // They will be remove ASAP
85
86    inline void hifpswap(double *a, double *b)     
87    {
88       double tmp;
89       tmp = *a;
90       *a = *b;
91       *b = tmp;
92    }
93    void hNoifpswap(double *a, double *b)    
94    {
95       double tmp;
96       tmp = *a;
97       *a = *b;
98       *b = tmp;
99    }    
100    void hfpswap(double *a, double *b);
101       
102    static inline void sthifpswap(double *a, double *b)     
103    {
104       double tmp;
105       tmp = *a;
106       *a = *b;
107       *b = tmp;
108    }
109    static void sthNoifpswap(double *a, double *b)    
110    {
111       double tmp;
112       tmp = *a;
113       *a = *b;
114       *b = tmp;
115    }    
116 // ------------ end of functions to remove --------------------
117
118 // For MD5
119 static std::string ConvertToMD5 (std::string &stringToCrypt);
120
121 private:
122    static std::string GetIPAddress(); //Do not expose this method
123
124    static std::string RootUID;
125    static const std::string GDCM_UID;
126    static uint8_t *FileMetaInformationVersion;
127    static const uint16_t FMIV;
128    static std::string GDCM_MAC_ADRESS;
129
130 // For MD5
131
132 /*
133   Copyright (C) 1999, 2002 Aladdin Enterprises.  All rights reserved.
134   This software is provided 'as-is', without any express or implied
135   warranty.  In no event will the authors be held liable for any damages
136   arising from the use of this software.
137
138   Permission is granted to anyone to use this software for any purpose,
139   including commercial applications, and to alter it and redistribute it
140   freely, subject to the following restrictions:
141
142   1. The origin of this software must not be misrepresented; you must not
143      claim that you wrote the original software. If you use this software
144      in a product, an acknowledgment in the product documentation would be
145      appreciated but is not required.
146   2. Altered source versions must be plainly marked as such, and must not be
147      misrepresented as being the original software.
148   3. This notice may not be removed or altered from any source distribution.
149
150   L. Peter Deutsch
151   ghost@aladdin.com
152 */
153
154 /* $Id: gdcmUtil.h,v 1.70 2007/10/01 09:25:06 jpr Exp $ */
155 /*
156   Independent implementation of MD5 (RFC 1321).
157   This code implements the MD5 Algorithm defined in RFC 1321, whose
158   text is available at
159  http://www.ietf.org/rfc/rfc1321.txt
160   The code is derived from the text of the RFC, including the test suite
161   (section A.5) but excluding the rest of Appendix A.  It does not include
162   any code or documentation that is identified in the RFC as being
163   copyrighted.
164   The original and principal author of md5.h is L. Peter Deutsch
165   <ghost@aladdin.com>.  Other authors are noted in the change history
166   that follows (in reverse chronological order):
167   2002-04-13 lpd Removed support for non-ANSI compilers; removed
168        references to Ghostscript; clarified derivation from RFC 1321;
169        now handles byte order either statically or dynamically.
170   1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
171   1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
172        added conditionalization for C++ compilation from 
173        Martin Purschke <purschke@bnl.gov>.
174   1999-05-03 lpd Original version.
175  */
176
177 /*
178  * This package supports both compile-time and run-time determination of CPU
179  * byte order.  If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be
180  * compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is
181  * defined as non-zero, the code will be compiled to run only on big-endian
182  * CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to
183  * run on either big- or little-endian CPUs, but will run slightly less
184  * efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined.
185  */
186
187 /* Define the state of the MD5 Algorithm. */
188 typedef struct md5_state_s {
189     uint32_t count[2];   /* message length in bits, lsw first */
190     uint32_t abcd[4];    /* digest buffer    */
191     uint8_t buf[64];     /* accumulate block */
192 } md5_state_t;
193
194    static void md5_process(md5_state_t *pms, const uint8_t *data /*[64]*/);
195    /* Initialize the algorithm. */
196    static void md5_init(md5_state_t *pms);
197    /* Append a string to the message. */
198    static void md5_append(md5_state_t *pms, const uint8_t *data, int nbytes);
199    /* Finish the message and return the digest. */
200    static void md5_finish(md5_state_t *pms, uint8_t digest[16]);
201
202 };
203
204 GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const uint16_t &val);
205 GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const uint32_t &val);
206 GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const double &val);
207 GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const char *val);
208 GDCM_EXPORT std::ostream &binary_write(std::ostream &os, std::string const &val);
209 GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const uint8_t *val, size_t len);
210 GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const uint16_t *val, size_t len);
211
212 } // end namespace gdcm
213 //-----------------------------------------------------------------------------
214 #endif