]> Creatis software - gdcm.git/blob - src/gdcmDocEntry.h
Last commit before the final(?) one, for the new version.
[gdcm.git] / src / gdcmDocEntry.h
1 // gdcmDocEntry.h
2 //-----------------------------------------------------------------------------
3 #ifndef GDCMDocEntry_H
4 #define GDCMDocEntry_H
5
6 #include <iostream>
7 #include <stdio.h>
8
9 #include "gdcmDictEntry.h"
10 //#include "gdcmValEntry.h"
11 class gdcmHeader;
12
13 //-----------------------------------------------------------------------------
14 /**
15  * \ingroup gdcmDocEntry
16  * \brief   The dicom header of a Dicom file contains a set of such entries
17  *          (when successfuly parsed against a given Dicom dictionary)
18  */
19 class GDCM_EXPORT gdcmDocEntry {
20 public:
21    gdcmDocEntry(gdcmDictEntry*);
22      
23    /// Returns the Dicom Group number of the current Dicom Header Entry
24    inline guint16      GetGroup(void)     { return entry->GetGroup();  };
25
26    /// Returns the Dicom Element number of the current Dicom Header Entry
27    inline guint16      GetElement(void)   { return entry->GetElement();};
28
29    /// Returns the 'key' of the current Dicom Header Entry
30    inline std::string  GetKey(void)       { return entry->GetKey();    };
31
32    /// \brief Returns the 'Name' '(e.g. "Patient's Name") found in the Dicom
33    /// Dictionnary of the current Dicom Header Entry
34    inline std::string  GetName(void)      { return entry->GetName();   };
35
36    /// \brief Returns the 'Value Representation' (e.g. "PN" : Person Name,
37    /// "SL" : Signed Long), found in the Dicom Header or in the Dicom
38    /// Dictionnary, of the current Dicom Header Entry
39    inline std::string  GetVR(void)        { return entry->GetVR();     };
40
41    /// \brief Returns offset (since the beginning of the file, including
42    /// the File Pramble, if any) of the value of the current Dicom HeaderEntry
43    /// \warning offset of the *value*, not of the Dicom Header Entry
44    inline size_t       GetOffset(void)    { return Offset;             };
45
46    /// \brief Returns the actual value length of the current Dicom Header Entry
47    /// \warning this value is not *allways* the one stored in the Dicom Header
48    ///          in case of well knowned bugs
49    inline guint32 GetLength(void) { return UsableLength; };
50     
51    /// \brief Returns the 'read length' of the current Dicom Header Entry
52    /// \warning this value is the one stored in the Dicom Header but not
53    ///          mandatoryly the one thats's used (in case on SQ, or delimiters,
54    ///          the usable length is set to zero)
55    inline guint32 GetReadLength(void) { return ReadLength; };
56
57    /// Sets the 'Value Representation' of the current Dicom Header Entry
58    inline void SetVR(std::string v) { entry->SetVR(v); };    
59
60    /// \brief Sets both 'Read Length' and 'Usable Length' of the current
61    /// Dicom Header Entry
62    inline void SetLength(guint32 l) { ReadLength=UsableLength=l;};
63       
64    // The following 3 members, for internal use only ! 
65    
66    /// \brief Sets only 'Read Length' (*not* 'Usable Length') of the current
67    /// Dicom Header Entry
68    inline void SetReadLength(guint32 l) { ReadLength   = l; };
69
70    /// \brief Sets only 'Usable Length' (*not* 'Read Length') of the current
71    /// Dicom Header Entry
72    inline void SetUsableLength(guint32 l) { UsableLength = l; }; 
73    
74    /// \brief   Sets the offset of the Dicom Element
75    /// \warning use with caution !
76    /// @param   of offset to be set
77    inline void gdcmDocEntry::SetOffset(size_t of) { Offset = of; };
78
79    /// Sets to TRUE the ImplicitVr flag of the current Dicom Element
80    inline void gdcmDocEntry::SetImplicitVR(void) { ImplicitVR = true; };
81  
82    /// \brief Tells us if the current Dicom Element was checked as ImplicitVr
83    /// @return true if the current Dicom Element was checked as ImplicitVr
84    inline bool gdcmDocEntry::IsImplicitVR(void) { return ImplicitVR; };
85
86    /// \brief Tells us if the VR of the current Dicom Element is Unknown
87    /// @return true if the VR is unkonwn
88    inline bool gdcmDocEntry::IsVRUnknown(void)
89                { return entry->IsVRUnknown(); };
90
91    /// \brief   Sets the DicEntry of the current Dicom Element
92    /// @param   NewEntry pointer to the DictEntry
93    inline void gdcmDocEntry::SetDictEntry(gdcmDictEntry *NewEntry)
94                { entry = NewEntry; };
95
96    /// \brief  Gets the DicEntry of the current Dicom Element
97    /// @return The DicEntry of the current Dicom Element
98    gdcmDictEntry * gdcmDocEntry::GetDictEntry(void) { return entry; }; 
99
100    /// \brief Sets the print level for the Dicom Header Elements
101    /// \note 0 for Light Print; 1 for 'medium' Print, 2 for Heavy
102    void SetPrintLevel(int level) { printLevel = level; };
103
104    /// \brief Gets the print level for the Dicom Header Elements
105    int GetPrintLevel(void) { return(printLevel); };
106    
107    virtual void Print (std::ostream & os = std::cout); 
108    
109    void gdcmDocEntry::PrintCommonPart(std::ostream & os);
110     
111    /// Gets the depth level of a Dicom Header Entry embedded in a SeQuence
112    inline int GetSQDepthLevel(void) { return (SQDepthLevel); };
113          
114    guint32 GetFullLength(void);
115    
116    void Copy(gdcmDocEntry *doc);
117
118    bool isItemDelimitor();
119    bool isSequenceDelimitor();   
120
121    inline int GetDepthLevel(void) 
122       {return(SQDepthLevel);}
123    void SetDepthLevel(int depth) 
124       {SQDepthLevel = depth;}
125             
126 private:
127    // FIXME: In fact we should be more specific and use :
128    // friend gdcmDocEntry * gdcmHeader::ReadNextElement(void);
129    friend class gdcmHeader;
130
131    /// Sets the depth level of a Dicom Header Entry embedded in a SeQuence 
132    inline void SetSQDepthLevel(int depthLevel) { SQDepthLevel = depthLevel; };
133       
134
135 protected:
136 // Variables
137
138    gdcmDictEntry *entry;
139    
140    /// \brief Updated from ReadLength, by FixFoungLentgh() for fixing a bug
141    /// in the header or helping the parser going on    
142    guint32 UsableLength; 
143   
144    /// \brief Length actually read on disk (before FixFoundLength). ReadLength
145    /// will be updated only when FixFoundLength actually fixes a bug in the
146    /// header, not when it performs a trick to help the Parser going on.
147    guint32 ReadLength;
148
149    /// \brief Even when reading explicit vr files, some elements happen to
150    /// be implicit. Flag them here since we can't use the entry->vr without
151    /// breaking the underlying dictionary.
152    bool ImplicitVR;
153
154    /// Offset from the begining of file for direct user access
155    size_t Offset; 
156
157    /// How many details are to be printed (value : 0,1,2)      
158    int printLevel;
159    
160    /// Gives the depth level of elements inside SeQuences   
161    int SQDepthLevel;
162 };
163
164 //-----------------------------------------------------------------------------
165 #endif