00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "gdcmElementSet.h"
00020 #include "gdcmDebug.h"
00021 #include "gdcmValEntry.h"
00022 #include "gdcmBinEntry.h"
00023 #include "gdcmSeqEntry.h"
00024
00025 namespace gdcm
00026 {
00027
00028
00032
00033 ElementSet::ElementSet(int depthLevel)
00034 : DocEntrySet()
00035 {
00036 (void)depthLevel;
00037 }
00038
00042 ElementSet::~ElementSet()
00043 {
00044 ClearEntry();
00045 }
00046
00047
00048
00055 void ElementSet::WriteContent(std::ofstream *fp, FileType filetype)
00056 {
00057 for (TagDocEntryHT::const_iterator i = TagHT.begin();
00058 i != TagHT.end();
00059 ++i)
00060 {
00061 i->second->WriteContent(fp, filetype);
00062 }
00063 }
00064
00069 bool ElementSet::AddEntry(DocEntry *newEntry)
00070 {
00071 const TagKey &key = newEntry->GetKey();
00072
00073 if( TagHT.count(key) == 1 )
00074 {
00075 gdcmWarningMacro( "Key already present: " << key.c_str());
00076 return false;
00077 }
00078 else
00079 {
00080 TagHT.insert(TagDocEntryHT::value_type(newEntry->GetKey(), newEntry));
00081 return true;
00082 }
00083 }
00084
00089 bool ElementSet::RemoveEntry( DocEntry *entryToRemove)
00090 {
00091 const TagKey &key = entryToRemove->GetKey();
00092 if( TagHT.count(key) == 1 )
00093 {
00094 TagHT.erase(key);
00095
00096 delete entryToRemove;
00097 return true;
00098 }
00099
00100 gdcmWarningMacro( "Key not present");
00101 return false ;
00102 }
00103
00108 bool ElementSet::RemoveEntryNoDestroy(DocEntry *entryToRemove)
00109 {
00110 const TagKey &key = entryToRemove->GetKey();
00111 if( TagHT.count(key) == 1 )
00112 {
00113 TagHT.erase(key);
00114
00115 return true;
00116 }
00117
00118 gdcmWarningMacro( "Key not present");
00119 return false ;
00120 }
00121
00125 void ElementSet::ClearEntry()
00126 {
00127 for(TagDocEntryHT::iterator cc = TagHT.begin();cc != TagHT.end(); ++cc)
00128 {
00129 if ( cc->second )
00130 {
00131 delete cc->second;
00132 }
00133 }
00134 TagHT.clear();
00135 }
00136
00142 DocEntry *ElementSet::GetFirstEntry()
00143 {
00144 ItTagHT = TagHT.begin();
00145 if (ItTagHT != TagHT.end())
00146 return ItTagHT->second;
00147 return NULL;
00148 }
00149
00156 DocEntry *ElementSet::GetNextEntry()
00157 {
00158 gdcmAssertMacro (ItTagHT != TagHT.end());
00159
00160 ++ItTagHT;
00161 if (ItTagHT != TagHT.end())
00162 return ItTagHT->second;
00163 return NULL;
00164 }
00165
00172 DocEntry *ElementSet::GetDocEntry(uint16_t group, uint16_t elem)
00173 {
00174 TagKey key = DictEntry::TranslateToKey(group, elem);
00175 TagDocEntryHT::iterator it = TagHT.find(key);
00176
00177 if ( it!=TagHT.end() )
00178 return it->second;
00179 return NULL;
00180 }
00181
00182
00183
00184
00185
00186
00187
00188
00189
00195 void ElementSet::Print(std::ostream &os, std::string const & )
00196 {
00197 for( TagDocEntryHT::const_iterator i = TagHT.begin(); i != TagHT.end(); ++i)
00198 {
00199 DocEntry *entry = i->second;
00200
00201 entry->SetPrintLevel(PrintLevel);
00202 entry->Print(os);
00203
00204 if ( dynamic_cast<SeqEntry*>(entry) )
00205 {
00206
00207 continue;
00208 }
00209 os << std::endl;
00210 }
00211 }
00212
00213
00214 }