]> Creatis software - gdcm.git/blob - src/gdcmDocEntry.h
Fix mistypings
[gdcm.git] / src / gdcmDocEntry.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDocEntry.h,v $
5   Language:  C++
6   Date:      $Date: 2007/09/17 12:16:02 $
7   Version:   $Revision: 1.71 $
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_NAME_SPACE 
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                              bool insideMetaElements, bool insideSequence);
46
47    /// \brief  Gets the DicEntry of the current Dicom entry
48    /// @return The DicEntry of the current Dicom entry
49    DictEntry * GetDictEntry() { return DicomDict; } 
50
51    /// Returns the Dicom Group number of the current Dicom entry
52    uint16_t const &GetGroup() const   { return Key[0];  }
53    //const uint16_t &GetGroup() const   { return DicomDict->GetGroup();  }
54
55    /// Returns the Dicom Element number of the current Dicom entry
56    uint16_t const &GetElement() const { return Key[1];}   
57    //const uint16_t &GetElement() const { return DicomDict->GetElement();}
58
59    /// Returns the 'key' of the current Dicom entry
60    TagKey const &GetKey() const { return Key; }   
61    //TagKey GetKey() const { return DicomDict->GetKey(); }
62
63    /// \brief Returns the 'Name' '(e.g. "Patient's Name") found in the Dicom
64    /// Dictionnary of the current Dicom Header Entry
65    std::string const &GetName();
66
67    /// \brief Returns the 'Value Representation' (e.g. "PN" : Person Name,
68    /// "SL" : Signed Long), found in the Dicom header or in the Dicom
69    /// Dictionnary, of the current Dicom entry
70    VRKey const &GetVR() const { return VR; }   
71    //VRKey const &GetVR() const { return DicomDict->GetVR(); }
72
73    /// \brief Returns the 'Value Multiplicity' (e.g. "1", "6", "1-n", "3-n"),
74    /// found in the Dicom entry or in the Dicom Dictionnary
75    /// of the current Dicom entry
76    std::string const &GetVM();
77
78    /// Sets the 'Value Multiplicity' of the current Dicom entry
79    //void SetVM( TagName const &v) { DicomDict->SetVM(v); } 
80    void SetVM( TagName &) { std::cout << "-----------------FIXME : SetVM "; }
81     
82    /// \brief Returns offset (since the beginning of the file, including
83    /// the File Preamble, if any) of the value of the current Dicom entry
84    /// \warning offset of the *value*, not of the Dicom entry
85    const size_t &GetOffset() const { return Offset; }
86
87    /// \brief Sets only 'Read Length' (*not* 'Usable Length') of the current
88    /// Dicom entry
89    void SetReadLength(uint32_t l) { ReadLength = l; }
90    /// \brief Returns the 'read length' of the current Dicom entry
91    /// \warning this value is the one stored in the Dicom header but not
92    ///          mandatoryly the one thats's used (in case of SQ, or delimiters,
93    ///          the usable length is set to zero)
94    const uint32_t &GetReadLength() const { return ReadLength; }
95
96    /// \brief Sets both 'Read Length' and 'Usable Length' of the current
97    /// Dicom entry
98    virtual void SetLength(uint32_t l) { Length = l; }
99    /// \brief Returns the actual value length of the current Dicom entry
100    /// \warning this value is not *always* the one stored in the Dicom header
101    ///          in case of well known bugs
102    const uint32_t &GetLength() const { return Length; }
103
104    uint32_t GetFullLength();
105    virtual uint32_t ComputeFullLength() = 0;
106
107 // The following members, for internal use only !
108
109    /// \brief   Sets the offset of the Dicom entry
110    /// \warning use with caution !
111    /// @param   of offset to be set
112    void SetOffset(size_t of) { Offset = of; }
113
114    /// Sets to TRUE the ImplicitVr flag of the current Dicom entry
115    void SetImplicitVR() { ImplicitVR = true; }
116  
117     /// Sets the 'Value Representation' of the current Dicom entry
118    /// @param   vr VR to be set    
119    void SetVR( VRKey const &vr) { VR = vr; } 
120
121     /// Sets the 'Value Representation' of the current Dicom entry
122    /// @param   key TagKey to be set
123    void SetTag( TagKey const &key) { Key = key; } 
124   
125 // -----------end of members to be used with caution
126    
127    /// \brief Tells us if the current Dicom entry was checked as ImplicitVr
128    /// @return true if the current Dicom entry was checked as ImplicitVr
129    bool IsImplicitVR() const { return ImplicitVR; }
130
131    /// \brief Tells us if the VR of the current Dicom entry is Unknown
132    /// @return true if the VR is unknown
133 //   bool IsVRUnknown() const { return DicomDict->IsVRUnknown(); }
134      bool IsVRUnknown() const { return VR == GDCM_VRUNKNOWN; }
135
136    /// \brief Tells us if the VM of the current Dicom entry is Unknown
137    /// @return true if the VM is unknown
138 //   bool IsVMUnknown() const { return DicomDict->IsVMUnknown(); }
139    bool IsVMUnknown() { return GetVM() == GDCM_UNKNOWN; }
140
141 /// \brief   tells us if entry is the last one of a 'no length' SequenceItem 
142 ///        (fffe,e00d) 
143    bool IsItemDelimitor() 
144                       {return (GetGroup() == 0xfffe && GetElement() == 0xe00d);}
145 ///\brief   tells us if entry is the last one of a 'no length' Sequence 
146 ///         (fffe,e0dd)       
147    bool IsItemStarter(){ if (GetGroup() != 0xfffe) return false;
148                          return (GetElement() == 0xe000); }
149  /// \brief   tells us if entry is the last one of a 'no length' Sequence 
150  ///          (fffe,e0dd) 
151    bool IsSequenceDelimitor() { return (GetGroup() == 0xfffe && GetElement() == 0xe0dd);}  
152
153    virtual void Copy(DocEntry *doc);
154
155 protected:
156   // DocEntry(DictEntry*);
157    DocEntry(uint16_t group, uint16_t elem, VRKey const &vr);
158    virtual ~DocEntry();
159
160    /// \brief pointer to the underlying Dicom dictionary element
161    DictEntry *DicomDict;
162       
163    /// \brief Corresponds to the real length of the data
164    /// This length might always be even
165    uint32_t Length; 
166   
167    /// \brief Length to read in the file to obtain data
168    uint32_t ReadLength;
169
170    /// \brief Even when reading explicit vr files, some elements happen to
171    /// be implicit. Flag them here since we can't use the entry->vr without
172    /// breaking the underlying dictionary.
173    bool ImplicitVR;
174
175    /// Offset from the beginning of file for direct user access
176    size_t Offset; 
177
178    /// \brief Value Representation (to avoid accessing Dicom Dict every time!)
179    VRKey VR; // JPRx
180       
181    /// \brief Dicom TagKey. Contains Dicom Group number and Dicom Element number
182    ///        (to avoid accessing Dicom Dict every time !) // JPRx
183    TagKey Key; // JPRx
184 private:
185
186 };
187 } // end namespace gdcm
188 //-----------------------------------------------------------------------------
189 #endif