1 /*=========================================================================
4 Module: $RCSfile: gdcmSeqEntry.cxx,v $
6 Date: $Date: 2004/10/22 03:05:42 $
7 Version: $Revision: 1.32 $
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 delimitor_mode = 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() )
57 this->UsableLength = 0;
58 this->ReadLength = 0xffffffff;
61 this->ImplicitVR = e->IsImplicitVR();
62 this->Offset = e->GetOffset();
66 * \brief Canonical destructor.
68 SeqEntry::~SeqEntry() {
69 for(ListSQItem::iterator cc = items.begin();cc != items.end();++cc)
78 * \brief canonical Printer
80 void SeqEntry::Print( std::ostream &os )
82 // First, Print the Dicom Element itself.
87 if (GetReadLength() == 0)
90 // Then, Print each SQ Item
91 for(ListSQItem::iterator cc = items.begin();cc != items.end();++cc)
96 // at end, print the sequence terminator item, if any
98 for ( int i = 0; i < SQDepthLevel; i++ )
102 if (seq_term != NULL)
110 os << " -------------- should have a sequence terminator item";
116 * \brief canonical Writer
118 void SeqEntry::Write(std::ofstream* fp, FileType filetype)
120 uint16_t seq_term_gr = 0xfffe;
121 uint16_t seq_term_el = 0xe0dd;
122 uint32_t seq_term_lg = 0xffffffff;
124 //uint16_t item_term_gr = 0xfffe;
125 //uint16_t item_term_el = 0xe00d;
127 DocEntry::Write(fp, filetype);
128 for(ListSQItem::iterator cc = GetSQItems().begin();
129 cc != GetSQItems().end();
132 (*cc)->Write(fp, filetype);
135 // we force the writting of a Sequence Delimitation item
136 // because we wrote the Sequence as a 'no Length' sequence
137 fp->write ( (char*)&seq_term_gr,(size_t)2 );
138 fp->write ( (char*)&seq_term_el,(size_t)2 );
139 fp->write ( (char*)&seq_term_lg,(size_t)4 );
142 //-----------------------------------------------------------------------------
145 /// \brief adds the passed ITEM to the ITEM chained List for this SeQuence.
146 void SeqEntry::AddEntry(SQItem *sqItem, int itemNumber)
148 sqItem->SetSQItemNumber(itemNumber);
149 items.push_back(sqItem);
153 * \brief return a pointer to the SQItem referenced by its ordinal number.
154 * Returns the first item when argument is negative.
155 * Returns the last item when argument is bigget than the total
158 SQItem* SeqEntry::GetSQItemByOrdinalNumber(int nb)
161 return (*(items.begin()));
163 for(ListSQItem::iterator cc = items.begin();
169 return (*(items.end())); // Euhhhhh ?!? Is this the last one . FIXME
171 //-----------------------------------------------------------------------------
175 //-----------------------------------------------------------------------------
178 //-----------------------------------------------------------------------------
179 } // end namespace gdcm