1 /*=========================================================================
4 Module: $RCSfile: gdcmDocEntryArchive.cxx,v $
6 Date: $Date: 2007/05/23 14:18:09 $
7 Version: $Revision: 1.19 $
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"
25 namespace GDCM_NAME_SPACE
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 TagKey key = newEntry->GetKey();
65 if ( Archive.find(key) == Archive.end() )
67 uint16_t group = newEntry->GetGroup();
68 uint16_t elem = newEntry->GetElement();
70 // Save the old DocEntry if any
71 DocEntry *old = ArchFile->GetDocEntry(group, elem);
76 ArchFile->RemoveEntry(old);
79 // Set the new DocEntry
80 ArchFile->AddEntry(newEntry);
88 * \brief Removes out of the Header a DocEntry.
89 * (it's kept in archive).
90 * @param group Group number of the Entry to remove
91 * @param elem Element number of the Entry to remove
92 * @return FALSE when an other DocEntry is already archived with the same key
95 bool DocEntryArchive::Push(uint16_t group, uint16_t elem)
97 //TagKey key = DictEntry::TranslateToKey(group, elem);
98 TagKey key(group, elem);
99 if ( Archive.find(key)==Archive.end() )
101 // Save the old DocEntry if any
102 DocEntry *old = ArchFile->GetDocEntry(group, elem);
107 ArchFile->RemoveEntry(old);
116 * \brief Restore in the Header the DocEntry specified by (group,element).
117 * The archive entry is destroyed.
118 * @param group Group number of the Entry to restore
119 * @param elem Element number of the Entry to restore
120 * @return FALSE when the key isn't in the archive,
123 bool DocEntryArchive::Restore(uint16_t group, uint16_t elem)
125 //TagKey key=DictEntry::TranslateToKey(group, elem);
126 TagKey key(group, elem);
127 TagDocEntryHT::iterator restoreIt=Archive.find(key);
128 if ( restoreIt!=Archive.end() )
130 // Delete the new value
131 DocEntry *rem = ArchFile->GetDocEntry(group, elem);
134 ArchFile->RemoveEntry(rem);
137 // Restore the old value
138 if ( restoreIt->second )
140 ArchFile->AddEntry(restoreIt->second);
141 restoreIt->second->Unregister();
144 Archive.erase(restoreIt);
152 * \brief Removes all DocEntry from the archive, and destroy them.
153 * The archives entries aren't restored.
155 void DocEntryArchive::ClearArchive( )
157 for(TagDocEntryHT::iterator it = Archive.begin();
162 it->second->Unregister();
167 //-----------------------------------------------------------------------------
170 //-----------------------------------------------------------------------------
173 //-----------------------------------------------------------------------------
177 * @param os The output stream to be written to.
179 void DocEntryArchive::Print(std::ostream &os)
181 os << "Elements in archives :" << std::endl;
182 for(TagDocEntryHT::iterator it = Archive.begin();
187 it->second->Print(os);
191 //-----------------------------------------------------------------------------
192 } // end namespace gdcm