1 /*=========================================================================
4 Module: $RCSfile: gdcmElementSet.cxx,v $
6 Date: $Date: 2004/12/16 11:37:02 $
7 Version: $Revision: 1.34 $
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
32 * \brief Constructor from a given ElementSet
34 //BOZ depthLevel is not usefull anymore
35 ElementSet::ElementSet(int depthLevel)
43 * \brief Canonical destructor.
45 ElementSet::~ElementSet()
47 for(TagDocEntryHT::iterator cc = TagHT.begin();cc != TagHT.end(); ++cc)
57 //-----------------------------------------------------------------------------
60 * \brief Prints the Header Entries (Dicom Elements)
64 void ElementSet::Print(std::ostream& os)
66 for( TagDocEntryHT::const_iterator i = TagHT.begin(); i != TagHT.end(); ++i)
68 DocEntry* entry = i->second;
70 if ( SeqEntry* seqEntry = dynamic_cast<SeqEntry*>(entry) )
73 // Avoid the newline for a sequence:
80 //-----------------------------------------------------------------------------
83 * \brief Writes the Header Entries (Dicom Elements)
87 void ElementSet::WriteContent(std::ofstream* fp, FileType filetype)
89 for (TagDocEntryHT::const_iterator i = TagHT.begin();
93 i->second->WriteContent(fp, filetype);
97 //-----------------------------------------------------------------------------
100 //-----------------------------------------------------------------------------
104 * \brief add a new Dicom Element pointer to the H Table
105 * @param newEntry entry to add
107 bool ElementSet::AddEntry(DocEntry* newEntry)
109 const TagKey& key = newEntry->GetKey();
111 if( TagHT.count(key) == 1 )
113 dbg.Verbose(1, "ElementSet::AddEntry key already present: ",
119 TagHT.insert(TagDocEntryHT::value_type(newEntry->GetKey(), newEntry));
125 * \brief Clear the hash table from given entry AND delete the entry.
126 * @param entryToRemove Entry to remove AND delete.
127 * \warning Some problems when using under Windows... prefer the use of
128 * Initialize / GetNext methods
130 bool ElementSet::RemoveEntry( DocEntry* entryToRemove)
132 const TagKey& key = entryToRemove->GetKey();
133 if( TagHT.count(key) == 1 )
136 dbg.Verbose(0, "ElementSet::RemoveEntry: one element erased.");
137 delete entryToRemove;
141 dbg.Verbose(0, "ElementSet::RemoveEntry: 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 dbg.Verbose(0, "ElementSet::RemoveEntry: one element erased.");
159 dbg.Verbose(0, "ElementSet::RemoveEntry: key not present");
164 * \brief Initialise the visit of the Hash table (TagHT)
166 void ElementSet::Initialize()
168 ItTagHT = TagHT.begin();
172 * \brief Get the next entry whil visiting the Hash table (TagHT)
173 * \return The next DocEntry if found, otherwhise NULL
175 DocEntry *ElementSet::GetNextEntry()
177 if (ItTagHT != TagHT.end())
179 DocEntry *tmp = ItTagHT->second;
190 //-----------------------------------------------------------------------------
191 } // end namespace gdcm