1 /*=========================================================================
4 Module: $RCSfile: gdcmSeqEntry.cxx,v $
6 Date: $Date: 2004/08/27 15:48:44 $
7 Version: $Revision: 1.24 $
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)
36 delimitor_mode = false;
40 ReadLength = 0xffffffff;
44 * \brief Constructor from a given gdcmSeqEntry
45 * @param e Pointer to existing Doc entry
47 gdcmSeqEntry::gdcmSeqEntry(gdcmDocEntry* e, int depth) : gdcmDocEntry(e->GetDictEntry())
49 this->UsableLength = 0;
50 this->ReadLength = 0xffffffff;
51 this->ImplicitVR = e->IsImplicitVR();
52 this->Offset = e->GetOffset();
53 //this->printLevel = e->GetPrintLevel(); // no longer exists ?!?
54 this->SQDepthLevel = depth;
57 * \brief Canonical destructor.
59 gdcmSeqEntry::~gdcmSeqEntry() {
60 for(ListSQItem::iterator cc = items.begin();cc != items.end();++cc)
69 * \brief canonical Printer
71 void gdcmSeqEntry::Print(std::ostream &os){
73 // First, Print the Dicom Element itself.
75 gdcmDocEntry::Print(os);
78 if (GetReadLength() == 0)
81 // Then, Print each SQ Item
82 for(ListSQItem::iterator cc = items.begin();cc != items.end();++cc)
87 // at end, print the sequence terminator item, if any
89 for (int i=0;i<SQDepthLevel+1;i++)
91 if (seq_term != NULL) {
97 os << " -------------- should have a sequence terminator item";
102 * \brief canonical Writer
104 void gdcmSeqEntry::Write(FILE *fp, FileType filetype)
106 uint16_t seq_term_gr = 0xfffe;
107 uint16_t seq_term_el = 0xe0dd;
108 uint32_t seq_term_lg = 0xffffffff;
110 uint16_t item_term_gr = 0xfffe;
111 uint16_t item_term_el = 0xe00d;
113 gdcmDocEntry::Write(fp, filetype);
114 for(ListSQItem::iterator cc = GetSQItems().begin();
115 cc != GetSQItems().end();
118 (*cc)->Write(fp, filetype);
121 //we force the writting of a Sequence Delimitation item
122 // because we wrote the Sequence as a 'no Length' sequence
123 fwrite ( &seq_term_gr,(size_t)2 ,(size_t)1 ,fp);
124 fwrite ( &seq_term_el,(size_t)2 ,(size_t)1 ,fp);
125 fwrite ( &seq_term_lg,(size_t)4 ,(size_t)1 ,fp);
128 //-----------------------------------------------------------------------------
131 /// \brief adds the passed ITEM to the ITEM chained List for this SeQuence.
132 void gdcmSeqEntry::AddEntry(gdcmSQItem *sqItem, int itemNumber) {
133 sqItem->SetSQItemNumber(itemNumber);
134 items.push_back(sqItem);
137 /// \brief Sets the depth level of a Sequence Entry embedded in a SeQuence
138 void gdcmSeqEntry::SetDepthLevel(int depth) {
139 SQDepthLevel = depth;
142 /// \brief return a pointer to the SQItem referenced by its ordinal number
143 /// (returns the first one if ordinal number is <0
144 /// returns the last one if ordinal number is > item number
146 gdcmSQItem *gdcmSeqEntry::GetSQItemByOrdinalNumber(int nb) {
148 return (*(items.begin()));
150 for(ListSQItem::iterator cc = items.begin();
156 return (*(items.end())); // Euhhhhh ?!? Is this the last one . FIXME
158 //-----------------------------------------------------------------------------
162 //-----------------------------------------------------------------------------
165 //-----------------------------------------------------------------------------