1 /*=========================================================================
4 Module: $RCSfile: gdcmSeqEntry.cxx,v $
6 Date: $Date: 2005/01/16 04:50:42 $
7 Version: $Revision: 1.43 $
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() )
58 ReadLength = 0xffffffff;
61 ImplicitVR = e->IsImplicitVR();
62 Offset = e->GetOffset();
67 * \brief Canonical destructor.
71 for(ListSQItem::iterator cc = Items.begin(); cc != Items.end(); ++cc)
82 * \brief canonical Printer
84 void SeqEntry::Print( std::ostream &os, std::string const & )
86 // First, Print the Dicom Element itself.
91 if (GetReadLength() == 0)
94 // Then, Print each SQ Item
95 for(ListSQItem::iterator cc = Items.begin(); cc != Items.end(); ++cc)
97 (*cc)->SetPrintLevel(PrintLevel);
101 // at end, print the sequence terminator item, if any
104 for ( int i = 0; i < SQDepthLevel; i++ )
110 SeqTerm->SetPrintLevel(PrintLevel);
117 os << " -------------- should have a sequence terminator item";
123 * \brief canonical Writer
125 void SeqEntry::WriteContent(std::ofstream *fp, FileType filetype)
127 uint16_t seq_term_gr = 0xfffe;
128 uint16_t seq_term_el = 0xe0dd;
129 uint32_t seq_term_lg = 0xffffffff;
131 //uint16_t item_term_gr = 0xfffe;
132 //uint16_t item_term_el = 0xe00d;
134 DocEntry::WriteContent(fp, filetype);
135 for(ListSQItem::iterator cc = Items.begin();
139 (*cc)->WriteContent(fp, filetype);
142 // we force the writting of a Sequence Delimitation item
143 // because we wrote the Sequence as a 'no Length' sequence
144 binary_write(*fp, seq_term_gr);
145 binary_write(*fp, seq_term_el);
146 binary_write(*fp, seq_term_lg);
149 //-----------------------------------------------------------------------------
152 /// \brief adds the passed ITEM to the ITEM chained List for this SeQuence.
153 void SeqEntry::AddEntry(SQItem *sqItem, int itemNumber)
155 sqItem->SetSQItemNumber(itemNumber);
156 Items.push_back(sqItem);
160 * \brief return a pointer to the SQItem referenced by its ordinal number.
161 * Returns the first item when argument is negative.
162 * Returns the last item when argument is bigget than the total
165 SQItem *SeqEntry::GetSQItemByOrdinalNumber(int nb)
169 return *(Items.begin());
172 for(ListSQItem::iterator cc = Items.begin();
181 return *(Items.end()); // Euhhhhh ?!? Is this the last one . FIXME
183 //-----------------------------------------------------------------------------
187 //-----------------------------------------------------------------------------
190 //-----------------------------------------------------------------------------
191 } // end namespace gdcm