1 /*=========================================================================
4 Module: $RCSfile: gdcmDocEntryArchive.cxx,v $
6 Date: $Date: 2005/10/24 16:00:47 $
7 Version: $Revision: 1.17 $
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 //-----------------------------------------------------------------------------
28 // Constructor / Destructor
32 DocEntryArchive::DocEntryArchive(File *file)
40 DocEntryArchive::~DocEntryArchive()
45 //-----------------------------------------------------------------------------
48 * \brief Replaces in the Header a DocEntry by the new DocEntry.
49 * The initial DocEntry is kept in archive.
50 * @param newEntry New entry to substitute to an other entry of the Header
51 * @return FALSE when an other DocEntry is already archived with the same key
54 bool DocEntryArchive::Push(DocEntry *newEntry)
59 uint16_t group = newEntry->GetDictEntry()->GetGroup();
60 uint16_t elem = newEntry->GetDictEntry()->GetElement();
61 TagKey key = DictEntry::TranslateToKey(group,elem);
63 if ( Archive.find(key) == Archive.end() )
65 // Save the old DocEntry if any
66 DocEntry *old = ArchFile->GetDocEntry(group, elem);
71 ArchFile->RemoveEntry(old);
74 // Set the new DocEntry
75 ArchFile->AddEntry(newEntry);
83 * \brief Removes out of the Header a DocEntry.
84 * (it's kept in archive).
85 * @param group Group number of the Entry to remove
86 * @param elem Element number of the Entry to remove
87 * @return FALSE when an other DocEntry is already archived with the same key
90 bool DocEntryArchive::Push(uint16_t group, uint16_t elem)
92 TagKey key = DictEntry::TranslateToKey(group, elem);
94 if ( Archive.find(key)==Archive.end() )
96 // Save the old DocEntry if any
97 DocEntry *old = ArchFile->GetDocEntry(group, elem);
102 ArchFile->RemoveEntry(old);
111 * \brief Restore in the Header the DocEntry specified by (group,element).
112 * The archive entry is destroyed.
113 * @param group Group number of the Entry to restore
114 * @param elem Element number of the Entry to restore
115 * @return FALSE when the key isn't in the archive,
118 bool DocEntryArchive::Restore(uint16_t group, uint16_t elem)
120 TagKey key=DictEntry::TranslateToKey(group, elem);
122 TagDocEntryHT::iterator restoreIt=Archive.find(key);
123 if ( restoreIt!=Archive.end() )
125 // Delete the new value
126 DocEntry *rem = ArchFile->GetDocEntry(group, elem);
129 ArchFile->RemoveEntry(rem);
132 // Restore the old value
133 if ( restoreIt->second )
135 ArchFile->AddEntry(restoreIt->second);
136 restoreIt->second->Unregister();
139 Archive.erase(restoreIt);
147 * \brief Removes all DocEntry from the archive, and destroy them.
148 * The archives entries aren't restored.
150 void DocEntryArchive::ClearArchive( )
152 for(TagDocEntryHT::iterator it = Archive.begin();
157 it->second->Unregister();
162 //-----------------------------------------------------------------------------
165 //-----------------------------------------------------------------------------
168 //-----------------------------------------------------------------------------
172 * @param os The output stream to be written to.
174 void DocEntryArchive::Print(std::ostream &os)
176 os << "Elements in archives :" << std::endl;
177 for(TagDocEntryHT::iterator it = Archive.begin();
182 it->second->Print(os);
186 //-----------------------------------------------------------------------------
187 } // end namespace gdcm