1 /*=========================================================================
4 Module: $RCSfile: gdcmSeqEntry.cxx,v $
6 Date: $Date: 2004/10/12 04:35:48 $
7 Version: $Revision: 1.31 $
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"
31 //-----------------------------------------------------------------------------
32 // Constructor / Destructor
35 * \brief Constructor from a given SeqEntry
37 SeqEntry::SeqEntry( DictEntry* e )
41 ReadLength = 0xffffffff;
44 delimitor_mode = 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() )
56 this->UsableLength = 0;
57 this->ReadLength = 0xffffffff;
60 this->ImplicitVR = e->IsImplicitVR();
61 this->Offset = e->GetOffset();
65 * \brief Canonical destructor.
67 SeqEntry::~SeqEntry() {
68 for(ListSQItem::iterator cc = items.begin();cc != items.end();++cc)
77 * \brief canonical Printer
79 void SeqEntry::Print( std::ostream &os )
81 // First, Print the Dicom Element itself.
86 if (GetReadLength() == 0)
89 // Then, Print each SQ Item
90 for(ListSQItem::iterator cc = items.begin();cc != items.end();++cc)
95 // at end, print the sequence terminator item, if any
97 for ( int i = 0; i < SQDepthLevel; i++ )
101 if (seq_term != NULL)
109 os << " -------------- should have a sequence terminator item";
115 * \brief canonical Writer
117 void SeqEntry::Write(FILE* fp, FileType filetype)
119 uint16_t seq_term_gr = 0xfffe;
120 uint16_t seq_term_el = 0xe0dd;
121 uint32_t seq_term_lg = 0xffffffff;
123 //uint16_t item_term_gr = 0xfffe;
124 //uint16_t item_term_el = 0xe00d;
126 DocEntry::Write(fp, filetype);
127 for(ListSQItem::iterator cc = GetSQItems().begin();
128 cc != GetSQItems().end();
131 (*cc)->Write(fp, filetype);
134 // we force the writting of a Sequence Delimitation item
135 // because we wrote the Sequence as a 'no Length' sequence
136 fwrite ( &seq_term_gr,(size_t)2 ,(size_t)1 ,fp);
137 fwrite ( &seq_term_el,(size_t)2 ,(size_t)1 ,fp);
138 fwrite ( &seq_term_lg,(size_t)4 ,(size_t)1 ,fp);
141 //-----------------------------------------------------------------------------
144 /// \brief adds the passed ITEM to the ITEM chained List for this SeQuence.
145 void SeqEntry::AddEntry(SQItem *sqItem, int itemNumber)
147 sqItem->SetSQItemNumber(itemNumber);
148 items.push_back(sqItem);
152 * \brief return a pointer to the SQItem referenced by its ordinal number.
153 * Returns the first item when argument is negative.
154 * Returns the last item when argument is bigget than the total
157 SQItem* SeqEntry::GetSQItemByOrdinalNumber(int nb)
160 return (*(items.begin()));
162 for(ListSQItem::iterator cc = items.begin();
168 return (*(items.end())); // Euhhhhh ?!? Is this the last one . FIXME
170 //-----------------------------------------------------------------------------
174 //-----------------------------------------------------------------------------
177 //-----------------------------------------------------------------------------
178 } // end namespace gdcm