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