1 /*=========================================================================
4 Module: $RCSfile: gdcmDocEntryArchive.cxx,v $
6 Date: $Date: 2005/01/26 11:42:02 $
7 Version: $Revision: 1.10 $
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 "gdcmDocEntryArchive.h"
20 #include "gdcmDebug.h"
21 #include "gdcmDocEntry.h"
27 //-----------------------------------------------------------------------------
31 DocEntryArchive::DocEntryArchive(File *file)
36 //-----------------------------------------------------------------------------
40 DocEntryArchive::~DocEntryArchive()
45 //-----------------------------------------------------------------------------
49 * @param os The output stream to be written to.
51 void DocEntryArchive::Print(std::ostream &os)
53 os << "Elements in archives :" << std::endl;
54 for(TagDocEntryHT::iterator it = Archive.begin();
59 it->second->Print(os);
63 //-----------------------------------------------------------------------------
66 * \brief Replace in the Header a DocEntry by the new DocEntry. The last
67 * DocEntry is kept in archive
68 * @param newEntry New entry to substitute to an other entry of the Header
69 * @return FALSE when an other DocEntry is already archived with the same
70 * generalized key, TRUE otherwise
72 bool DocEntryArchive::Push(DocEntry *newEntry)
77 uint16_t group = newEntry->GetDictEntry()->GetGroup();
78 uint16_t elem = newEntry->GetDictEntry()->GetElement();
79 std::string key = DictEntry::TranslateToKey(group,elem);
81 if( Archive.find(key)==Archive.end() )
83 // Save the old DocEntry if any
84 DocEntry *old = ArchFile->GetDocEntry(group,elem);
87 ArchFile->RemoveEntryNoDestroy(old);
89 // Set the new DocEntry
90 ArchFile->AddEntry(newEntry);
92 /* // Save the old DocEntry if any
93 TagDocEntryHT::iterator it = HeaderHT.find(key);
94 if( it!=HeaderHT.end() )
96 Archive[key] = it->second;
103 // Set the new DocEntry
104 HeaderHT[key] = newEntry;*/
112 * \brief Replace in the Header a DocEntry by the new DocEntry. The last
113 * DocEntry is kept in archive
114 * @param group Group number of the Entry
115 * @param elem Element number of the Entry
116 * @return FALSE when an other DocEntry is already archived with the same
117 * generalized key, TRUE otherwise
119 bool DocEntryArchive::Push(uint16_t group,uint16_t elem)
121 std::string key = DictEntry::TranslateToKey(group,elem);
123 if( Archive.find(key)==Archive.end() )
125 // Save the old DocEntry if any
126 DocEntry *old = ArchFile->GetDocEntry(group,elem);
129 ArchFile->RemoveEntryNoDestroy(old);
131 /* // Save the old DocEntry if any
132 TagDocEntryHT::iterator it = HeaderHT.find(key);
133 if( it!=HeaderHT.end() )
135 Archive[key] = it->second;
145 * \brief Restore in the Header the DocEntry that have the generalized key.
146 * The old entry is destroyed.
147 * @param group Group number of the Entry
148 * @param elem Element number of the Entry
149 * @return FALSE when the generalized key isn't in the archive,
152 bool DocEntryArchive::Restore(uint16_t group,uint16_t elem)
154 std::string key=DictEntry::TranslateToKey(group,elem);
156 TagDocEntryHT::iterator restoreIt=Archive.find(key);
157 if( restoreIt!=Archive.end() )
159 // Delete the new value
160 DocEntry *rem = ArchFile->GetDocEntry(group,elem);
162 ArchFile->RemoveEntry(rem);
164 // Restore the old value
166 ArchFile->AddEntry(Archive[key]);
168 /* // Delete the new value
169 TagDocEntryHT::iterator restorePos = HeaderHT.find(key);
170 if( restorePos!=HeaderHT.end() )
172 delete restorePos->second;
175 // Restore the old value
178 HeaderHT[key] = Archive[key];
182 HeaderHT.erase(restorePos);
185 Archive.erase(restoreIt);
193 * \brief Remove all DocEntry that are in the archive.
194 * The entries aren't restored but only destroyed.
196 void DocEntryArchive::ClearArchive( )
198 for(TagDocEntryHT::iterator it = Archive.begin();
207 //-----------------------------------------------------------------------------
210 //-----------------------------------------------------------------------------
213 //-----------------------------------------------------------------------------
215 } // end namespace gdcm