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