1 /*=========================================================================
4 Module: $RCSfile: gdcmDocEntryArchive.cxx,v $
6 Date: $Date: 2004/11/23 11:14:13 $
7 Version: $Revision: 1.2 $
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"
26 //-----------------------------------------------------------------------------
30 DocEntryArchive::DocEntryArchive(Header *header):
31 HeaderHT(header->TagHT)
35 //-----------------------------------------------------------------------------
39 DocEntryArchive::~DocEntryArchive()
44 //-----------------------------------------------------------------------------
48 * @param os The output stream to be written to.
50 void DocEntryArchive::Print(std::ostream &os)
52 os << "Elements in archives :" << std::endl;
53 for(TagDocEntryHT::iterator it = Archive.begin();
58 it->second->Print(os);
62 //-----------------------------------------------------------------------------
65 * \brief Replace in the Header a DocEntry by the new DocEntry. The last
66 * DocEntry is kept in archieve
67 * @param newEntry New entry to substitute to an other entry of the Header
68 * @return FALSE when an other DocEntry is already archieved with the same
69 * generalized key, TRUE otherwise
71 bool DocEntryArchive::Push(DocEntry *newEntry)
76 uint16_t gr = newEntry->GetDictEntry()->GetGroup();
77 uint16_t elt = newEntry->GetDictEntry()->GetElement();
78 std::string key = DictEntry::TranslateToKey(gr,elt);
80 if( Archive.find(key)==Archive.end() )
82 // Save the old DocEntry if any
83 TagDocEntryHT::iterator it = HeaderHT.find(key);
84 if( it!=HeaderHT.end() )
85 Archive[key] = it->second;
89 // Set the new DocEntry
90 HeaderHT[key] = newEntry;
98 * \brief Restore in the Header the DocEntry that have the generalized key.
99 * The old entry is destroyed.
100 * @param key Key of the DocEntry to restore
101 * @return FALSE when the generalized key isn't in the archieve,
104 bool DocEntryArchive::Restore(uint16_t group,uint16_t element)
106 std::string key=DictEntry::TranslateToKey(group,element);
108 TagDocEntryHT::iterator restoreIt=Archive.find(key);
109 if( restoreIt!=Archive.end() )
111 TagDocEntryHT::iterator restorePos = HeaderHT.find(key);
112 if( restoreIt!=HeaderHT.end() )
113 delete restorePos->second;
116 HeaderHT[key] = Archive[key];
118 HeaderHT.erase(restorePos);
120 Archive.erase(restoreIt);
128 * \brief Remove all DocEntry that are in the archive. The entries aren't
129 * restored but only destroyed.
131 void DocEntryArchive::ClearArchive(void)
133 for(TagDocEntryHT::iterator it = Archive.begin();
142 //-----------------------------------------------------------------------------
145 //-----------------------------------------------------------------------------
148 //-----------------------------------------------------------------------------
150 } // end namespace gdcm