]> Creatis software - gdcm.git/blob - src/gdcmDocEntry.h
To speed up the parsing process (avoid accessing HTable when useless):
[gdcm.git] / src / gdcmDocEntry.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDocEntry.h,v $
5   Language:  C++
6   Date:      $Date: 2006/03/22 13:19:25 $
7   Version:   $Revision: 1.61 $
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 "gdcmRefCounter.h"
23 #include "gdcmDictEntry.h"
24
25 #include <iostream>
26 #include <fstream>
27
28 namespace gdcm 
29 {
30 class File;
31 class SeqEntry;
32
33 //-----------------------------------------------------------------------------
34 /**
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 DocEntry : public RefCounter
39 {
40    gdcmTypeMacro(DocEntry);
41
42 public:
43    virtual void Print (std::ostream &os = std::cout, std::string const &indent = ""); 
44    virtual void WriteContent(std::ofstream *fp, FileType filetype);
45
46    /// \brief  Gets the DicEntry of the current Dicom entry
47    /// @return The DicEntry of the current Dicom entry
48    DictEntry * GetDictEntry() { return DicomDict; } 
49
50    /// Returns the Dicom Group number of the current Dicom entry
51    const uint16_t GetGroup() const   { return Key.GetGroup();  }
52    //const uint16_t &GetGroup() const   { return DicomDict->GetGroup();  }
53
54    /// Returns the Dicom Element number of the current Dicom entry
55    const uint16_t GetElement() const { return Key.GetElement();}   
56    //const uint16_t &GetElement() const { return DicomDict->GetElement();}
57
58    /// Returns the 'key' of the current Dicom entry
59    TagKey GetKey() const { return Key; }   
60    //TagKey GetKey() const { return DicomDict->GetKey(); }
61
62    /// \brief Returns the 'Name' '(e.g. "Patient's Name") found in the Dicom
63    /// Dictionnary of the current Dicom Header Entry
64    std::string const &GetName() const { return DicomDict->GetName(); }
65
66    /// \brief Returns the 'Value Representation' (e.g. "PN" : Person Name,
67    /// "SL" : Signed Long), found in the Dicom header or in the Dicom
68    /// Dictionnary, of the current Dicom entry
69    VRKey const &GetVR() const { return VR; }   
70    //VRKey const &GetVR() const { return DicomDict->GetVR(); }
71
72    /// \brief Returns the 'Value Multiplicity' (e.g. "1", "6", "1-n", "3-n"),
73    /// found in the Dicom entry or in the Dicom Dictionnary
74    /// of the current Dicom entry
75    std::string const &GetVM() const { return DicomDict->GetVM(); }
76
77    /// Sets the 'Value Multiplicity' of the current Dicom entry
78    void SetVM( TagName const &v) { DicomDict->SetVM(v); } 
79
80    /// \brief Returns offset (since the beginning of the file, including
81    /// the File Preamble, if any) of the value of the current Dicom entry
82    /// \warning offset of the *value*, not of the Dicom entry
83    const size_t &GetOffset() const { return Offset; }
84
85    /// \brief Sets only 'Read Length' (*not* 'Usable Length') of the current
86    /// Dicom entry
87    void SetReadLength(uint32_t l) { ReadLength = l; }
88    /// \brief Returns the 'read length' of the current Dicom entry
89    /// \warning this value is the one stored in the Dicom header but not
90    ///          mandatoryly the one thats's used (in case of SQ, or delimiters,
91    ///          the usable length is set to zero)
92    const uint32_t &GetReadLength() const { return ReadLength; }
93
94    /// \brief Sets both 'Read Length' and 'Usable Length' of the current
95    /// Dicom entry
96    virtual void SetLength(uint32_t l) { Length = l; }
97    /// \brief Returns the actual value length of the current Dicom entry
98    /// \warning this value is not *always* the one stored in the Dicom header
99    ///          in case of well known bugs
100    const uint32_t &GetLength() const { return Length; }
101
102    uint32_t GetFullLength();
103    virtual uint32_t ComputeFullLength() = 0;
104
105 // The following members, for internal use only !
106
107    /// \brief   Sets the offset of the Dicom entry
108    /// \warning use with caution !
109    /// @param   of offset to be set
110    void SetOffset(size_t of) { Offset = of; }
111
112    /// Sets to TRUE the ImplicitVr flag of the current Dicom entry
113    void SetImplicitVR() { ImplicitVR = true; }
114  
115     /// Sets the 'Value Representation' of the current Dicom entry
116    /// @param   vr VR to be set    
117    void SetVR( VRKey const &vr) { VR = vr; } 
118
119     /// Sets the 'Value Representation' of the current Dicom entry
120    /// @param   key TagKey to be set
121    void SetTag( TagKey const &key) { Key = key; } 
122   
123 // -----------end of members to be used with caution
124    
125    /// \brief Tells us if the current Dicom entry was checked as ImplicitVr
126    /// @return true if the current Dicom entry was checked as ImplicitVr
127    bool IsImplicitVR() const { return ImplicitVR; }
128
129    /// \brief Tells us if the VR of the current Dicom entry is Unknown
130    /// @return true if the VR is unknown
131    bool IsVRUnknown() const { return DicomDict->IsVRUnknown(); }
132
133    /// \brief Tells us if the VM of the current Dicom entry is Unknown
134    /// @return true if the VM is unknown
135    bool IsVMUnknown() const { return DicomDict->IsVMUnknown(); }
136
137    bool IsItemDelimitor();
138    bool IsItemStarter();
139    bool IsSequenceDelimitor();   
140
141    virtual void Copy(DocEntry *doc);
142
143 protected:
144    DocEntry(DictEntry*);
145    virtual ~DocEntry();
146
147    /// \brief pointer to the underlying Dicom dictionary element
148    DictEntry *DicomDict;
149       
150    /// \brief Corresponds to the real length of the data
151    /// This length might always be even
152    uint32_t Length; 
153   
154    /// \brief Length to read in the file to obtain data
155    uint32_t ReadLength;
156
157    /// \brief Even when reading explicit vr files, some elements happen to
158    /// be implicit. Flag them here since we can't use the entry->vr without
159    /// breaking the underlying dictionary.
160    bool ImplicitVR;
161
162    /// Offset from the beginning of file for direct user access
163    size_t Offset; 
164
165    /// \brief Value Representation (to avoid accessing Dicom Dict every time!)
166    VRKey VR; // JPRx
167       
168    /// \brief Dicom \ref TagKey. Contains Dicom Group number and Dicom Element number
169    ///        (to avoid accessing Dicom Dict every time !) // JPRx
170    TagKey Key; // JPRx
171 private:
172
173 };
174 } // end namespace gdcm
175 //-----------------------------------------------------------------------------
176 #endif