1 /*=========================================================================
4 Module: $RCSfile: gdcmElementSet.cxx,v $
6 Date: $Date: 2004/11/16 10:37:54 $
7 Version: $Revision: 1.28 $
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)
49 DocEntry* entryToDelete = cc->second;
59 //-----------------------------------------------------------------------------
63 //-----------------------------------------------------------------------------
66 * \brief Prints the Header Entries (Dicom Elements)
70 void ElementSet::Print(std::ostream& os)
72 for( TagDocEntryHT::const_iterator i = TagHT.begin(); i != TagHT.end(); ++i)
74 DocEntry* entry = i->second;
76 if ( SeqEntry* seqEntry = dynamic_cast<SeqEntry*>(entry) )
79 // Avoid the newline for a sequence:
87 * \brief Writes the Header Entries (Dicom Elements)
91 void ElementSet::Write(std::ofstream* fp, FileType filetype)
93 for (TagDocEntryHT::const_iterator i = TagHT.begin();
97 i->second->Write(fp, filetype);
100 //-----------------------------------------------------------------------------
103 //-----------------------------------------------------------------------------
105 //-----------------------------------------------------------------------------
109 * \brief add a new Dicom Element pointer to the H Table
110 * @param newEntry entry to add
112 bool ElementSet::AddEntry(DocEntry* newEntry)
114 const TagKey& key = newEntry->GetKey();
116 if( TagHT.count(key) == 1 )
118 dbg.Verbose(1, "ElementSet::AddEntry key already present: ",
124 TagHT.insert(TagDocEntryHT::value_type(newEntry->GetKey(), newEntry));
130 * \brief Clear the hash table from given entry BUT keep the entry.
131 * @param entryToRemove Entry to remove.
133 bool ElementSet::RemoveEntryNoDestroy(DocEntry* entryToRemove)
135 const TagKey& key = entryToRemove->GetKey();
136 if( TagHT.count(key) == 1 )
139 dbg.Verbose(0, "ElementSet::RemoveEntry: one element erased.");
143 dbg.Verbose(0, "ElementSet::RemoveEntry: key not present: ");
148 * \brief Clear the hash table from given entry AND delete the entry.
149 * @param entryToRemove Entry to remove AND delete.
151 bool ElementSet::RemoveEntry( DocEntry* entryToRemove)
153 const TagKey& key = entryToRemove->GetKey();
154 if( TagHT.count(key) == 1 )
157 dbg.Verbose(0, "ElementSet::RemoveEntry: one element erased.");
158 delete entryToRemove;
162 dbg.Verbose(0, "ElementSet::RemoveEntry: key not present: ");
165 } // end namespace gdcm