1 /*=========================================================================
4 Module: $RCSfile: gdcmElementSet.cxx,v $
6 Date: $Date: 2004/11/16 13:20:34 $
7 Version: $Revision: 1.29 $
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;
53 // Because the gdcmFile links the datas of gdcmPixelConvert with the
54 // data in a binArea, these datas are deleted 2 times... very bad...
55 //delete entryToDelete;
62 //-----------------------------------------------------------------------------
66 //-----------------------------------------------------------------------------
69 * \brief Prints the Header Entries (Dicom Elements)
73 void ElementSet::Print(std::ostream& os)
75 for( TagDocEntryHT::const_iterator i = TagHT.begin(); i != TagHT.end(); ++i)
77 DocEntry* entry = i->second;
79 if ( SeqEntry* seqEntry = dynamic_cast<SeqEntry*>(entry) )
82 // Avoid the newline for a sequence:
90 * \brief Writes the Header Entries (Dicom Elements)
94 void ElementSet::Write(std::ofstream* fp, FileType filetype)
96 for (TagDocEntryHT::const_iterator i = TagHT.begin();
100 i->second->Write(fp, filetype);
103 //-----------------------------------------------------------------------------
106 //-----------------------------------------------------------------------------
108 //-----------------------------------------------------------------------------
112 * \brief add a new Dicom Element pointer to the H Table
113 * @param newEntry entry to add
115 bool ElementSet::AddEntry(DocEntry* newEntry)
117 const TagKey& key = newEntry->GetKey();
119 if( TagHT.count(key) == 1 )
121 dbg.Verbose(1, "ElementSet::AddEntry key already present: ",
127 TagHT.insert(TagDocEntryHT::value_type(newEntry->GetKey(), newEntry));
133 * \brief Clear the hash table from given entry BUT keep the entry.
134 * @param entryToRemove Entry to remove.
136 bool ElementSet::RemoveEntryNoDestroy(DocEntry* entryToRemove)
138 const TagKey& key = entryToRemove->GetKey();
139 if( TagHT.count(key) == 1 )
142 dbg.Verbose(0, "ElementSet::RemoveEntry: one element erased.");
146 dbg.Verbose(0, "ElementSet::RemoveEntry: key not present: ");
151 * \brief Clear the hash table from given entry AND delete the entry.
152 * @param entryToRemove Entry to remove AND delete.
154 bool ElementSet::RemoveEntry( DocEntry* entryToRemove)
156 const TagKey& key = entryToRemove->GetKey();
157 if( TagHT.count(key) == 1 )
160 dbg.Verbose(0, "ElementSet::RemoveEntry: one element erased.");
161 delete entryToRemove;
165 dbg.Verbose(0, "ElementSet::RemoveEntry: key not present: ");
168 } // end namespace gdcm