1 /*=========================================================================
4 Module: $RCSfile: gdcmSeqEntry.cxx,v $
6 Date: $Date: 2005/01/17 11:13:21 $
7 Version: $Revision: 1.44 $
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"
24 #include "gdcmDebug.h"
33 //-----------------------------------------------------------------------------
34 // Constructor / Destructor
37 * \brief Constructor from a given SeqEntry
39 SeqEntry::SeqEntry( DictEntry *e )
43 ReadLength = 0xffffffff;
46 DelimitorMode = false;
51 * \brief Constructor from a given SeqEntry
52 * @param e Pointer to existing Doc entry
53 * @param depth depth level of the current Seq entry
55 SeqEntry::SeqEntry( DocEntry *e, int depth )
56 : DocEntry( e->GetDictEntry() )
59 ReadLength = 0xffffffff;
62 ImplicitVR = e->IsImplicitVR();
63 Offset = e->GetOffset();
68 * \brief Canonical destructor.
72 for(ListSQItem::iterator cc = Items.begin(); cc != Items.end(); ++cc)
83 * \brief canonical Printer
85 void SeqEntry::Print( std::ostream &os, std::string const & )
87 // First, Print the Dicom Element itself.
92 if (GetReadLength() == 0)
95 // Then, Print each SQ Item
96 for(ListSQItem::iterator cc = Items.begin(); cc != Items.end(); ++cc)
98 (*cc)->SetPrintLevel(PrintLevel);
102 // at end, print the sequence terminator item, if any
105 for ( int i = 0; i < SQDepthLevel; i++ )
111 SeqTerm->SetPrintLevel(PrintLevel);
118 gdcmVerboseMacro(" -------- should have a sequence terminator item");
124 * \brief canonical Writer
126 void SeqEntry::WriteContent(std::ofstream *fp, FileType filetype)
128 uint16_t seq_term_gr = 0xfffe;
129 uint16_t seq_term_el = 0xe0dd;
130 uint32_t seq_term_lg = 0xffffffff;
132 //uint16_t item_term_gr = 0xfffe;
133 //uint16_t item_term_el = 0xe00d;
135 DocEntry::WriteContent(fp, filetype);
136 for(ListSQItem::iterator cc = Items.begin();
140 (*cc)->WriteContent(fp, filetype);
143 // we force the writting of a Sequence Delimitation item
144 // because we wrote the Sequence as a 'no Length' sequence
145 binary_write(*fp, seq_term_gr);
146 binary_write(*fp, seq_term_el);
147 binary_write(*fp, seq_term_lg);
150 //-----------------------------------------------------------------------------
153 /// \brief adds the passed ITEM to the ITEM chained List for this SeQuence.
154 void SeqEntry::AddEntry(SQItem *sqItem, int itemNumber)
156 sqItem->SetSQItemNumber(itemNumber);
157 Items.push_back(sqItem);
161 * \brief return a pointer to the SQItem referenced by its ordinal number.
162 * Returns the first item when argument is negative.
163 * Returns the last item when argument is bigget than the total
166 SQItem *SeqEntry::GetSQItemByOrdinalNumber(int nb)
170 return *(Items.begin());
173 for(ListSQItem::iterator cc = Items.begin();
182 return *(Items.end()); // Euhhhhh ?!? Is this the last one . FIXME
184 //-----------------------------------------------------------------------------
188 //-----------------------------------------------------------------------------
191 //-----------------------------------------------------------------------------
192 } // end namespace gdcm