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