]> Creatis software - gdcm.git/blob - src/gdcmDocEntrySet.h
* Some classes inherit now from gdcm::RefCounter
[gdcm.git] / src / gdcmDocEntrySet.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDocEntrySet.h,v $
5   Language:  C++
6   Date:      $Date: 2005/10/25 14:52:34 $
7   Version:   $Revision: 1.62 $
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 "gdcmRefCounter.h"
23 #include "gdcmVRKey.h"
24 #include "gdcmTagKey.h"
25
26 #include <fstream>
27
28 namespace gdcm 
29 {
30 //-----------------------------------------------------------------------------
31 class DocEntry;
32 class DataEntry;
33 class SeqEntry;
34 class DictEntry;
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 RefCounter
60 {
61    gdcmTypeMacro(DocEntrySet);
62
63 public:
64    /// \brief write any type of entry to the entry set
65    virtual void WriteContent (std::ofstream *fp, FileType filetype) = 0;
66
67    /// \brief Remove all Entry in the entry set
68    virtual void ClearEntry() = 0;
69    /// \brief adds any type of entry to the entry set
70    virtual bool AddEntry(DocEntry *entry) = 0;
71    /// \brief Removes any type of entry out of the entry set, and destroys it
72    virtual bool RemoveEntry(DocEntry *entryToRemove) = 0;
73    /// Gets the first entry of any type of set
74    virtual DocEntry *GetFirstEntry()=0;
75    /// Gets the next entry of any type of set
76    virtual DocEntry *GetNextEntry()=0;
77
78    virtual std::string GetEntryString(uint16_t group, uint16_t elem);
79    virtual void *GetEntryBinArea(uint16_t group, uint16_t elem);
80    virtual int GetEntryLength(uint16_t group, uint16_t elem);
81    virtual std::string GetEntryForcedAsciiValue(uint16_t group, uint16_t elem);
82
83    /// \brief Gets any type of DocEntry, identified by its (group,elem)
84    virtual DocEntry *GetDocEntry(uint16_t group, uint16_t elem) = 0;
85    /// \brief Gets a DataEntry, identified by its (group, elem)
86    DataEntry *GetDataEntry(uint16_t group, uint16_t elem);
87    /// \brief Gets a SeqEntry, identified by its (group,elem)
88    SeqEntry *GetSeqEntry(uint16_t group, uint16_t elem);
89
90    bool SetEntryString(std::string const &content,
91                        uint16_t group, uint16_t elem);
92    bool SetEntryBinArea(uint8_t *content, int lgth,
93                         uint16_t group, uint16_t elem);
94    bool SetEntryString(std::string const &content, DataEntry *entry);
95    bool SetEntryBinArea(uint8_t *content, int lgth, DataEntry *entry);
96
97    DataEntry *InsertEntryString(std::string const &value,
98                                    uint16_t group, uint16_t elem,
99                                    VRKey const &vr = GDCM_VRUNKNOWN);
100    DataEntry *InsertEntryBinArea(uint8_t *binArea, int lgth,
101                                     uint16_t group, uint16_t elem,
102                                     VRKey const &vr = GDCM_VRUNKNOWN);
103    SeqEntry *InsertSeqEntry(uint16_t group, uint16_t elem);
104    /// tells us if the set contains no entry
105    virtual bool IsEmpty() = 0;
106    virtual bool CheckIfEntryExist(uint16_t group, uint16_t elem);
107
108 // DocEntry  related utilities 
109    DataEntry *NewDataEntry(uint16_t group,uint16_t elem,
110                          VRKey const &vr = GDCM_VRUNKNOWN);
111    SeqEntry *NewSeqEntry(uint16_t group, uint16_t elem);
112
113 protected:
114    /// Canonical Constructor
115    DocEntrySet();
116    /// Canonical Destructor
117    virtual ~DocEntrySet() {}
118
119 // DictEntry  related utilities
120    DictEntry *GetDictEntry(uint16_t group, uint16_t elem);
121    DictEntry *GetDictEntry(uint16_t group, uint16_t elem,
122                            VRKey const &vr);
123    /// To be able to backtrack (Private Sequence, Implicit VR related pb)
124    DocEntry *PreviousDocEntry;
125
126 private:
127 };
128
129 } // end namespace gdcm
130 //-----------------------------------------------------------------------------
131 #endif
132