1 /*=========================================================================
4 Module: $RCSfile: gdcmElementSet.cxx,v $
6 Date: $Date: 2005/10/24 16:00:47 $
7 Version: $Revision: 1.67 $
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 "gdcmSeqEntry.h"
22 #include "gdcmDataEntry.h"
26 //-----------------------------------------------------------------------------
27 // Constructor / Destructor
29 * \brief Constructor for a given ElementSet
31 ElementSet::ElementSet()
37 * \brief Canonical destructor.
39 ElementSet::~ElementSet()
44 //-----------------------------------------------------------------------------
47 * \brief Writes the Header Entries (Dicom Elements)
49 * @param fp ofstream to write to
50 * @param filetype filetype
52 void ElementSet::WriteContent(std::ofstream *fp, FileType filetype)
54 for (TagDocEntryHT::const_iterator i = TagHT.begin();
58 i->second->WriteContent(fp, filetype);
63 * \brief add a new Dicom Element pointer to the H Table
64 * @param newEntry entry to add
66 bool ElementSet::AddEntry(DocEntry *newEntry)
68 const TagKey &key = newEntry->GetKey();
70 if ( TagHT.count(key) == 1 )
72 gdcmWarningMacro( "Key already present: " << key );
77 TagHT.insert(TagDocEntryHT::value_type(newEntry->GetKey(), newEntry));
84 * \brief Clear the hash table from given entry AND delete the entry.
85 * @param entryToRemove Entry to remove AND delete.
87 bool ElementSet::RemoveEntry( DocEntry *entryToRemove)
89 const TagKey &key = entryToRemove->GetKey();
90 if ( TagHT.count(key) == 1 )
93 entryToRemove->Unregister();
97 gdcmWarningMacro( "Key not present : " << key);
102 * \brief delete all entries in the ElementSet
104 void ElementSet::ClearEntry()
106 for(TagDocEntryHT::iterator cc = TagHT.begin();cc != TagHT.end(); ++cc)
110 cc->second->Unregister();
117 * \brief Get the first entry while visiting *the* 'zero level' DocEntrySet
118 * (DocEntries out of any Sequence)
119 * \return The first DocEntry if found, otherwhise NULL
121 DocEntry *ElementSet::GetFirstEntry()
123 ItTagHT = TagHT.begin();
124 if (ItTagHT != TagHT.end())
125 return ItTagHT->second;
130 * \brief Get the next entry while visiting *the* 'zero level' DocEntrySet
131 * (DocEntries out of any Sequence)
132 * \note : meaningfull only if GetFirstEntry already called
133 * \return The next DocEntry if found, otherwhise NULL
135 DocEntry *ElementSet::GetNextEntry()
137 gdcmAssertMacro (ItTagHT != TagHT.end());
140 if (ItTagHT != TagHT.end())
141 return ItTagHT->second;
146 * \brief retrieves a Dicom Element using (group, element)
147 * @param group Group number of the searched Dicom Element
148 * @param elem Element number of the searched Dicom Element
151 DocEntry *ElementSet::GetDocEntry(uint16_t group, uint16_t elem)
153 TagKey key = DictEntry::TranslateToKey(group, elem);
154 TagDocEntryHT::iterator it = TagHT.find(key);
156 if ( it!=TagHT.end() )
161 //-----------------------------------------------------------------------------
164 //-----------------------------------------------------------------------------
167 //-----------------------------------------------------------------------------
170 * \brief Prints the Header Entries (Dicom Elements) from the H Table
171 * @param os ostream to write to
172 * @param indent Indentation string to be prepended during printing
174 void ElementSet::Print(std::ostream &os, std::string const & )
176 // Let's change the 'warning value' for Pixel Data,
177 // to avoid human reader to be confused by 'gdcm::NotLoaded'.
178 DataEntry *pixelElement = GetDataEntry(0x7fe0,0x0010);
179 if ( pixelElement != 0 )
181 pixelElement->SetFlag( DataEntry::FLAG_PIXELDATA );
184 for( TagDocEntryHT::const_iterator i = TagHT.begin(); i != TagHT.end(); ++i)
186 DocEntry *entry = i->second;
188 entry->SetPrintLevel(PrintLevel);
191 if ( dynamic_cast<SeqEntry *>(entry) )
193 // Avoid the newline for a sequence:
200 //-----------------------------------------------------------------------------
201 } // end namespace gdcm