00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "gdcmDocEntryArchive.h"
00020 #include "gdcmDebug.h"
00021 #include "gdcmDocEntry.h"
00022
00023 #include <string>
00024
00025 namespace gdcm
00026 {
00027
00028
00032 DocEntryArchive::DocEntryArchive(File *file)
00033 {
00034 ArchFile = file;
00035 }
00036
00040 DocEntryArchive::~DocEntryArchive()
00041 {
00042 ClearArchive();
00043 }
00044
00045
00046
00054 bool DocEntryArchive::Push(DocEntry *newEntry)
00055 {
00056 if(!newEntry)
00057 return false;
00058
00059 uint16_t group = newEntry->GetDictEntry()->GetGroup();
00060 uint16_t elem = newEntry->GetDictEntry()->GetElement();
00061 std::string key = DictEntry::TranslateToKey(group,elem);
00062
00063 if( Archive.find(key)==Archive.end() )
00064 {
00065
00066 DocEntry *old = ArchFile->GetDocEntry(group,elem);
00067 Archive[key] = old;
00068 if( old )
00069 ArchFile->RemoveEntryNoDestroy(old);
00070
00071
00072 ArchFile->AddEntry(newEntry);
00073
00074 return true;
00075 }
00076 return false;
00077 }
00078
00087 bool DocEntryArchive::Push(uint16_t group,uint16_t elem)
00088 {
00089 std::string key = DictEntry::TranslateToKey(group,elem);
00090
00091 if( Archive.find(key)==Archive.end() )
00092 {
00093
00094 DocEntry *old = ArchFile->GetDocEntry(group,elem);
00095 Archive[key] = old;
00096 if( old )
00097 ArchFile->RemoveEntryNoDestroy(old);
00098
00099 return true;
00100 }
00101 return false;
00102 }
00103
00112 bool DocEntryArchive::Restore(uint16_t group,uint16_t elem)
00113 {
00114 std::string key=DictEntry::TranslateToKey(group,elem);
00115
00116 TagDocEntryHT::iterator restoreIt=Archive.find(key);
00117 if( restoreIt!=Archive.end() )
00118 {
00119
00120 DocEntry *rem = ArchFile->GetDocEntry(group,elem);
00121 if( rem )
00122 ArchFile->RemoveEntry(rem);
00123
00124
00125 if( Archive[key] )
00126 ArchFile->AddEntry(Archive[key]);
00127
00128 Archive.erase(restoreIt);
00129
00130 return true;
00131 }
00132 return false;
00133 }
00134
00139 void DocEntryArchive::ClearArchive( )
00140 {
00141 for(TagDocEntryHT::iterator it = Archive.begin();
00142 it!=Archive.end();
00143 ++it)
00144 {
00145 delete it->second;
00146 }
00147 Archive.clear();
00148 }
00149
00150
00151
00152
00153
00154
00155
00156
00157
00162 void DocEntryArchive::Print(std::ostream &os)
00163 {
00164 os << "Elements in archives :" << std::endl;
00165 for(TagDocEntryHT::iterator it = Archive.begin();
00166 it!=Archive.end();
00167 ++it)
00168 {
00169 if(it->second)
00170 it->second->Print(os);
00171 }
00172 }
00173
00174
00175 }