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