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