]> Creatis software - gdcm.git/blob - src/gdcmDocEntrySet.h
81425d0e9f5db6b199088340ba12bf9fb2230800
[gdcm.git] / src / gdcmDocEntrySet.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDocEntrySet.h,v $
5   Language:  C++
6   Date:      $Date: 2005/09/06 15:28:49 $
7   Version:   $Revision: 1.56 $
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 GDCMDOCENTRYSET_H
20 #define GDCMDOCENTRYSET_H
21
22 #include "gdcmBase.h"
23 #include <fstream>
24
25 namespace gdcm 
26 {
27 //-----------------------------------------------------------------------------
28 class DocEntry;
29 class ValEntry;
30 class BinEntry;
31 class SeqEntry;
32 class DictEntry;
33
34 typedef TagKey BaseTagKey;
35
36 //-----------------------------------------------------------------------------
37 /**
38  * \brief
39  * \ref DocEntrySet is an abstract base class for \ref ElementSet
40  * and \ref SQItem which are both containers for DocEntries.
41  *  - \ref ElementSet is based on the STL map<> container
42  * (see \ref ElementSet::TagHT)
43  *  - \ref SQItem is based on an STL list container (see \ref ListDocEntry).
44  * Since the syntax for adding a new element to a map<> or a list<>
45  * differ, \ref DocEntrySet is designed as an adapter to unify the
46  * interfaces of \ref DocEntrySet and \ref ElementSet.
47  * As an illustration of this design, please refer to the implementation
48  * of \ref AddEntry (or any pure virtual method) in both derived classes.
49  * This adapter unification of interfaces enables the parsing of a
50  * DICOM header containing (optionaly heavily nested) sequences to be
51  * written recursively [see \ref Document::ParseDES 
52  * which calls \ref Document::ParseSQ, which in turns calls 
53  * \ref Document::ParseDES ].
54  *
55  * \note Developpers should strongly resist to the temptation of adding
56  *       members to this class since this class is designed as an adapter 
57  *       in the form of an abstract base class.
58  */
59 class GDCM_EXPORT DocEntrySet : public Base
60 {
61 public:
62    /// Canonical Constructor
63    DocEntrySet();
64    /// Canonical Destructor
65    virtual ~DocEntrySet() {}
66
67    /// \brief write any type of entry to the entry set
68    virtual void WriteContent (std::ofstream *fp, FileType filetype) = 0;
69
70    /// \brief Remove all Entry in the entry set
71    virtual void ClearEntry() = 0;
72    /// \brief adds any type of entry to the entry set
73    virtual bool AddEntry(DocEntry *entry) = 0;
74    /// \brief Removes any type of entry out of the entry set, and destroys it
75    virtual bool RemoveEntry(DocEntry *entryToRemove) = 0;
76    /// \brief Removes any type of entry out of the entry set, DOESN'T destroy it
77    virtual bool RemoveEntryNoDestroy(DocEntry *entryToRemove) = 0;
78    /// Gets the first entry of any type of set
79    virtual DocEntry *GetFirstEntry()=0;
80    /// Gets the next entry of any type of set
81    virtual DocEntry *GetNextEntry()=0;
82
83    virtual std::string GetEntryValue(uint16_t group, uint16_t elem);
84    virtual void *GetEntryBinArea(uint16_t group, uint16_t elem);
85    
86    virtual int GetEntryLength(uint16_t group, uint16_t elem);
87    virtual std::string GetEntryVR(uint16_t group, uint16_t elem);
88    virtual std::string GetEntryForcedAsciiValue(uint16_t group, uint16_t elem);
89    /// \brief Gets any type of DocEntry, identified by its (group,elem)
90    virtual DocEntry *GetDocEntry(uint16_t group, uint16_t elem) = 0;
91    /// \brief Gets a ValEntry, identified by its (group, elem)
92    ValEntry *GetValEntry(uint16_t group, uint16_t elem);
93    /// \brief Gets a BinEntry, identified by its (group,elem)
94    BinEntry *GetBinEntry(uint16_t group, uint16_t elem);
95    /// \brief Gets a SeqEntry, identified by its (group,elem)
96    SeqEntry *GetSeqEntry(uint16_t group, uint16_t elem);
97
98    bool SetValEntry(std::string const &content,
99                             uint16_t group, uint16_t elem);
100    bool SetBinEntry(uint8_t *content, int lgth,
101                             uint16_t group, uint16_t elem);
102    bool SetValEntry(std::string const &content, ValEntry *entry);
103    bool SetBinEntry(uint8_t *content, int lgth, BinEntry *entry);
104
105    ValEntry *InsertValEntry(std::string const &value,
106                                     uint16_t group, uint16_t elem,
107                                     TagName const &vr = GDCM_UNKNOWN);
108    BinEntry *InsertBinEntry(uint8_t *binArea, int lgth,
109                                     uint16_t group, uint16_t elem,
110                                     TagName const &vr = GDCM_UNKNOWN);
111    SeqEntry *InsertSeqEntry(uint16_t group, uint16_t elem);
112    /// tells us if the set contains no entry
113    virtual bool IsEmpty() = 0;
114    virtual bool CheckIfEntryExist(uint16_t group, uint16_t elem);
115
116 // DocEntry  related utilities 
117    ValEntry *NewValEntry(uint16_t group,uint16_t elem,
118                          TagName const &vr = GDCM_UNKNOWN);
119    BinEntry *NewBinEntry(uint16_t group, uint16_t elem,
120                          TagName const &vr = GDCM_UNKNOWN);
121    SeqEntry *NewSeqEntry(uint16_t group, uint16_t elem);
122
123 // DictEntry  related utilities 
124    DictEntry *NewVirtualDictEntry(uint16_t group,uint16_t elem,
125                                   TagName const &vr     = GDCM_UNKNOWN,
126                                   TagName const &vm     = GDCM_UNKNOWN,
127                                   TagName const &name   = GDCM_UNKNOWN );
128
129 protected:
130 // DictEntry  related utilities
131    DictEntry *GetDictEntry(uint16_t group, uint16_t elem);
132    DictEntry *GetDictEntry(uint16_t group, uint16_t elem,
133                            TagName const &vr);
134    /// To be able to backtrack (Private Sequence, Implicit VR related pb)
135    DocEntry *PreviousDocEntry;
136
137 private:
138 };
139
140 } // end namespace gdcm
141 //-----------------------------------------------------------------------------
142 #endif
143