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