00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "gdcmSeqEntry.h"
00020 #include "gdcmSQItem.h"
00021 #include "gdcmValEntry.h"
00022 #include "gdcmTS.h"
00023 #include "gdcmGlobal.h"
00024 #include "gdcmUtil.h"
00025 #include "gdcmDebug.h"
00026
00027 #include <iostream>
00028 #include <iomanip>
00029 #include <fstream>
00030
00031 namespace gdcm
00032 {
00033
00034
00038 SeqEntry::SeqEntry( DictEntry *e )
00039 : DocEntry(e)
00040 {
00041 Length = 0;
00042 ReadLength = 0xffffffff;
00043 SQDepthLevel = -1;
00044
00045 DelimitorMode = false;
00046 SeqTerm = NULL;
00047 }
00048
00054 SeqEntry::SeqEntry( DocEntry *e, int depth )
00055 : DocEntry( e->GetDictEntry() )
00056 {
00057 Length = 0;
00058 ReadLength = 0xffffffff;
00059 SQDepthLevel = depth;
00060
00061 ImplicitVR = e->IsImplicitVR();
00062 Offset = e->GetOffset();
00063 SeqTerm = NULL;
00064 }
00065
00069 SeqEntry::~SeqEntry()
00070 {
00071 ClearSQItem();
00072 }
00073
00074
00075
00076
00077
00078
00079
00080
00081 void SeqEntry::WriteContent(std::ofstream *fp, FileType filetype)
00082 {
00083 uint16_t seq_term_gr = 0xfffe;
00084 uint16_t seq_term_el = 0xe0dd;
00085 uint32_t seq_term_lg = 0xffffffff;
00086
00087
00088
00089
00090 DocEntry::WriteContent(fp, filetype);
00091 for(ListSQItem::iterator cc = Items.begin();
00092 cc != Items.end();
00093 ++cc)
00094 {
00095 (*cc)->WriteContent(fp, filetype);
00096 }
00097
00098
00099
00100 binary_write(*fp, seq_term_gr);
00101 binary_write(*fp, seq_term_el);
00102 binary_write(*fp, seq_term_lg);
00103 }
00104
00111 void SeqEntry::AddSQItem(SQItem *sqItem, int itemNumber)
00112 {
00113
00114
00115
00116
00117
00118 sqItem->SetSQItemNumber(itemNumber);
00119 Items.push_back(sqItem);
00120 }
00121
00125 void SeqEntry::ClearSQItem()
00126 {
00127 for(ListSQItem::iterator cc = Items.begin(); cc != Items.end(); ++cc)
00128 {
00129 delete *cc;
00130 }
00131 if (SeqTerm)
00132 {
00133 delete SeqTerm;
00134 }
00135 }
00136
00141 SQItem *SeqEntry::GetFirstSQItem()
00142 {
00143 ItSQItem = Items.begin();
00144 if (ItSQItem != Items.end())
00145 return *ItSQItem;
00146 return NULL;
00147 }
00148
00155 SQItem *SeqEntry::GetNextSQItem()
00156 {
00157 gdcmAssertMacro (ItSQItem != Items.end())
00158 {
00159 ++ItSQItem;
00160 if (ItSQItem != Items.end())
00161 return *ItSQItem;
00162 }
00163 return NULL;
00164 }
00165
00172 SQItem *SeqEntry::GetSQItem(int nb)
00173 {
00174 if (nb<0)
00175 {
00176 return *(Items.begin());
00177 }
00178 int count = 0 ;
00179 for(ListSQItem::iterator cc = Items.begin();
00180 cc != Items.end();
00181 count ++, ++cc)
00182 {
00183 if (count == nb)
00184 {
00185 return *cc;
00186 }
00187 }
00188 return *(Items.end());
00189 }
00190
00194 unsigned int SeqEntry::GetNumberOfSQItems()
00195 {
00196 return Items.size();
00197 }
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00227 void SeqEntry::Print( std::ostream &os, std::string const & )
00228 {
00229
00230 os << "S ";
00231 DocEntry::Print(os);
00232 os << std::endl;
00233
00234 if (GetReadLength() == 0)
00235 return;
00236
00237
00238 for(ListSQItem::iterator cc = Items.begin(); cc != Items.end(); ++cc)
00239 {
00240 (*cc)->SetPrintLevel(PrintLevel);
00241 (*cc)->Print(os);
00242 }
00243
00244
00245 if (DelimitorMode)
00246 {
00247 for ( int i = 0; i < SQDepthLevel; i++ )
00248 {
00249 os << " | " ;
00250 }
00251 if (SeqTerm != NULL)
00252 {
00253 SeqTerm->SetPrintLevel(PrintLevel);
00254 SeqTerm->Print(os);
00255 os << std::endl;
00256 }
00257 else
00258 {
00259
00260 gdcmWarningMacro(" -------- should have a sequence terminator item");
00261 }
00262 }
00263 }
00264
00265
00266 }