1 /*=========================================================================
4 Module: $RCSfile: gdcmSeqEntry.cxx,v $
6 Date: $Date: 2004/09/13 12:10:53 $
7 Version: $Revision: 1.27 $
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.htm 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, int depth)
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+1;i++)
95 if (seq_term != NULL) {
101 os << " -------------- should have a sequence terminator item";
106 * \brief canonical Writer
108 void gdcmSeqEntry::Write(FILE *fp, FileType filetype)
110 uint16_t seq_term_gr = 0xfffe;
111 uint16_t seq_term_el = 0xe0dd;
112 uint32_t seq_term_lg = 0xffffffff;
114 //uint16_t item_term_gr = 0xfffe;
115 //uint16_t item_term_el = 0xe00d;
117 gdcmDocEntry::Write(fp, filetype);
118 for(ListSQItem::iterator cc = GetSQItems().begin();
119 cc != GetSQItems().end();
122 (*cc)->Write(fp, filetype);
125 // we force the writting of a Sequence Delimitation item
126 // because we wrote the Sequence as a 'no Length' sequence
127 fwrite ( &seq_term_gr,(size_t)2 ,(size_t)1 ,fp);
128 fwrite ( &seq_term_el,(size_t)2 ,(size_t)1 ,fp);
129 fwrite ( &seq_term_lg,(size_t)4 ,(size_t)1 ,fp);
132 //-----------------------------------------------------------------------------
135 /// \brief adds the passed ITEM to the ITEM chained List for this SeQuence.
136 void gdcmSeqEntry::AddEntry(gdcmSQItem *sqItem, int itemNumber)
138 sqItem->SetSQItemNumber(itemNumber);
139 items.push_back(sqItem);
143 * \brief return a pointer to the SQItem referenced by its ordinal number.
144 * Returns the first item when argument is negative.
145 * Returns the last item when argument is bigget than the total
148 gdcmSQItem *gdcmSeqEntry::GetSQItemByOrdinalNumber(int nb)
151 return (*(items.begin()));
153 for(ListSQItem::iterator cc = items.begin();
159 return (*(items.end())); // Euhhhhh ?!? Is this the last one . FIXME
161 //-----------------------------------------------------------------------------
165 //-----------------------------------------------------------------------------
168 //-----------------------------------------------------------------------------