1 /*=========================================================================
4 Module: $RCSfile: gdcmElementSet.cxx,v $
6 Date: $Date: 2005/01/25 15:44:24 $
7 Version: $Revision: 1.51 $
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 for a given ElementSet
33 //BOZ depthLevel is not usefull anymore
34 ElementSet::ElementSet(int depthLevel)
41 * \brief Canonical destructor.
43 ElementSet::~ElementSet()
48 //-----------------------------------------------------------------------------
51 * \brief Prints the Header Entries (Dicom Elements) from the H Table
52 * @param os ostream to write to
53 * @param indent Indentation string to be prepended during printing
55 void ElementSet::Print(std::ostream &os, std::string const & )
57 for( TagDocEntryHT::const_iterator i = TagHT.begin(); i != TagHT.end(); ++i)
59 DocEntry* entry = i->second;
61 entry->SetPrintLevel(PrintLevel);
64 if ( dynamic_cast<SeqEntry*>(entry) )
66 // Avoid the newline for a sequence:
73 //-----------------------------------------------------------------------------
76 * \brief Writes the Header Entries (Dicom Elements)
78 * @param fp ofstream to write to
79 * @param filetype filetype
81 void ElementSet::WriteContent(std::ofstream *fp, FileType filetype)
83 for (TagDocEntryHT::const_iterator i = TagHT.begin();
87 i->second->WriteContent(fp, filetype);
92 * \brief delete all entries in the ElementSet
94 void ElementSet::ClearEntry()
96 for(TagDocEntryHT::iterator cc = TagHT.begin();cc != TagHT.end(); ++cc)
107 * \brief add a new Dicom Element pointer to the H Table
108 * @param newEntry entry to add
110 bool ElementSet::AddEntry(DocEntry *newEntry)
112 const TagKey &key = newEntry->GetKey();
114 if( TagHT.count(key) == 1 )
116 gdcmVerboseMacro( "Key already present: " << key.c_str());
121 TagHT.insert(TagDocEntryHT::value_type(newEntry->GetKey(), newEntry));
127 * \brief Clear the hash table from given entry AND delete the entry.
128 * @param entryToRemove Entry to remove AND delete.
130 bool ElementSet::RemoveEntry( DocEntry *entryToRemove)
132 const TagKey &key = entryToRemove->GetKey();
133 if( TagHT.count(key) == 1 )
136 //gdcmVerboseMacro( "One element erased.");
137 delete entryToRemove;
141 gdcmVerboseMacro( "Key not present");
146 * \brief Clear the hash table from given entry BUT keep the entry.
147 * @param entryToRemove Entry to remove.
149 bool ElementSet::RemoveEntryNoDestroy(DocEntry *entryToRemove)
151 const TagKey &key = entryToRemove->GetKey();
152 if( TagHT.count(key) == 1 )
155 //gdcmVerboseMacro( "One element erased.");
159 gdcmVerboseMacro( "Key not present");
164 * \brief Get the first entry while visiting the DocEntrySet
165 * \return The first DocEntry if found, otherwhise NULL
167 DocEntry *ElementSet::GetFirstEntry()
169 ItTagHT = TagHT.begin();
170 if (ItTagHT != TagHT.end())
171 return ItTagHT->second;
176 * \brief Get the next entry while visiting the Hash table (TagHT)
177 * \note : meaningfull only if GetFirstEntry already called
178 * \return The next DocEntry if found, otherwhise NULL
180 DocEntry *ElementSet::GetNextEntry()
182 gdcmAssertMacro (ItTagHT != TagHT.end());
185 if (ItTagHT != TagHT.end())
186 return ItTagHT->second;
191 * \brief retrieves a Dicom Element using (group, element)
192 * @param group Group number of the searched Dicom Element
193 * @param elem Element number of the searched Dicom Element
196 DocEntry *ElementSet::GetDocEntry(uint16_t group, uint16_t elem)
198 TagKey key = DictEntry::TranslateToKey(group, elem);
199 TagDocEntryHT::iterator it = TagHT.find(key);
201 if ( it!=TagHT.end() )
206 //-----------------------------------------------------------------------------
209 //-----------------------------------------------------------------------------
212 //-----------------------------------------------------------------------------
213 } // end namespace gdcm