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