]> Creatis software - gdcm.git/blob - src/gdcmDocEntry.h
Coding Style + Doxygenation
[gdcm.git] / src / gdcmDocEntry.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDocEntry.h,v $
5   Language:  C++
6   Date:      $Date: 2005/01/06 20:03:27 $
7   Version:   $Revision: 1.34 $
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 offset (since the beginning of the file, including
68    /// the File Preamble, if any) of the value of the current Dicom HeaderEntry
69    /// \warning offset of the *value*, not of the Dicom Header Entry
70    size_t GetOffset() { return Offset; };
71
72    /// \brief Returns the actual value length of the current Dicom Header Entry
73    /// \warning this value is not *always* the one stored in the Dicom Header
74    ///          in case of well knowned bugs
75    uint32_t GetLength() { return UsableLength; };
76     
77    /// \brief Returns the 'read length' of the current Dicom Header Entry
78    /// \warning this value is the one stored in the Dicom Header but not
79    ///          mandatoryly the one thats's used (in case on SQ, or delimiters,
80    ///          the usable length is set to zero)
81    uint32_t GetReadLength() { return ReadLength; };
82
83    /// Sets the 'Value Representation' of the current Dicom Header Entry
84    void SetVR( TagName const &v) { DicomDict->SetVR(v); };    
85
86    /// \brief Sets both 'Read Length' and 'Usable Length' of the current
87    /// Dicom Header Entry
88    void SetLength(uint32_t l) { ReadLength = UsableLength = l; };
89       
90    // The following 3 members, for internal use only ! 
91    
92    /// \brief Sets only 'Read Length' (*not* 'Usable Length') of the current
93    /// Dicom Header Entry
94    void SetReadLength(uint32_t l) { ReadLength = l; };
95
96    /// \brief Sets only 'Usable Length' (*not* 'Read Length') of the current
97    /// Dicom Header Entry
98    void SetUsableLength(uint32_t l) { UsableLength = l; }; 
99    
100    /// \brief   Sets the offset of the Dicom Element
101    /// \warning use with caution !
102    /// @param   of offset to be set
103    void SetOffset(size_t of) { Offset = of; };
104
105    /// Sets to TRUE the ImplicitVr flag of the current Dicom Element
106    void SetImplicitVR() { ImplicitVR = true; };
107  
108    /// \brief Tells us if the current Dicom Element was checked as ImplicitVr
109    /// @return true if the current Dicom Element was checked as ImplicitVr
110    bool IsImplicitVR() { return ImplicitVR; };
111
112    /// \brief Tells us if the VR of the current Dicom Element is Unknown
113    /// @return true if the VR is unknown
114    bool IsVRUnknown() { return DicomDict->IsVRUnknown(); };
115
116    /// \brief   Sets the DicEntry of the current Dicom Element
117    /// @param   newEntry pointer to the DictEntry
118    void SetDictEntry(DictEntry *newEntry) { DicomDict = newEntry; };
119
120    /// \brief  Gets the DicEntry of the current Dicom Element
121    /// @return The DicEntry of the current Dicom Element
122    DictEntry * GetDictEntry() { return DicomDict; }; 
123    
124    virtual void WriteContent(std::ofstream *fp, FileType filetype);
125    
126    uint32_t GetFullLength();
127    
128    void Copy(DocEntry *doc);
129
130    bool IsItemDelimitor();
131    bool IsSequenceDelimitor();   
132
133    virtual void Print (std::ostream &os = std::cout); 
134
135 private:
136    // FIXME: In fact we should be more specific and use :
137    // friend DocEntry * Header::ReadNextElement(void);
138    friend class Header;    
139
140 protected:
141 // Variables
142
143    /// \brief pointer to the underlying Dicom dictionary element
144    DictEntry *DicomDict;
145    
146    /// \brief Updated from ReadLength, by FixFoungLentgh() for fixing a bug
147    /// in the header or helping the parser going on    
148    uint32_t UsableLength; 
149   
150    /// \brief Length actually read on disk (before FixFoundLength). ReadLength
151    /// will be updated only when FixFoundLength actually fixes a bug in the
152    /// header, not when it performs a trick to help the Parser going on.
153    uint32_t ReadLength;
154
155    /// \brief Even when reading explicit vr files, some elements happen to
156    /// be implicit. Flag them here since we can't use the entry->vr without
157    /// breaking the underlying dictionary.
158    bool ImplicitVR;
159
160    /// Offset from the begining of file for direct user access
161    size_t Offset; 
162
163    /// \brief Generalized key of this DocEntry (for details on
164    ///        the generalized key refer to \ref TagKey documentation).
165    TagKey Key;
166 };
167 } // end namespace gdcm
168 //-----------------------------------------------------------------------------
169 #endif