1 /*=========================================================================
4 Module: $RCSfile: gdcmElementSet.cxx,v $
6 Date: $Date: 2005/02/07 08:48:18 $
7 Version: $Revision: 1.58 $
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"
27 //-----------------------------------------------------------------------------
28 // Constructor / Destructor
30 * \brief Constructor for a given ElementSet
32 //BOZ depthLevel is not usefull anymore
33 ElementSet::ElementSet(int depthLevel)
40 * \brief Canonical destructor.
42 ElementSet::~ElementSet()
47 //-----------------------------------------------------------------------------
50 * \brief Writes the Header Entries (Dicom Elements)
52 * @param fp ofstream to write to
53 * @param filetype filetype
55 void ElementSet::WriteContent(std::ofstream *fp, FileType filetype)
57 for (TagDocEntryHT::const_iterator i = TagHT.begin();
61 i->second->WriteContent(fp, filetype);
66 * \brief add a new Dicom Element pointer to the H Table
67 * @param newEntry entry to add
69 bool ElementSet::AddEntry(DocEntry *newEntry)
71 const TagKey &key = newEntry->GetKey();
73 if( TagHT.count(key) == 1 )
75 gdcmWarningMacro( "Key already present: " << key.c_str());
80 TagHT.insert(TagDocEntryHT::value_type(newEntry->GetKey(), newEntry));
86 * \brief Clear the hash table from given entry AND delete the entry.
87 * @param entryToRemove Entry to remove AND delete.
89 bool ElementSet::RemoveEntry( DocEntry *entryToRemove)
91 const TagKey &key = entryToRemove->GetKey();
92 if( TagHT.count(key) == 1 )
95 //gdcmWarningMacro( "One element erased.");
100 gdcmWarningMacro( "Key not present");
105 * \brief Clear the hash table from given entry BUT keep the entry.
106 * @param entryToRemove Entry to remove.
108 bool ElementSet::RemoveEntryNoDestroy(DocEntry *entryToRemove)
110 const TagKey &key = entryToRemove->GetKey();
111 if( TagHT.count(key) == 1 )
114 //gdcmWarningMacro( "One element erased.");
118 gdcmWarningMacro( "Key not present");
123 * \brief delete all entries in the ElementSet
125 void ElementSet::ClearEntry()
127 for(TagDocEntryHT::iterator cc = TagHT.begin();cc != TagHT.end(); ++cc)
138 * \brief Get the first entry while visiting *the* 'zero level' DocEntrySet
139 * (DocEntries out of any Sequence)
140 * \return The first DocEntry if found, otherwhise NULL
142 DocEntry *ElementSet::GetFirstEntry()
144 ItTagHT = TagHT.begin();
145 if (ItTagHT != TagHT.end())
146 return ItTagHT->second;
151 * \brief Get the next entry while visiting *the* 'zero level' DocEntrySet
152 * (DocEntries out of any Sequence)
153 * \note : meaningfull only if GetFirstEntry already called
154 * \return The next DocEntry if found, otherwhise NULL
156 DocEntry *ElementSet::GetNextEntry()
158 gdcmAssertMacro (ItTagHT != TagHT.end());
161 if (ItTagHT != TagHT.end())
162 return ItTagHT->second;
167 * \brief retrieves a Dicom Element using (group, element)
168 * @param group Group number of the searched Dicom Element
169 * @param elem Element number of the searched Dicom Element
172 DocEntry *ElementSet::GetDocEntry(uint16_t group, uint16_t elem)
174 TagKey key = DictEntry::TranslateToKey(group, elem);
175 TagDocEntryHT::iterator it = TagHT.find(key);
177 if ( it!=TagHT.end() )
182 //-----------------------------------------------------------------------------
185 //-----------------------------------------------------------------------------
188 //-----------------------------------------------------------------------------
191 * \brief Prints the Header Entries (Dicom Elements) from the H Table
192 * @param os ostream to write to
193 * @param indent Indentation string to be prepended during printing
195 void ElementSet::Print(std::ostream &os, std::string const & )
197 for( TagDocEntryHT::const_iterator i = TagHT.begin(); i != TagHT.end(); ++i)
199 DocEntry *entry = i->second;
201 entry->SetPrintLevel(PrintLevel);
204 if ( dynamic_cast<SeqEntry*>(entry) )
206 // Avoid the newline for a sequence:
213 //-----------------------------------------------------------------------------
214 } // end namespace gdcm