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