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