1 /*=========================================================================
4 Module: $RCSfile: gdcmElementSet.cxx,v $
6 Date: $Date: 2005/01/20 11:37:37 $
7 Version: $Revision: 1.47 $
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.
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.
17 =========================================================================*/
19 #include "gdcmElementSet.h"
20 #include "gdcmDebug.h"
21 #include "gdcmValEntry.h"
22 #include "gdcmBinEntry.h"
23 #include "gdcmSeqEntry.h"
28 //-----------------------------------------------------------------------------
29 // Constructor / Destructor
31 * \brief Constructor from a given ElementSet
33 //BOZ depthLevel is not usefull anymore
34 ElementSet::ElementSet(int depthLevel)
41 * \brief Canonical destructor.
43 ElementSet::~ElementSet()
45 for(TagDocEntryHT::iterator cc = TagHT.begin();cc != TagHT.end(); ++cc)
55 //-----------------------------------------------------------------------------
58 * \brief Prints the Header Entries (Dicom Elements)
60 * @param os ostream to write to
61 * @param indent Indentation string to be prepended during printing
63 void ElementSet::Print(std::ostream &os, std::string const & )
65 for( TagDocEntryHT::const_iterator i = TagHT.begin(); i != TagHT.end(); ++i)
67 DocEntry* entry = i->second;
69 entry->SetPrintLevel(PrintLevel);
72 if ( dynamic_cast<SeqEntry*>(entry) )
74 // Avoid the newline for a sequence:
81 //-----------------------------------------------------------------------------
84 * \brief Writes the Header Entries (Dicom Elements)
86 * @param fp ofstream to write to
87 * @param filetype filetype
89 void ElementSet::WriteContent(std::ofstream *fp, FileType filetype)
91 for (TagDocEntryHT::const_iterator i = TagHT.begin();
95 i->second->WriteContent(fp, filetype);
101 * \brief retrieves a Dicom Element using (group, element)
102 * @param group Group number of the searched Dicom Element
103 * @param elem Element number of the searched Dicom Element
106 DocEntry *ElementSet::GetDocEntry(uint16_t group, uint16_t elem)
108 TagKey key = DictEntry::TranslateToKey(group, elem);
109 if ( !TagHT.count(key))
113 return TagHT.find(key)->second;
117 * \brief Same as \ref Document::GetDocEntry except it only
118 * returns a result when the corresponding entry is of type
120 * @param group Group number of the searched Dicom Element
121 * @param elem Element number of the searched Dicom Element
122 * @return When present, the corresponding ValEntry.
124 ValEntry *ElementSet::GetValEntry(uint16_t group, uint16_t elem)
126 DocEntry *currentEntry = GetDocEntry(group, elem);
131 if ( ValEntry *entry = dynamic_cast<ValEntry*>(currentEntry) )
135 gdcmVerboseMacro( "Unfound ValEntry.");
141 * \brief Same as \ref Document::GetDocEntry except it only
142 * returns a result when the corresponding entry is of type
144 * @param group Group number of the searched Dicom Element
145 * @param elem Element number of the searched Dicom Element
146 * @return When present, the corresponding BinEntry.
148 BinEntry *ElementSet::GetBinEntry(uint16_t group, uint16_t elem)
150 DocEntry *currentEntry = GetDocEntry(group, elem);
155 if ( BinEntry *entry = dynamic_cast<BinEntry*>(currentEntry) )
159 gdcmVerboseMacro( "Unfound BinEntry.");
165 * \brief Same as \ref Document::GetDocEntry except it only
166 * returns a result when the corresponding entry is of type
168 * @param group Group number of the searched Dicom Element
169 * @param elem Element number of the searched Dicom Element
170 * @return When present, the corresponding SeqEntry.
172 SeqEntry *ElementSet::GetSeqEntry(uint16_t group, uint16_t elem)
174 DocEntry *currentEntry = GetDocEntry(group, elem);
179 if ( SeqEntry *entry = dynamic_cast<SeqEntry*>(currentEntry) )
183 gdcmVerboseMacro( "Unfound SeqEntry.");
189 //-----------------------------------------------------------------------------
192 //-----------------------------------------------------------------------------
196 * \brief add a new Dicom Element pointer to the H Table
197 * @param newEntry entry to add
199 bool ElementSet::AddEntry(DocEntry *newEntry)
201 const TagKey &key = newEntry->GetKey();
203 if( TagHT.count(key) == 1 )
205 gdcmVerboseMacro( "Key already present: " << key.c_str());
210 TagHT.insert(TagDocEntryHT::value_type(newEntry->GetKey(), newEntry));
216 * \brief Clear the hash table from given entry AND delete the entry.
217 * @param entryToRemove Entry to remove AND delete.
219 bool ElementSet::RemoveEntry( DocEntry *entryToRemove)
221 const TagKey &key = entryToRemove->GetKey();
222 if( TagHT.count(key) == 1 )
225 //gdcmVerboseMacro( "One element erased.");
226 delete entryToRemove;
230 gdcmVerboseMacro( "Key not present");
235 * \brief Clear the hash table from given entry BUT keep the entry.
236 * @param entryToRemove Entry to remove.
238 bool ElementSet::RemoveEntryNoDestroy(DocEntry *entryToRemove)
240 const TagKey &key = entryToRemove->GetKey();
241 if( TagHT.count(key) == 1 )
244 //gdcmVerboseMacro( "One element erased.");
248 gdcmVerboseMacro( "Key not present");
253 * \brief Get the first entry while visiting the DocEntrySet
254 * \return The first DocEntry if found, otherwhise NULL
256 DocEntry *ElementSet::GetFirstEntry()
258 ItTagHT = TagHT.begin();
259 if (ItTagHT != TagHT.end())
260 return ItTagHT->second;
265 * \brief Get the next entry while visiting the Hash table (TagHT)
266 * \note : meaningfull only if GetFirstEntry already called
267 * \return The next DocEntry if found, otherwhise NULL
269 DocEntry *ElementSet::GetNextEntry()
271 gdcmAssertMacro (ItTagHT != TagHT.end());
274 if (ItTagHT != TagHT.end())
275 return ItTagHT->second;
279 //-----------------------------------------------------------------------------
280 } // end namespace gdcm