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