]> Creatis software - gdcm.git/blob - src/gdcmHeaderEntry.h
2004-04-28 Jean-Pierre Roux
[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    /**
125     * \ingroup gdcmHeaderEntry
126     * \brief   Sets only 'Usable Length' (*not* 'Read Length')
127     *          of the current Dicom Header Entry
128     */          
129    inline void         SetUsableLength(guint32 l){ UsableLength = l; }; 
130         
131    /**
132     * \ingroup gdcmHeaderEntry
133     * \brief   Sets the value (string)
134     *          of the current Dicom Header Entry
135     */          
136    inline void         SetValue(std::string val) {  value = val; };
137
138    /**
139     * \ingroup gdcmHeaderEntry
140     * \brief   Sets the value (non string)
141     *          of the current Dicom Header Entry
142     */ 
143     inline void         SetVoidArea(void * area)  { voidArea = area;  };
144    
145    /**
146     * \ingroup gdcmHeaderEntry
147     * \brief   Sets the offset of the Dicom Element
148     * \warning : use with caution !
149     * @param   of offset to be set
150     */
151    inline void gdcmHeaderEntry::SetOffset(size_t of) { Offset = of; };
152
153    /**
154     * \ingroup gdcmHeaderEntry
155     * \brief   Sets to TRUE the ImplicitVr flag of the current Dicom Element
156     */
157    inline void gdcmHeaderEntry::SetImplicitVR(void) { ImplicitVR = true; };
158  
159    /**
160     * \ingroup gdcmHeaderEntry
161     * \brief   tells us if the current Dicom Element was checked as ImplicitVr
162     * @return true if the current Dicom Element was checked as ImplicitVr
163     */ 
164    inline bool  gdcmHeaderEntry::IsImplicitVR(void) { return ImplicitVR; };
165
166    /**
167     * \ingroup gdcmHeaderEntry
168     * \brief   tells us if the VR of the current Dicom Element is Unkonwn
169     * @return true if the VR is unkonwn
170     */ 
171    inline bool   gdcmHeaderEntry::IsVRUnknown(void) { return entry->IsVRUnknown(); };
172
173    /**
174     * \ingroup gdcmHeaderEntry
175     * \brief   Sets the DicEntry of the current Dicom Element
176     * @param   NewEntry pointer to the DictEntry
177     */ 
178    inline void gdcmHeaderEntry::SetDictEntry(gdcmDictEntry *NewEntry) { 
179       entry = NewEntry;
180    };
181
182    /**
183     * \ingroup gdcmHeaderEntry
184     * \brief   Gets the DicEntry of the current Dicom Element
185     * @return  the DicEntry of the current Dicom Element
186     */
187    gdcmDictEntry * gdcmHeaderEntry::GetDictEntry(void) { return entry; }; 
188
189    /**
190     * \ingroup gdcmHeaderEntry
191     * \brief   Sets the print level for the Dicom Header Elements
192     * \note 0 for Light Print; 1 for 'medium' Print, 2 for Heavy
193     */
194    void SetPrintLevel(int level) { printLevel = level; };
195    void Print (std::ostream & os = std::cout); 
196         
197    /**
198     * \ingroup gdcmHeaderEntry
199     * \brief   Gets the depth level of a Dicom Header Entry
200     *          embedded in a SeQuence
201     */          
202    inline int         GetSQDepthLevel(void) 
203       {  return (SQDepthLevel); };
204          
205    guint32 GetFullLength(void);
206    
207 private:
208    // FIXME: In fact we should be more specific and use :
209    // friend gdcmHeaderEntry * gdcmHeader::ReadNextElement(void);
210    
211    friend class gdcmHeader;
212
213  /**
214     * \ingroup gdcmHeaderEntry
215     * \brief   Sets the depth level of a Dicom Header Entry
216     *          embedded in a SeQuence 
217     */          
218    inline void         SetSQDepthLevel(int depthLevel) 
219       {  SQDepthLevel = depthLevel; };
220       
221 // Variables
222    gdcmDictEntry *entry;
223    /// Updated from ReadLength, by FixFoungLentgh()
224    /// for fixing a bug in the header 
225    /// or helping the parser going on    
226    guint32 UsableLength; 
227                           
228    /// Length actually read on disk
229    /// (before FixFoundLength)
230    /// ReadLength will be updated only when
231    /// FixFoundLength actually fixes a bug in the header,
232    /// not when it performs a trick to help the Parser
233    /// going on.
234    /// *for internal* use only
235    guint32 ReadLength;
236
237    /// Even when reading explicit vr files, some
238    /// elements happen to be implicit. Flag them here
239    /// since we can't use the entry->vr without breaking
240    /// the underlying dictionary.       
241    bool ImplicitVR;
242                           
243    /// Header Entry value, stores as a std::string (VR will be used, later, to decode)
244    std::string  value;
245
246    /// unsecure memory area to hold 'non string' values 
247    /// (ie : Lookup Tables, overlays)   
248    void *voidArea;
249    /// Offset from the begining of file for direct user access               
250    size_t Offset; 
251    /// How many details are to be printed (value : 0,1,2)      
252    int printLevel;
253    
254    /// Gives the depth level of elements inside SeQuences   
255    int SQDepthLevel;
256 };
257
258 //-----------------------------------------------------------------------------
259 #endif