1 /*=========================================================================
4 Module: $RCSfile: gdcmSeqEntry.cxx,v $
6 Date: $Date: 2005/01/20 11:26:18 $
7 Version: $Revision: 1.48 $
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
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)
81 //-----------------------------------------------------------------------------
84 * \brief canonical Printer
86 void SeqEntry::Print( std::ostream &os, std::string const & )
88 // First, Print the Dicom Element itself.
93 if (GetReadLength() == 0)
96 // Then, Print each SQ Item
97 for(ListSQItem::iterator cc = Items.begin(); cc != Items.end(); ++cc)
99 (*cc)->SetPrintLevel(PrintLevel);
103 // at end, print the sequence terminator item, if any
106 for ( int i = 0; i < SQDepthLevel; i++ )
112 SeqTerm->SetPrintLevel(PrintLevel);
119 gdcmVerboseMacro(" -------- should have a sequence terminator item");
124 //-----------------------------------------------------------------------------
127 * \brief canonical Writer
129 void SeqEntry::WriteContent(std::ofstream *fp, FileType filetype)
131 uint16_t seq_term_gr = 0xfffe;
132 uint16_t seq_term_el = 0xe0dd;
133 uint32_t seq_term_lg = 0xffffffff;
135 //uint16_t item_term_gr = 0xfffe;
136 //uint16_t item_term_el = 0xe00d;
138 DocEntry::WriteContent(fp, filetype);
139 for(ListSQItem::iterator cc = Items.begin();
143 (*cc)->WriteContent(fp, filetype);
146 // we force the writting of a Sequence Delimitation item
147 // because we wrote the Sequence as a 'no Length' sequence
148 binary_write(*fp, seq_term_gr);
149 binary_write(*fp, seq_term_el);
150 binary_write(*fp, seq_term_lg);
154 * \brief Get the first entry while visiting the SeqEntry
155 * \return The first SQItem if found, otherwhise NULL
157 SQItem *SeqEntry::GetFirstSQItem()
159 ItSQItem = Items.begin();
160 if (ItSQItem != Items.end())
166 * \brief Get the next SQItem while visiting the SeqEntry
167 * \note : meaningfull only if GetFirstEntry already called
168 * \return The next SQItem if found, otherwhise NULL
171 SQItem *SeqEntry::GetNextSQItem()
173 gdcmAssertMacro (ItSQItem != Items.end())
176 if (ItSQItem != Items.end())
183 * \brief return a pointer to the SQItem referenced by its ordinal number.
184 * Returns the first item when argument is negative.
185 * Returns the last item when argument is bigger than the total
188 SQItem *SeqEntry::GetSQItem(int nb)
192 return *(Items.begin());
195 for(ListSQItem::iterator cc = Items.begin();
204 return *(Items.end()); // Euhhhhh ?!? Is this the last one . FIXME
207 unsigned int SeqEntry::GetNumberOfSQItems()
212 /// \brief adds the passed ITEM to the ITEM chained List for this SeQuence.
213 void SeqEntry::AddSQItem(SQItem *sqItem, int itemNumber)
215 sqItem->SetSQItemNumber(itemNumber);
216 Items.push_back(sqItem);
219 //-----------------------------------------------------------------------------
223 //-----------------------------------------------------------------------------
226 //-----------------------------------------------------------------------------
227 } // end namespace gdcm