]> Creatis software - gdcm.git/blob - src/gdcmUtil.h
* Improvement of the TestInline
[gdcm.git] / src / gdcmUtil.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmUtil.h,v $
5   Language:  C++
6   Date:      $Date: 2005/11/29 13:02:47 $
7   Version:   $Revision: 1.66 $
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 
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 std::string NormalizePath(std::string const &name);
51    static std::string GetPath(std::string const &fullName);
52    static std::string GetName(std::string const &fullName);
53    static std::string GetCurrentDate();
54    static std::string GetCurrentTime();
55    static std::string GetCurrentDateTime();
56    /// Provides a simple static GetVersion() function
57    static std::string GetVersion() 
58                       { return GDCM_VERSION;}
59    static unsigned int GetCurrentThreadID();
60    static unsigned int GetCurrentProcessID();
61    static bool         IsCurrentProcessorBigEndian();
62
63    static std::string DicomString(const char *s, size_t l);
64    static std::string DicomString(const char *s);
65    static bool        DicomStringEqual(const std::string &s1, const char *s2);
66    static bool        CompareDicomString(const std::string &s1, 
67                                          const char *s2, int op);
68    static std::string GetMACAddress();
69
70    static std::string CreateUniqueUID(const std::string &root = "");
71    static void SetRootUID(const std::string &root = "");
72    static const std::string &GetRootUID();
73
74    static const uint8_t *GetFileMetaInformationVersion() 
75                      { return FileMetaInformationVersion;}
76    static void SetFileMetaInformationVersion( uint16_t fmiv )
77                      { FileMetaInformationVersion = (uint8_t *)&fmiv; }
78
79 // ----------------- to be removed later --------------------------     
80 //To perform a full check of inline functions on all the platforms, 
81 // we put here the two 'static' functions
82 // hifpswap and  hNoifpswap in a .h
83 // They will be remove ASAP
84
85    inline void hifpswap(double *a, double *b)     
86    {
87       double tmp;
88       tmp = *a;
89       *a = *b;
90       *b = tmp;
91    }
92    void hNoifpswap(double *a, double *b)    
93    {
94       double tmp;
95       tmp = *a;
96       *a = *b;
97       *b = tmp;
98    }    
99    void hfpswap(double *a, double *b);   
100    static inline void sthifpswap(double *a, double *b)     
101    {
102       double tmp;
103       tmp = *a;
104       *a = *b;
105       *b = tmp;
106    }
107    static void sthNoifpswap(double *a, double *b)    
108    {
109       double tmp;
110       tmp = *a;
111       *a = *b;
112       *b = tmp;
113    }    
114 // ------------ end of functions to remove --------------------
115 private:
116    static std::string GetIPAddress(); //Do not expose this method
117
118    static std::string RootUID;
119    static const std::string GDCM_UID;
120    static uint8_t *FileMetaInformationVersion;
121    static const uint16_t FMIV;
122    static std::string GDCM_MAC_ADRESS;
123 };
124
125 GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const uint16_t &val);
126 GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const uint32_t &val);
127 GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const double &val);
128 GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const char *val);
129 GDCM_EXPORT std::ostream &binary_write(std::ostream &os, std::string const &val);
130 GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const uint8_t *val, size_t len);
131 GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const uint16_t *val, size_t len);
132 } // end namespace gdcm
133 //-----------------------------------------------------------------------------
134 #endif