1 /*=========================================================================
4 Module: $RCSfile: gdcmSeqEntry.cxx,v $
6 Date: $Date: 2004/08/31 14:24:47 $
7 Version: $Revision: 1.26 $
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.htm 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 "gdcmSeqEntry.h"
20 #include "gdcmSQItem.h"
22 #include "gdcmGlobal.h"
27 //-----------------------------------------------------------------------------
28 // Constructor / Destructor
30 * \ingroup gdcmSeqEntry
31 * \brief Constructor from a given gdcmSeqEntry
33 gdcmSeqEntry::gdcmSeqEntry(gdcmDictEntry* e, int depth)
36 delimitor_mode = false;
40 ReadLength = 0xffffffff;
44 * \brief Constructor from a given gdcmSeqEntry
45 * @param e Pointer to existing Doc entry
46 * @param depth depth level of the current Seq entry
48 gdcmSeqEntry::gdcmSeqEntry(gdcmDocEntry* e, int depth) : gdcmDocEntry(e->GetDictEntry())
50 this->UsableLength = 0;
51 this->ReadLength = 0xffffffff;
52 this->ImplicitVR = e->IsImplicitVR();
53 this->Offset = e->GetOffset();
54 //this->printLevel = e->GetPrintLevel(); // no longer exists ?!?
55 this->SQDepthLevel = depth;
58 * \brief Canonical destructor.
60 gdcmSeqEntry::~gdcmSeqEntry() {
61 for(ListSQItem::iterator cc = items.begin();cc != items.end();++cc)
70 * \brief canonical Printer
72 void gdcmSeqEntry::Print(std::ostream &os){
74 // First, Print the Dicom Element itself.
76 gdcmDocEntry::Print(os);
79 if (GetReadLength() == 0)
82 // Then, Print each SQ Item
83 for(ListSQItem::iterator cc = items.begin();cc != items.end();++cc)
88 // at end, print the sequence terminator item, if any
90 for (int i=0;i<SQDepthLevel+1;i++)
92 if (seq_term != NULL) {
98 os << " -------------- should have a sequence terminator item";
103 * \brief canonical Writer
105 void gdcmSeqEntry::Write(FILE *fp, FileType filetype)
107 uint16_t seq_term_gr = 0xfffe;
108 uint16_t seq_term_el = 0xe0dd;
109 uint32_t seq_term_lg = 0xffffffff;
111 //uint16_t item_term_gr = 0xfffe;
112 //uint16_t item_term_el = 0xe00d;
114 gdcmDocEntry::Write(fp, filetype);
115 for(ListSQItem::iterator cc = GetSQItems().begin();
116 cc != GetSQItems().end();
119 (*cc)->Write(fp, filetype);
122 //we force the writting of a Sequence Delimitation item
123 // because we wrote the Sequence as a 'no Length' sequence
124 fwrite ( &seq_term_gr,(size_t)2 ,(size_t)1 ,fp);
125 fwrite ( &seq_term_el,(size_t)2 ,(size_t)1 ,fp);
126 fwrite ( &seq_term_lg,(size_t)4 ,(size_t)1 ,fp);
129 //-----------------------------------------------------------------------------
132 /// \brief adds the passed ITEM to the ITEM chained List for this SeQuence.
133 void gdcmSeqEntry::AddEntry(gdcmSQItem *sqItem, int itemNumber) {
134 sqItem->SetSQItemNumber(itemNumber);
135 items.push_back(sqItem);
138 /// \brief Sets the depth level of a Sequence Entry embedded in a SeQuence
139 void gdcmSeqEntry::SetDepthLevel(int depth) {
140 SQDepthLevel = depth;
143 /// \brief return a pointer to the SQItem referenced by its ordinal number
144 /// (returns the first one if ordinal number is <0
145 /// returns the last one if ordinal number is > item number
147 gdcmSQItem *gdcmSeqEntry::GetSQItemByOrdinalNumber(int nb) {
149 return (*(items.begin()));
151 for(ListSQItem::iterator cc = items.begin();
157 return (*(items.end())); // Euhhhhh ?!? Is this the last one . FIXME
159 //-----------------------------------------------------------------------------
163 //-----------------------------------------------------------------------------
166 //-----------------------------------------------------------------------------