1 /*=========================================================================
4 Module: $RCSfile: gdcmSeqEntry.cxx,v $
6 Date: $Date: 2004/08/26 15:29:53 $
7 Version: $Revision: 1.23 $
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 = e->GetDepthLevel();
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 = 0x00000000;
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);
120 //we force the writting of an Item Delimitation item
121 // because we wrote the Item as a 'no Length' item
122 fwrite ( &item_term_gr,(size_t)2 ,(size_t)1 ,fp);
123 fwrite ( &item_term_el,(size_t)2 ,(size_t)1 ,fp);
124 fwrite ( &seq_term_lg, (size_t)4 ,(size_t)1 ,fp); // Heu .....
127 //we force the writting of a Sequence Delimitation item
128 // because we wrote the Sequence as a 'no Length' sequence
129 fwrite ( &seq_term_gr,(size_t)2 ,(size_t)1 ,fp);
130 fwrite ( &seq_term_el,(size_t)2 ,(size_t)1 ,fp);
131 fwrite ( &seq_term_lg,(size_t)4 ,(size_t)1 ,fp);
134 //-----------------------------------------------------------------------------
137 /// \brief adds the passed ITEM to the ITEM chained List for this SeQuence.
138 void gdcmSeqEntry::AddEntry(gdcmSQItem *sqItem, int itemNumber) {
139 sqItem->SetSQItemNumber(itemNumber);
140 items.push_back(sqItem);
143 /// \brief Sets the depth level of a Sequence Entry embedded in a SeQuence
144 void gdcmSeqEntry::SetDepthLevel(int depth) {
145 SQDepthLevel = depth;
148 /// \brief return a pointer to the SQItem referenced by its ordinal number
149 /// (returns the first one if ordinal number is <0
150 /// returns the last one if ordinal number is > item number
152 gdcmSQItem *gdcmSeqEntry::GetSQItemByOrdinalNumber(int nb) {
154 return (*(items.begin()));
156 for(ListSQItem::iterator cc = items.begin();
162 return (*(items.end())); // Euhhhhh ?!? Is this the last one . FIXME
164 //-----------------------------------------------------------------------------
168 //-----------------------------------------------------------------------------
171 //-----------------------------------------------------------------------------