1 /*=========================================================================
4 Module: $RCSfile: gdcmSeqEntry.cxx,v $
6 Date: $Date: 2004/07/21 14:02:11 $
7 Version: $Revision: 1.22 $
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;
42 * \brief Canonical destructor.
44 gdcmSeqEntry::~gdcmSeqEntry() {
45 for(ListSQItem::iterator cc = items.begin();cc != items.end();++cc)
54 * \brief canonical Printer
56 void gdcmSeqEntry::Print(std::ostream &os){
58 // First, Print the Dicom Element itself.
60 gdcmDocEntry::Print(os);
63 if (GetReadLength() == 0)
66 // Then, Print each SQ Item
67 for(ListSQItem::iterator cc = items.begin();cc != items.end();++cc)
72 // at end, print the sequence terminator item, if any
74 for (int i=0;i<SQDepthLevel+1;i++)
76 if (seq_term != NULL) {
82 os << " -------------- should have a sequence terminator item";
87 * \brief canonical Writer
89 void gdcmSeqEntry::Write(FILE *fp, FileType filetype)
91 uint16_t seq_term_gr = 0xfffe;
92 uint16_t seq_term_el = 0xe0dd;
93 uint32_t seq_term_lg = 0x00000000;
95 uint16_t item_term_gr = 0xfffe;
96 uint16_t item_term_el = 0xe00d;
98 gdcmDocEntry::Write(fp, filetype);
99 for(ListSQItem::iterator cc = GetSQItems().begin();
100 cc != GetSQItems().end();
103 (*cc)->Write(fp, filetype);
105 fwrite ( &item_term_gr,(size_t)2 ,(size_t)1 ,fp);
106 fwrite ( &item_term_el,(size_t)2 ,(size_t)1 ,fp);
107 fwrite ( &seq_term_lg, (size_t)4 ,(size_t)1 ,fp); // Heu .....
109 //we force the writting of a Sequence Delimitaion item
110 // because we wrote the Sequence as a 'no Length' sequence
111 fwrite ( &seq_term_gr,(size_t)2 ,(size_t)1 ,fp);
112 fwrite ( &seq_term_el,(size_t)2 ,(size_t)1 ,fp);
113 fwrite ( &seq_term_lg,(size_t)4 ,(size_t)1 ,fp);
116 //-----------------------------------------------------------------------------
119 /// \brief adds the passed ITEM to the ITEM chained List for this SeQuence.
120 void gdcmSeqEntry::AddEntry(gdcmSQItem *sqItem, int itemNumber) {
121 sqItem->SetSQItemNumber(itemNumber);
122 items.push_back(sqItem);
125 /// \brief Sets the depth level of a Sequence Entry embedded in a SeQuence
126 void gdcmSeqEntry::SetDepthLevel(int depth) {
127 SQDepthLevel = depth;
130 /// \brief return a pointer to the SQItem referenced by its ordinal number
131 /// (returns the first one if ordinal number is <0
132 /// returns the last one if ordinal number is > item number
134 gdcmSQItem *gdcmSeqEntry::GetSQItemByOrdinalNumber(int nb) {
136 return (*(items.begin()));
138 for(ListSQItem::iterator cc = items.begin();
144 return (*(items.end())); // Euhhhhh ?!? Is this the last one . FIXME
146 //-----------------------------------------------------------------------------
150 //-----------------------------------------------------------------------------
153 //-----------------------------------------------------------------------------