1 /*=========================================================================
4 Module: $RCSfile: gdcmSeqEntry.cxx,v $
6 Date: $Date: 2005/10/25 14:52:35 $
7 Version: $Revision: 1.60 $
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 DocEntry
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.
73 //-----------------------------------------------------------------------------
76 * \brief canonical Writer
77 * @param fp pointer to an already open file
78 * @param filetype type of the file (ACR, ImplicitVR, ExplicitVR, ...)
80 void SeqEntry::WriteContent(std::ofstream *fp, FileType filetype)
82 uint16_t seq_term_gr = 0xfffe;
83 uint16_t seq_term_el = 0xe0dd;
84 uint32_t seq_term_lg = 0xffffffff;
86 //uint16_t item_term_gr = 0xfffe;
87 //uint16_t item_term_el = 0xe00d;
89 DocEntry::WriteContent(fp, filetype);
90 for(ListSQItem::iterator cc = Items.begin();
94 (*cc)->WriteContent(fp, filetype);
97 // we force the writting of a Sequence Delimitation item
98 // because we wrote the Sequence as a 'no Length' sequence
99 binary_write(*fp, seq_term_gr);
100 binary_write(*fp, seq_term_el);
101 binary_write(*fp, seq_term_lg);
105 * \brief adds the passed ITEM to the ITEM chained List for this SeQuence.
106 * @param sqItem SQItem to be pushed back in the SeqEntry
107 * @param itemNumber ordinal number of the SQItem
108 * \note NOT end-user intendend method !
110 void SeqEntry::AddSQItem(SQItem *sqItem, int itemNumber)
112 // FIXME : SQItemNumber is supposed to be the ordinal number of the SQItem
113 // within the Sequence.
114 // Either only 'push_back' is allowed,
115 // and we just have to do something like SeqEntry::lastNb++
116 // Or we can add (or remove) anywhere, and SQItemNumber will be broken
117 sqItem->SetSQItemNumber(itemNumber);
118 Items.push_back(sqItem);
123 * \brief Remove all SQItem.
125 void SeqEntry::ClearSQItem()
127 for(ListSQItem::iterator cc = Items.begin(); cc != Items.end(); ++cc)
133 SeqTerm->Unregister();
138 * \brief Get the first entry while visiting the SeqEntry
139 * \return The first SQItem if found, otherwhise NULL
141 SQItem *SeqEntry::GetFirstSQItem()
143 ItSQItem = Items.begin();
144 if (ItSQItem != Items.end())
150 * \brief Get the next SQItem while visiting the SeqEntry
151 * \note : meaningfull only if GetFirstEntry already called
152 * \return The next SQItem if found, otherwhise NULL
155 SQItem *SeqEntry::GetNextSQItem()
157 gdcmAssertMacro (ItSQItem != Items.end())
160 if (ItSQItem != Items.end())
167 * \brief return a pointer to the SQItem referenced by its ordinal number.
168 * Returns the first item when argument is negative.
169 * Returns the last item when argument is bigger than the total
172 SQItem *SeqEntry::GetSQItem(int nb)
176 return *(Items.begin());
179 for(ListSQItem::iterator cc = Items.begin();
188 return *(Items.end());
192 * \brief returns the number of SQItems within the current Sequence
194 unsigned int SeqEntry::GetNumberOfSQItems()
200 * \brief Sets the Sequence Delimitation Item
201 * \param e Delimitation item
203 void SeqEntry::SetDelimitationItem(DocEntry *e)
208 SeqTerm->Unregister();
215 //-----------------------------------------------------------------------------
219 //-----------------------------------------------------------------------------
222 //-----------------------------------------------------------------------------
225 * \brief canonical Printer
227 void SeqEntry::Print( std::ostream &os, std::string const & )
229 // First, Print the Dicom Element itself.
234 if (GetReadLength() == 0)
237 // Then, Print each SQ Item
238 for(ListSQItem::iterator cc = Items.begin(); cc != Items.end(); ++cc)
240 (*cc)->SetPrintLevel(PrintLevel);
244 // at end, print the sequence terminator item, if any
248 for ( i = 0; i < SQDepthLevel; i++ )
250 os << " --- " << std::endl;
251 for ( i = 0; i < SQDepthLevel; i++ )
255 SeqTerm->SetPrintLevel(PrintLevel);
262 gdcmWarningMacro(" -------- should have a sequence terminator item");
267 //-----------------------------------------------------------------------------
268 } // end namespace gdcm