1 /*=========================================================================
4 Module: $RCSfile: gdcmDocEntryArchive.cxx,v $
6 Date: $Date: 2005/06/24 10:55:59 $
7 Version: $Revision: 1.15 $
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 std::string 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);
69 ArchFile->RemoveEntryNoDestroy(old);
71 // Set the new DocEntry
72 ArchFile->AddEntry(newEntry);
80 * \brief Removes out of the Header a DocEntry.
81 * (it's kept in archive).
82 * @param group Group number of the Entry to remove
83 * @param elem Element number of the Entry to remove
84 * @return FALSE when an other DocEntry is already archived with the same key
87 bool DocEntryArchive::Push(uint16_t group, uint16_t elem)
89 std::string key = DictEntry::TranslateToKey(group, elem);
91 if ( Archive.find(key)==Archive.end() )
93 // Save the old DocEntry if any
94 DocEntry *old = ArchFile->GetDocEntry(group, elem);
97 ArchFile->RemoveEntryNoDestroy(old);
105 * \brief Restore in the Header the DocEntry specified by (group,element).
106 * The archive entry is destroyed.
107 * @param group Group number of the Entry to restore
108 * @param elem Element number of the Entry to restore
109 * @return FALSE when the key isn't in the archive,
112 bool DocEntryArchive::Restore(uint16_t group, uint16_t elem)
114 std::string key=DictEntry::TranslateToKey(group, elem);
116 TagDocEntryHT::iterator restoreIt=Archive.find(key);
117 if ( restoreIt!=Archive.end() )
119 // Delete the new value
120 DocEntry *rem = ArchFile->GetDocEntry(group, elem);
122 ArchFile->RemoveEntry(rem);
124 // Restore the old value
126 ArchFile->AddEntry(Archive[key]);
128 Archive.erase(restoreIt);
136 * \brief Removes all DocEntry from the archive, and destroy them.
137 * The archives entries aren't restored.
139 void DocEntryArchive::ClearArchive( )
141 for(TagDocEntryHT::iterator it = Archive.begin();
150 //-----------------------------------------------------------------------------
153 //-----------------------------------------------------------------------------
156 //-----------------------------------------------------------------------------
160 * @param os The output stream to be written to.
162 void DocEntryArchive::Print(std::ostream &os)
164 os << "Elements in archives :" << std::endl;
165 for(TagDocEntryHT::iterator it = Archive.begin();
170 it->second->Print(os);
174 //-----------------------------------------------------------------------------
175 } // end namespace gdcm