]> Creatis software - gdcm.git/blob - src/gdcmCommon.h
ENH: NEW FEATURE: TagKey is now a union of two uint16_t instead of string this greatl...
[gdcm.git] / src / gdcmCommon.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmCommon.h,v $
5   Language:  C++
6   Date:      $Date: 2005/07/11 15:20:46 $
7   Version:   $Revision: 1.73 $
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 GDCMCOMMON_H
20 #define GDCMCOMMON_H
21
22 #include "gdcmConfigure.h"
23
24 //-----------------------------------------------------------------------------
25 //This is needed when compiling in debug mode
26 #ifdef _MSC_VER
27 // 'identifier' : class 'type' needs to have dll-interface to be used by
28 // clients of class 'type2'
29 #pragma warning ( disable : 4251 )
30 // non dll-interface class 'type' used as base for dll-interface class 'type2'
31 #pragma warning ( disable : 4275 )
32 // 'identifier' : identifier was truncated to 'number' characters in the
33 // debug information
34 #pragma warning ( disable : 4786 )
35 //'identifier' : decorated name length exceeded, name was truncated
36 #pragma warning ( disable : 4503 )
37 // C++ exception specification ignored except to indicate a 
38 // function is not __declspec(nothrow)
39 #pragma warning ( disable : 4290 )
40 // signed/unsigned mismatch
41 #pragma warning ( disable : 4018 )
42 // return type for 'identifier' is '' (ie; not a UDT or reference to UDT. Will
43 // produce errors if applied using infix notation
44 #pragma warning ( disable : 4284 )
45 // 'type' : forcing value to bool 'true' or 'false' (performance warning)
46 // //#pragma warning ( disable : 4800 )
47 #endif //_MSC_VER
48
49 //-----------------------------------------------------------------------------
50 #ifdef CMAKE_HAVE_STDINT_H
51    #include <stdint.h>
52 #else
53 #ifdef CMAKE_HAVE_INTTYPES_H
54    // Old system only have this
55    #include <inttypes.h>   // For uint8_t uint16_t and uint32_t
56 #else
57 // Broken plateform do not respect C99 and do not provide those typedef
58 // Special case for recent borland compiler, comes with stdint.h
59 #if defined(_MSC_VER) || defined(__BORLANDC__) && (__BORLANDC__ < 0x0560)  || defined(__MINGW32__)
60 typedef  signed char         int8_t;
61 typedef  signed short        int16_t;
62 typedef  signed int          int32_t;
63 typedef  unsigned char       uint8_t;
64 typedef  unsigned short      uint16_t;
65 typedef  unsigned int        uint32_t;
66 #else
67 #error "Sorry your plateform is not supported"
68 #endif // defined(_MSC_VER) || defined(__BORLANDC__) && (__BORLANDC__ < 0x0560)  || defined(__MINGW32__)
69 #endif // CMAKE_HAVE_INTTYPES_H
70 #endif // CMAKE_HAVE_STDINT_H
71
72 // Basically for VS6 and bcc 5.5.1:
73 #ifndef UINT32_MAX
74 #define UINT32_MAX    (4294967295U)
75 #endif
76
77 #if defined(_WIN32) && defined(BUILD_SHARED_LIBS)
78   #ifdef gdcm_EXPORTS
79     #define GDCM_EXPORT __declspec( dllexport )
80   #else
81     #define GDCM_EXPORT __declspec( dllimport )
82   #endif
83 #else
84   #define GDCM_EXPORT
85 #endif
86
87 #include <string>
88 #define FASTTAGKEY 0
89
90 // FIXME: Should rewrite this:
91 #if FASTTAGKEY
92 #include <iostream>
93 #endif
94 #if defined(_MSC_VER) && (_MSC_VER == 1200)
95 /* ostream operator for std::string since VS6 does not provide it*/
96 #include <iostream>
97 #endif
98
99 /// \brief namespace for Grass root DiCoM
100 namespace gdcm
101 {
102
103 // Centralize information about the gdcm dictionary in only one file:
104 #ifndef PUB_DICT_PATH
105 #  define PUB_DICT_PATH   "../Dicts/"
106 #endif
107 #define PUB_DICT_NAME     "DicomV3Dict"
108 #define PUB_DICT_FILENAME "gdcm.dic"
109 #define DICT_ELEM         "DicomDir.dic"
110 #define DICT_TS           "dicomTS.dic"
111 #define DICT_VR           "dicomVR.dic"
112 #define DICT_GROUP_NAME   "DictGroupName.dic"
113
114 GDCM_EXPORT extern const std::string GDCM_UNKNOWN;
115 GDCM_EXPORT extern const std::string GDCM_UNFOUND;
116 GDCM_EXPORT extern const std::string GDCM_BINLOADED;
117 GDCM_EXPORT extern const std::string GDCM_NOTLOADED;
118 GDCM_EXPORT extern const std::string GDCM_UNREAD;
119
120 /// \brief TagKey is made to hold the standard Dicom Tag (Group number, Element
121 /// number)
122 /// Instead of using the two '16 bits integers' as the Hask Table key, we
123 /// converted into a string (e.g. 0x0018,0x0050 converted into "0018|0050")
124 /// It appears to be a huge waste of time.
125 /// We'll fix the mess up -without any change in the API- as soon as the bench
126 /// marks are fully performed.
127
128 #if FASTTAGKEY
129 typedef union   {
130       uint16_t  tab[2];
131       uint32_t  tagkey;
132     } TagKey;
133 /* ostream operator for TagKey */
134 inline std::ostream& operator<<(std::ostream& _O, TagKey _val)
135 {
136   return ( _O << std::ios::hex << _val.tab[0] 
137     << "|" << std::ios::hex << _val.tab[1] );
138 };
139 inline bool operator==(TagKey _self, TagKey _val)
140 {
141   return _self.tagkey == _val.tagkey;
142 };
143 inline bool operator<(TagKey _self, TagKey _val)
144 {
145   return _self.tagkey < _val.tagkey;
146 };
147 // FIXME
148 // This one is clearly weird, see gdcmDocument:918
149 inline TagKey operator+(TagKey _self, TagKey _val)
150 {
151   TagKey r;
152   r.tagkey = _self.tagkey + _val.tagkey;
153   return r;
154 };
155 #else
156 typedef std::string TagKey;
157 #endif
158 #if defined(_MSC_VER) && (_MSC_VER == 1200)
159 // Doing everything within gdcm namespace to avoid polluting 3d party software
160 inline std::ostream& operator<<(std::ostream& _O, std::string _val)
161 {
162   return _O << _val.c_str();
163 };
164 #endif
165 typedef std::string TagName;
166
167 enum FileType {
168    Unknown = 0,
169    ExplicitVR, // DicomDir is in this case. Except when it's ImplicitVR !...
170    ImplicitVR,
171    ACR,
172    ACR_LIBIDO
173 };
174
175 /// \brief type of the elements composing a DICOMDIR (for internal use only)
176 enum DicomDirType {
177    DD_UNKNOWN = 0,
178    DD_META,
179    DD_PATIENT,
180    DD_STUDY,
181    DD_SERIE,
182    DD_IMAGE
183 };
184
185 /**
186  * \brief structure, for internal use only
187  */  
188 struct Element
189 {
190    /// DicomGroup number
191    unsigned short int Group;
192    /// DicomElement number
193    unsigned short int Elem;
194    /// value (coded as a std::string) of the Element
195    std::string Value;
196 };
197
198 } //namespace gdcm
199 //-----------------------------------------------------------------------------
200 #endif