1 /*=========================================================================
4 Module: $RCSfile: gdcmDocEntryArchive.cxx,v $
6 Date: $Date: 2005/01/11 00:21:48 $
7 Version: $Revision: 1.6 $
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 group Group number of the Entry
106 * @param element Element number of the Entry
107 * @return FALSE when an other DocEntry is already archieved with the same
108 * generalized key, TRUE otherwise
110 bool DocEntryArchive::Push(uint16_t group,uint16_t element)
112 std::string key = DictEntry::TranslateToKey(group,element);
114 if( Archive.find(key)==Archive.end() )
116 // Save the old DocEntry if any
117 TagDocEntryHT::iterator it = HeaderHT.find(key);
118 if( it!=HeaderHT.end() )
120 Archive[key] = it->second;
130 * \brief Restore in the Header the DocEntry that have the generalized key.
131 * The old entry is destroyed.
132 * @param group Group number of the Entry
133 * @param element Element number of the Entry
134 * @return FALSE when the generalized key isn't in the archieve,
137 bool DocEntryArchive::Restore(uint16_t group,uint16_t element)
139 std::string key=DictEntry::TranslateToKey(group,element);
141 TagDocEntryHT::iterator restoreIt=Archive.find(key);
142 if( restoreIt!=Archive.end() )
144 TagDocEntryHT::iterator restorePos = HeaderHT.find(key);
145 if( restorePos!=HeaderHT.end() )
147 delete restorePos->second;
152 HeaderHT[key] = Archive[key];
156 HeaderHT.erase(restorePos);
159 Archive.erase(restoreIt);
167 * \brief Remove all DocEntry that are in the archive. The entries aren't
168 * restored but only destroyed.
170 void DocEntryArchive::ClearArchive(void)
172 for(TagDocEntryHT::iterator it = Archive.begin();
181 //-----------------------------------------------------------------------------
184 //-----------------------------------------------------------------------------
187 //-----------------------------------------------------------------------------
189 } // end namespace gdcm