1 /*=========================================================================
4 Module: $RCSfile: gdcmDocEntryArchive.cxx,v $
6 Date: $Date: 2004/12/03 20:16:58 $
7 Version: $Revision: 1.4 $
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(Header *header):
32 HeaderHT(header->TagHT)
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 archieve
68 * @param newEntry New entry to substitute to an other entry of the Header
69 * @return FALSE when an other DocEntry is already archieved with the same
70 * generalized key, TRUE otherwise
72 bool DocEntryArchive::Push(DocEntry *newEntry)
77 uint16_t gr = newEntry->GetDictEntry()->GetGroup();
78 uint16_t elt = newEntry->GetDictEntry()->GetElement();
79 std::string key = DictEntry::TranslateToKey(gr,elt);
81 if( Archive.find(key)==Archive.end() )
83 // Save the old DocEntry if any
84 TagDocEntryHT::iterator it = HeaderHT.find(key);
85 if( it!=HeaderHT.end() )
87 Archive[key] = it->second;
94 // Set the new DocEntry
95 HeaderHT[key] = newEntry;
103 * \brief Replace in the Header a DocEntry by the new DocEntry. The last
104 * DocEntry is kept in archieve
105 * @param newEntry New entry to substitute to an other entry of the Header
106 * @return FALSE when an other DocEntry is already archieved with the same
107 * generalized key, TRUE otherwise
109 bool DocEntryArchive::Push(uint16_t group,uint16_t element)
111 std::string key = DictEntry::TranslateToKey(group,element);
113 if( Archive.find(key)==Archive.end() )
115 // Save the old DocEntry if any
116 TagDocEntryHT::iterator it = HeaderHT.find(key);
117 if( it!=HeaderHT.end() )
119 Archive[key] = it->second;
129 * \brief Restore in the Header the DocEntry that have the generalized key.
130 * The old entry is destroyed.
131 * @param key Key of the DocEntry to restore
132 * @return FALSE when the generalized key isn't in the archieve,
135 bool DocEntryArchive::Restore(uint16_t group,uint16_t element)
137 std::string key=DictEntry::TranslateToKey(group,element);
139 TagDocEntryHT::iterator restoreIt=Archive.find(key);
140 if( restoreIt!=Archive.end() )
142 TagDocEntryHT::iterator restorePos = HeaderHT.find(key);
143 if( restorePos!=HeaderHT.end() )
145 delete restorePos->second;
150 HeaderHT[key] = Archive[key];
154 HeaderHT.erase(restorePos);
157 Archive.erase(restoreIt);
165 * \brief Remove all DocEntry that are in the archive. The entries aren't
166 * restored but only destroyed.
168 void DocEntryArchive::ClearArchive(void)
170 for(TagDocEntryHT::iterator it = Archive.begin();
179 //-----------------------------------------------------------------------------
182 //-----------------------------------------------------------------------------
185 //-----------------------------------------------------------------------------
187 } // end namespace gdcm