1 /*=========================================================================
4 Module: $RCSfile: gdcmSeqEntry.cxx,v $
6 Date: $Date: 2004/09/27 08:39:07 $
7 Version: $Revision: 1.30 $
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"
27 //-----------------------------------------------------------------------------
28 // Constructor / Destructor
30 * \ingroup gdcmSeqEntry
31 * \brief Constructor from a given gdcmSeqEntry
33 gdcmSeqEntry::gdcmSeqEntry( gdcmDictEntry* e )
37 ReadLength = 0xffffffff;
40 delimitor_mode = false;
45 * \brief Constructor from a given gdcmSeqEntry
46 * @param e Pointer to existing Doc entry
47 * @param depth depth level of the current Seq entry
49 gdcmSeqEntry::gdcmSeqEntry( gdcmDocEntry* e, int depth )
50 : gdcmDocEntry( e->GetDictEntry() )
52 this->UsableLength = 0;
53 this->ReadLength = 0xffffffff;
56 this->ImplicitVR = e->IsImplicitVR();
57 this->Offset = e->GetOffset();
61 * \brief Canonical destructor.
63 gdcmSeqEntry::~gdcmSeqEntry() {
64 for(ListSQItem::iterator cc = items.begin();cc != items.end();++cc)
73 * \brief canonical Printer
75 void gdcmSeqEntry::Print( std::ostream &os )
77 // First, Print the Dicom Element itself.
79 gdcmDocEntry::Print(os);
82 if (GetReadLength() == 0)
85 // Then, Print each SQ Item
86 for(ListSQItem::iterator cc = items.begin();cc != items.end();++cc)
91 // at end, print the sequence terminator item, if any
93 for ( int i = 0; i < SQDepthLevel; i++ )
105 os << " -------------- should have a sequence terminator item";
111 * \brief canonical Writer
113 void gdcmSeqEntry::Write(FILE* fp, FileType filetype)
115 uint16_t seq_term_gr = 0xfffe;
116 uint16_t seq_term_el = 0xe0dd;
117 uint32_t seq_term_lg = 0xffffffff;
119 //uint16_t item_term_gr = 0xfffe;
120 //uint16_t item_term_el = 0xe00d;
122 gdcmDocEntry::Write(fp, filetype);
123 for(ListSQItem::iterator cc = GetSQItems().begin();
124 cc != GetSQItems().end();
127 (*cc)->Write(fp, filetype);
130 // we force the writting of a Sequence Delimitation item
131 // because we wrote the Sequence as a 'no Length' sequence
132 fwrite ( &seq_term_gr,(size_t)2 ,(size_t)1 ,fp);
133 fwrite ( &seq_term_el,(size_t)2 ,(size_t)1 ,fp);
134 fwrite ( &seq_term_lg,(size_t)4 ,(size_t)1 ,fp);
137 //-----------------------------------------------------------------------------
140 /// \brief adds the passed ITEM to the ITEM chained List for this SeQuence.
141 void gdcmSeqEntry::AddEntry(gdcmSQItem *sqItem, int itemNumber)
143 sqItem->SetSQItemNumber(itemNumber);
144 items.push_back(sqItem);
148 * \brief return a pointer to the SQItem referenced by its ordinal number.
149 * Returns the first item when argument is negative.
150 * Returns the last item when argument is bigget than the total
153 gdcmSQItem* gdcmSeqEntry::GetSQItemByOrdinalNumber(int nb)
156 return (*(items.begin()));
158 for(ListSQItem::iterator cc = items.begin();
164 return (*(items.end())); // Euhhhhh ?!? Is this the last one . FIXME
166 //-----------------------------------------------------------------------------
170 //-----------------------------------------------------------------------------
173 //-----------------------------------------------------------------------------