]> Creatis software - gdcm.git/blob - src/gdcmDocEntry.h
* Remove the Key information in Entry
[gdcm.git] / src / gdcmDocEntry.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDocEntry.h,v $
5   Language:  C++
6   Date:      $Date: 2005/10/19 13:17:04 $
7   Version:   $Revision: 1.52 $
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 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 Base
39 {
40 public:
41    DocEntry(DictEntry*);
42    /// \brief Canonical Destructor
43    virtual ~DocEntry() {}
44
45    virtual void Print (std::ostream &os = std::cout, std::string const &indent = ""); 
46    virtual void WriteContent(std::ofstream *fp, FileType filetype);
47
48    /// \brief  Gets the DicEntry of the current Dicom entry
49    /// @return The DicEntry of the current Dicom entry
50    DictEntry * GetDictEntry() { return DicomDict; } 
51
52    /// Returns the Dicom Group number of the current Dicom entry
53    const uint16_t &GetGroup() const   { return DicomDict->GetGroup();  }
54
55    /// Returns the Dicom Element number of the current Dicom entry
56    const uint16_t &GetElement() const { return DicomDict->GetElement();}
57
58    /// Returns the 'key' of the current Dicom entry
59    TagKey GetKey() const { return DicomDict->GetKey(); }
60
61    /// \brief Returns the 'Name' '(e.g. "Patient's Name") found in the Dicom
62    /// Dictionnary of the current Dicom Header Entry
63    std::string const &GetName() const { return DicomDict->GetName(); }
64
65    /// \brief Returns the 'Value Representation' (e.g. "PN" : Person Name,
66    /// "SL" : Signed Long), found in the Dicom header or in the Dicom
67    /// Dictionnary, of the current Dicom entry
68    VRKey const &GetVR() const { return DicomDict->GetVR(); }
69
70    /// \brief Returns the 'Value Multiplicity' (e.g. "1", "1-n", "6"),
71    /// found in the Dicom entry or in the Dicom Dictionnary
72    /// of the current Dicom entry
73    std::string const &GetVM() const { return DicomDict->GetVM(); }
74
75    /// Sets the 'Value Multiplicity' of the current Dicom entry
76    void SetVM( TagName const &v) { DicomDict->SetVM(v); } 
77
78    /// \brief Returns offset (since the beginning of the file, including
79    /// the File Preamble, if any) of the value of the current Dicom entry
80    /// \warning offset of the *value*, not of the Dicom entry
81    const size_t &GetOffset() const { return Offset; }
82
83    /// \brief Sets only 'Read Length' (*not* 'Usable Length') of the current
84    /// Dicom entry
85    void SetReadLength(uint32_t l) { ReadLength = l; }
86    /// \brief Returns the 'read length' of the current Dicom entry
87    /// \warning this value is the one stored in the Dicom header but not
88    ///          mandatoryly the one thats's used (in case on SQ, or delimiters,
89    ///          the usable length is set to zero)
90    const uint32_t &GetReadLength() const { return ReadLength; }
91
92    /// \brief Sets both 'Read Length' and 'Usable Length' of the current
93    /// Dicom entry
94    virtual void SetLength(uint32_t l) { Length = l; }
95    /// \brief Returns the actual value length of the current Dicom entry
96    /// \warning this value is not *always* the one stored in the Dicom header
97    ///          in case of well knowned bugs
98    const uint32_t &GetLength() const { return Length; }
99
100    uint32_t GetFullLength();
101
102 // The following 3 members, for internal use only ! 
103    /// \brief   Sets the offset of the Dicom entry
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 entry
109    void SetImplicitVR() { ImplicitVR = true; }
110  
111    /// \brief Tells us if the current Dicom entry was checked as ImplicitVr
112    /// @return true if the current Dicom entry was checked as ImplicitVr
113    bool IsImplicitVR() const { return ImplicitVR; }
114
115    /// \brief Tells us if the VR of the current Dicom entry is Unknown
116    /// @return true if the VR is unknown
117    bool IsVRUnknown() const { return DicomDict->IsVRUnknown(); }
118
119    /// \brief Tells us if the VM of the current Dicom entry is Unknown
120    /// @return true if the VM is unknown
121    bool IsVMUnknown() const { return DicomDict->IsVMUnknown(); }
122
123    bool IsItemDelimitor();
124    bool IsItemStarter();
125    bool IsSequenceDelimitor();   
126    
127    virtual void Copy(DocEntry *e);
128
129 protected:
130    /// \brief pointer to the underlying Dicom dictionary element
131    DictEntry *DicomDict;
132    
133    /// \brief Correspond to the real length of the data
134    /// This length might always be even
135    uint32_t Length; 
136   
137    /// \brief Length to read in the file to obtain data
138    uint32_t ReadLength;
139
140    /// \brief Even when reading explicit vr files, some elements happen to
141    /// be implicit. Flag them here since we can't use the entry->vr without
142    /// breaking the underlying dictionary.
143    bool ImplicitVR;
144
145    /// Offset from the beginning of file for direct user access
146    size_t Offset; 
147
148 private:
149 };
150 } // end namespace gdcm
151 //-----------------------------------------------------------------------------
152 #endif