1 /*=========================================================================
4 Module: $RCSfile: gdcmElementSet.cxx,v $
6 Date: $Date: 2005/01/16 04:50:41 $
7 Version: $Revision: 1.42 $
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, std::string const & )
66 for( TagDocEntryHT::const_iterator i = TagHT.begin(); i != TagHT.end(); ++i)
68 DocEntry* entry = i->second;
70 entry->SetPrintLevel(PrintLevel);
73 if ( SeqEntry *seqEntry = dynamic_cast<SeqEntry*>(entry) )
76 // Avoid the newline for a sequence:
83 //-----------------------------------------------------------------------------
86 * \brief Writes the Header Entries (Dicom Elements)
90 void ElementSet::WriteContent(std::ofstream *fp, FileType filetype)
92 for (TagDocEntryHT::const_iterator i = TagHT.begin();
96 i->second->WriteContent(fp, filetype);
100 //-----------------------------------------------------------------------------
103 //-----------------------------------------------------------------------------
107 * \brief add a new Dicom Element pointer to the H Table
108 * @param newEntry entry to add
110 bool ElementSet::AddEntry(DocEntry *newEntry)
112 const TagKey &key = newEntry->GetKey();
114 if( TagHT.count(key) == 1 )
116 gdcmVerboseMacro( "Key already present: " << key.c_str());
121 TagHT.insert(TagDocEntryHT::value_type(newEntry->GetKey(), newEntry));
127 * \brief Clear the hash table from given entry AND delete the entry.
128 * @param entryToRemove Entry to remove AND delete.
129 * \warning Some problems when using under Windows... prefer the use of
130 * Initialize / GetNext methods
132 bool ElementSet::RemoveEntry( DocEntry *entryToRemove)
134 const TagKey &key = entryToRemove->GetKey();
135 if( TagHT.count(key) == 1 )
138 gdcmVerboseMacro( "One element erased.");
139 delete entryToRemove;
143 gdcmVerboseMacro( "Key not present");
148 * \brief Clear the hash table from given entry BUT keep the entry.
149 * @param entryToRemove Entry to remove.
151 bool ElementSet::RemoveEntryNoDestroy(DocEntry *entryToRemove)
153 const TagKey &key = entryToRemove->GetKey();
154 if( TagHT.count(key) == 1 )
157 gdcmVerboseMacro( "One element erased.");
161 gdcmVerboseMacro( "Key not present");
166 * \brief Initialise the visit of the Hash table (TagHT)
168 void ElementSet::InitTraversal()
170 ItTagHT = TagHT.begin();
174 * \brief Get the next entry whil visiting the Hash table (TagHT)
175 * \return The next DocEntry if found, otherwhise NULL
177 DocEntry *ElementSet::GetNextEntry()
179 if (ItTagHT != TagHT.end())
181 DocEntry *tmp = ItTagHT->second;
192 //-----------------------------------------------------------------------------
193 } // end namespace gdcm