1 /*=========================================================================
4 Module: $RCSfile: gdcmSeqEntry.cxx,v $
6 Date: $Date: 2004/11/03 20:52:13 $
7 Version: $Revision: 1.34 $
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 "gdcmSeqEntry.h"
20 #include "gdcmSQItem.h"
22 #include "gdcmGlobal.h"
32 //-----------------------------------------------------------------------------
33 // Constructor / Destructor
36 * \brief Constructor from a given SeqEntry
38 SeqEntry::SeqEntry( DictEntry* e )
42 ReadLength = 0xffffffff;
45 DelimitorMode = false;
50 * \brief Constructor from a given SeqEntry
51 * @param e Pointer to existing Doc entry
52 * @param depth depth level of the current Seq entry
54 SeqEntry::SeqEntry( DocEntry* e, int depth )
55 : DocEntry( e->GetDictEntry() )
57 this->UsableLength = 0;
58 this->ReadLength = 0xffffffff;
61 this->ImplicitVR = e->IsImplicitVR();
62 this->Offset = e->GetOffset();
66 * \brief Canonical destructor.
70 for(ListSQItem::iterator cc = Items.begin(); cc != Items.end(); ++cc)
81 * \brief canonical Printer
83 void SeqEntry::Print( std::ostream &os )
85 // First, Print the Dicom Element itself.
90 if (GetReadLength() == 0)
93 // Then, Print each SQ Item
94 for(ListSQItem::iterator cc = Items.begin(); cc != Items.end(); ++cc)
99 // at end, print the sequence terminator item, if any
102 for ( int i = 0; i < SQDepthLevel; i++ )
114 os << " -------------- should have a sequence terminator item";
120 * \brief canonical Writer
122 void SeqEntry::Write(std::ofstream* fp, FileType filetype)
124 uint16_t seq_term_gr = 0xfffe;
125 uint16_t seq_term_el = 0xe0dd;
126 uint32_t seq_term_lg = 0xffffffff;
128 //uint16_t item_term_gr = 0xfffe;
129 //uint16_t item_term_el = 0xe00d;
131 DocEntry::Write(fp, filetype);
132 for(ListSQItem::iterator cc = Items.begin();
136 (*cc)->Write(fp, filetype);
139 // we force the writting of a Sequence Delimitation item
140 // because we wrote the Sequence as a 'no Length' sequence
141 binary_write(*fp, seq_term_gr);
142 binary_write(*fp, seq_term_el);
143 binary_write(*fp, seq_term_lg);
146 //-----------------------------------------------------------------------------
149 /// \brief adds the passed ITEM to the ITEM chained List for this SeQuence.
150 void SeqEntry::AddEntry(SQItem *sqItem, int itemNumber)
152 sqItem->SetSQItemNumber(itemNumber);
153 Items.push_back(sqItem);
157 * \brief return a pointer to the SQItem referenced by its ordinal number.
158 * Returns the first item when argument is negative.
159 * Returns the last item when argument is bigget than the total
162 SQItem* SeqEntry::GetSQItemByOrdinalNumber(int nb)
166 return *(Items.begin());
169 for(ListSQItem::iterator cc = Items.begin();
178 return *(Items.end()); // Euhhhhh ?!? Is this the last one . FIXME
180 //-----------------------------------------------------------------------------
184 //-----------------------------------------------------------------------------
187 //-----------------------------------------------------------------------------
188 } // end namespace gdcm