1 /*=========================================================================
4 Module: $RCSfile: gdcmSeqEntry.cxx,v $
6 Date: $Date: 2005/02/01 10:29:56 $
7 Version: $Revision: 1.52 $
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"
32 //-----------------------------------------------------------------------------
33 // Constructor / Destructor
35 * \brief Constructor from a given SeqEntry
37 SeqEntry::SeqEntry( DictEntry *e )
41 ReadLength = 0xffffffff;
44 DelimitorMode = false;
49 * \brief Constructor from a given SeqEntry
50 * @param e Pointer to existing Doc entry
51 * @param depth depth level of the current Seq entry
53 SeqEntry::SeqEntry( DocEntry *e, int depth )
54 : DocEntry( e->GetDictEntry() )
57 ReadLength = 0xffffffff;
60 ImplicitVR = e->IsImplicitVR();
61 Offset = e->GetOffset();
66 * \brief Canonical destructor.
70 for(ListSQItem::iterator cc = Items.begin(); cc != Items.end(); ++cc)
80 //-----------------------------------------------------------------------------
83 * \brief canonical Writer
84 * @param fp pointer to an already open file
85 * @param filetype type of the file (ACR, ImplicitVR, ExplicitVR, ...)
87 void SeqEntry::WriteContent(std::ofstream *fp, FileType filetype)
89 uint16_t seq_term_gr = 0xfffe;
90 uint16_t seq_term_el = 0xe0dd;
91 uint32_t seq_term_lg = 0xffffffff;
93 //uint16_t item_term_gr = 0xfffe;
94 //uint16_t item_term_el = 0xe00d;
96 DocEntry::WriteContent(fp, filetype);
97 for(ListSQItem::iterator cc = Items.begin();
101 (*cc)->WriteContent(fp, filetype);
104 // we force the writting of a Sequence Delimitation item
105 // because we wrote the Sequence as a 'no Length' sequence
106 binary_write(*fp, seq_term_gr);
107 binary_write(*fp, seq_term_el);
108 binary_write(*fp, seq_term_lg);
112 * \brief Get the first entry while visiting the SeqEntry
113 * \return The first SQItem if found, otherwhise NULL
115 SQItem *SeqEntry::GetFirstSQItem()
117 ItSQItem = Items.begin();
118 if (ItSQItem != Items.end())
124 * \brief Get the next SQItem while visiting the SeqEntry
125 * \note : meaningfull only if GetFirstEntry already called
126 * \return The next SQItem if found, otherwhise NULL
129 SQItem *SeqEntry::GetNextSQItem()
131 gdcmAssertMacro (ItSQItem != Items.end())
134 if (ItSQItem != Items.end())
141 * \brief return a pointer to the SQItem referenced by its ordinal number.
142 * Returns the first item when argument is negative.
143 * Returns the last item when argument is bigger than the total
146 SQItem *SeqEntry::GetSQItem(int nb)
150 return *(Items.begin());
153 for(ListSQItem::iterator cc = Items.begin();
162 return *(Items.end());
166 * \brief returns the number of SQItems within the current Sequence
168 unsigned int SeqEntry::GetNumberOfSQItems()
174 * \brief adds the passed ITEM to the ITEM chained List for this SeQuence.
175 * @param sqItem SQItem to be pushed back in the SeqEntry
176 * @param itemNumber ordinal number of the SQItem
177 * \note NOT end-user intendend method !
179 void SeqEntry::AddSQItem(SQItem *sqItem, int itemNumber)
181 // FIXME : SQItemNumber is supposed to be the ordinal number of the SQItem
182 // within the Sequence.
183 // Either only 'push_back' is allowed,
184 // and we just have to do something like SeqEntry::lastNb++
185 // Or we can add (or remove) anywhere, and SQItemNumber will be broken
186 sqItem->SetSQItemNumber(itemNumber);
187 Items.push_back(sqItem);
190 //-----------------------------------------------------------------------------
194 //-----------------------------------------------------------------------------
197 //-----------------------------------------------------------------------------
200 * \brief canonical Printer
202 void SeqEntry::Print( std::ostream &os, std::string const & )
204 // First, Print the Dicom Element itself.
209 if (GetReadLength() == 0)
212 // Then, Print each SQ Item
213 for(ListSQItem::iterator cc = Items.begin(); cc != Items.end(); ++cc)
215 (*cc)->SetPrintLevel(PrintLevel);
219 // at end, print the sequence terminator item, if any
222 for ( int i = 0; i < SQDepthLevel; i++ )
228 SeqTerm->SetPrintLevel(PrintLevel);
235 gdcmVerboseMacro(" -------- should have a sequence terminator item");
240 //-----------------------------------------------------------------------------
241 } // end namespace gdcm