]> Creatis software - gdcm.git/blob - src/gdcmHeaderEntry.h
6242cba258a1294293e127a90f7c0fb683a88ab1
[gdcm.git] / src / gdcmHeaderEntry.h
1 // gdcmHeaderEntry.h
2 //-----------------------------------------------------------------------------
3 #ifndef GDCMHeaderEntry_H
4 #define GDCMHeaderEntry_H
5
6 #include <iostream>
7 #include <stdio.h>
8
9 #include "gdcmDictEntry.h"
10 class gdcmHeader;
11
12 //-----------------------------------------------------------------------------
13 /**
14  * \ingroup gdcmHeaderEntry
15  * \brief   The dicom header of a Dicom file contains a set of such entries
16  *          (when successfuly parsed against a given Dicom dictionary)
17  */
18 class GDCM_EXPORT gdcmHeaderEntry {
19 public:
20    gdcmHeaderEntry(gdcmDictEntry*);
21    /**
22     * \ingroup gdcmHeaderEntry
23     * \brief   returns the Dicom Group number of the current Dicom Header Entry
24     * @return 
25     */    
26    inline guint16      GetGroup(void)     { return entry->GetGroup();  };
27    /**
28     * \ingroup gdcmHeaderEntry
29     * \brief   returns the Dicom Element number of the current Dicom Header Entry
30     * @return 
31     */ 
32    inline guint16      GetElement(void)   { return entry->GetElement();};
33    /**
34     * \ingroup gdcmHeaderEntry
35     * \brief   returns the 'key' of the current Dicom Header Entry
36     * @return 
37     */
38    inline std::string  GetKey(void)       { return entry->GetKey();    };
39    /**
40     * \ingroup gdcmHeaderEntry
41     * \brief   returns the 'Name' '(e.g. "Patient's Name")
42     *          found in the Dicom Dictionnary
43     *          of the current Dicom Header Entry
44     * @return
45     */ 
46    inline std::string  GetName(void)      { return entry->GetName();   };
47
48    /**
49     * \ingroup gdcmHeaderEntry
50     * \brief   returns the 'Value Representation' 
51     *          (e.g. "PN" : Person Name, "SL" : Signed Long),
52     *          found in the Dicom Header or in the Dicom Dictionnary,
53     *          of the current Dicom Header Entry
54     * @return
55     */
56    inline std::string  GetVR(void)        { return entry->GetVR();     };
57    /**
58     * \ingroup gdcmHeaderEntry
59     * \brief   returns the 'Value' (e.g. "Dupond Marcel")
60     *          converted into a 'string', if it's stored as an integer
61     *          in the Dicom Header
62     *          of the current Dicom Header Entry
63     * @return
64     */ 
65    inline std::string  GetValue(void)     { return value;              };
66    /**
67     * \ingroup gdcmHeaderEntry
68     * \brief   returns the area value of the current Dicom Header Entry
69     *          when it's not string-translatable
70     *          (e.g : a LUT table)         
71     * @return
72     */    
73    inline void *       GetVoidArea(void)  { return voidArea;           };
74    /**
75     * \ingroup gdcmHeaderEntry
76     * \brief   returns offset (since the beginning of the file,
77     *          including the File Pramble, if any)
78     *          of the value of the current Dicom Header Entry
79     * \warning : offset of the *value*, not of the Dicom Header Entry
80     *  
81     * @return
82     */    
83    inline size_t       GetOffset(void)    { return Offset;             };
84    /**
85     * \ingroup gdcmHeaderEntry
86     * \brief   returns the actual value length of the current Dicom Header Entry
87     * \warning this value is not *allways* the one stored in the Dicom Header
88     *          in case on well knowned buggs
89     * @return
90     */        
91    inline guint32      GetLength(void)    { return UsableLength;       };
92     
93    /**
94     * \ingroup gdcmHeaderEntry
95     * \brief   returns the 'read length' of the current Dicom Header Entry
96     * \warning this value is the one stored in the Dicom Header
97     *          but not mandatoryly the one thats's used
98     *          (in case on SQ, or delimiters, the usable length is set to zero)
99     * @return
100     */     
101    inline guint32      GetReadLength(void) { return ReadLength;};
102
103    /**
104     * \ingroup gdcmHeaderEntry
105     * \brief   Sets the 'Value Representation' of the current Dicom Header Entry
106     */   
107    inline void         SetVR(std::string v)      { entry->SetVR(v);          };    
108    /**
109     * \ingroup gdcmHeaderEntry
110     * \brief   Sets both 'Read Length' and 'Usable Length'
111     *          of the current Dicom Header Entry
112     */ 
113    inline void         SetLength(guint32 l)      { ReadLength=UsableLength=l;};
114       
115    // The following 3 members, for internal use only ! 
116    
117    /**
118     * \ingroup gdcmHeaderEntry
119     * \brief   Sets only 'Read Length' (*not* 'Usable Length')
120     *          of the current Dicom Header Entry
121     */ 
122    inline void         SetReadLength(guint32 l)  { ReadLength   = l; };
123    /**
124     * \ingroup gdcmHeaderEntry
125     * \brief   Sets only 'Usable Length' (*not* 'Read Length')
126     *          of the current Dicom Header Entry
127     */          
128    inline void         SetUsableLength(guint32 l){ UsableLength = l; }; 
129         
130    /**
131     * \ingroup gdcmHeaderEntry
132     * \brief   Sets the value (string)
133     *          of the current Dicom Header Entry
134     */          
135    inline void         SetValue(std::string val) { value = val;      };
136
137    /**
138     * \ingroup gdcmHeaderEntry
139     * \brief   Sets the value (non string)
140     *          of the current Dicom Header Entry
141     */ 
142     inline void         SetVoidArea(void * area)  { voidArea = area;  };
143    
144    /**
145     * \ingroup gdcmHeaderEntry
146     * \brief   Sets the offset of the Dicom Element
147     * \warning : use with caution !
148     * @param   of offset to be set
149     */
150    inline void gdcmHeaderEntry::SetOffset(size_t of) { Offset = of; };
151
152    /**
153     * \ingroup gdcmHeaderEntry
154     * \brief   Sets to TRUE the ImplicitVr flag of the current Dicom Element
155     */
156    inline void gdcmHeaderEntry::SetImplicitVR(void) { ImplicitVR = true; };
157  
158    /**
159     * \ingroup gdcmHeaderEntry
160     * \brief   tells us if the current Dicom Element was checked as ImplicitVr
161     * @return true if the current Dicom Element was checked as ImplicitVr
162     */ 
163    inline bool  gdcmHeaderEntry::IsImplicitVR(void) { return ImplicitVR; };
164
165    /**
166     * \ingroup gdcmHeaderEntry
167     * \brief   tells us if the VR of the current Dicom Element is Unkonwn
168     * @return true if the VR is unkonwn
169     */ 
170    inline bool   gdcmHeaderEntry::IsVRUnknown(void) { return entry->IsVRUnknown(); };
171
172    /**
173     * \ingroup gdcmHeaderEntry
174     * \brief   Sets the DicEntry of the current Dicom Element
175     * @param   NewEntry pointer to the DictEntry
176     */ 
177    inline void gdcmHeaderEntry::SetDictEntry(gdcmDictEntry *NewEntry) { 
178       entry = NewEntry;
179    };
180
181    /**
182     * \ingroup gdcmHeaderEntry
183     * \brief   Gets the DicEntry of the current Dicom Element
184     * @return  the DicEntry of the current Dicom Element
185     */
186    gdcmDictEntry * gdcmHeaderEntry::GetDictEntry(void) { return entry; }; 
187
188    /**
189     * \ingroup gdcmHeaderEntry
190     * \brief   Sets the print level for the Dicom Header Elements
191     * \note 0 for Light Print; 1 for 'medium' Print, 2 for Heavy
192     */
193    void SetPrintLevel(int level) { printLevel = level; };
194    void Print (std::ostream & os = std::cout); 
195
196 private:
197    // FIXME: In fact we should be more specific and use :
198    // friend gdcmHeaderEntry * gdcmHeader::ReadNextElement(void);
199    
200    friend class gdcmHeader;
201
202 // Variables
203    gdcmDictEntry *entry;
204    /// Updated from ReadLength, by FixFoungLentgh()
205    /// for fixing a bug in the header 
206    /// or helping the parser going on    
207    guint32 UsableLength; 
208                           
209    /// Length actually read on disk
210    /// (before FixFoundLength)
211    /// ReadLength will be updated only when
212    /// FixFoundLength actually fixes a bug in the header,
213    /// not when it performs a trick to help the Parser
214    /// going on.
215    /// *for internal* use only
216    guint32 ReadLength;
217
218    /// Even when reading explicit vr files, some
219    /// elements happen to be implicit. Flag them here
220    /// since we can't use the entry->vr without breaking
221    /// the underlying dictionary.       
222    bool ImplicitVR;
223                           
224    /// Header Entry value, stores as a std::string (VR will be used, later, to decode)
225    std::string  value;
226
227    /// unsecure memory area to hold 'non string' values 
228    /// (ie : Lookup Tables, overlays)   
229    void *voidArea;
230    /// Offset from the begining of file for direct user access               
231    size_t Offset; 
232    /// How many details are to be printed (value : 0,1,2)      
233    int printLevel;
234 };
235
236 //-----------------------------------------------------------------------------
237 #endif