]> Creatis software - gdcm.git/blob - src/gdcmSeqEntry.cxx
6026a867e9b6187746f41fdf49450b7b2355ed2a
[gdcm.git] / src / gdcmSeqEntry.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmSeqEntry.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/06/23 15:01:57 $
7   Version:   $Revision: 1.19 $
8                                                                                 
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.
12                                                                                 
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.
16                                                                                 
17 =========================================================================*/
18
19 #include "gdcmSeqEntry.h"
20 #include "gdcmSQItem.h"
21 #include "gdcmTS.h"
22 #include "gdcmGlobal.h"
23 #include "gdcmUtil.h"
24
25 #include <iostream>
26 #include <iomanip>
27 //-----------------------------------------------------------------------------
28 // Constructor / Destructor
29 /**
30  * \ingroup gdcmSeqEntry
31  * \brief   Constructor from a given gdcmSeqEntry
32  */
33 gdcmSeqEntry::gdcmSeqEntry(gdcmDictEntry* e, int depth) 
34              : gdcmDocEntry(e)
35 {
36    delimitor_mode = false;
37    seq_term  = NULL;
38    SQDepthLevel = depth;
39 }
40
41 /**
42  * \brief   Canonical destructor.
43  */
44 gdcmSeqEntry::~gdcmSeqEntry() {
45    for(ListSQItem::iterator cc = items.begin();cc != items.end();++cc)
46    {
47       delete *cc;
48      std::cout << "delete SQItem" <<std:: endl;
49    }
50    if (!seq_term)
51       delete seq_term;
52 }
53
54 /*
55  * \brief   canonical Printer
56  */
57 void gdcmSeqEntry::Print(std::ostream &os){
58
59    // First, Print the Dicom Element itself.
60    SetPrintLevel(2);   
61    gdcmDocEntry::Print(os);
62    os << std::endl;
63
64    if (GetReadLength() == 0)
65       return;
66
67    // Then, Print each SQ Item   
68    for(ListSQItem::iterator cc = items.begin();cc != items.end();++cc)
69    {
70       (*cc)->Print(os);   
71    }
72
73    // at end, print the sequence terminator item, if any
74    if (delimitor_mode) {
75       for (int i=0;i<SQDepthLevel+1;i++)
76          os << "   | " ;
77       if (seq_term != NULL) {
78          seq_term->Print(os);
79          os << std::endl;
80       } 
81       else 
82          os << "      -------------- should have a sequence terminator item";
83    }                    
84 }
85
86 /*
87  * \brief   canonical Writer
88  */
89 void gdcmSeqEntry::Write(FILE *fp, FileType filetype)
90 {
91    gdcmDocEntry::Write(fp, filetype);
92    for(ListSQItem::iterator cc  = GetSQItems().begin();
93                             cc != GetSQItems().end();
94                           ++cc)
95    {
96       (*cc)->Write(fp, filetype);   
97    }  
98 }
99
100 //-----------------------------------------------------------------------------
101 // Public
102
103  /// \brief   adds the passed ITEM to the ITEM chained List for this SeQuence.      
104 void gdcmSeqEntry::AddEntry(gdcmSQItem *sqItem, int itemNumber) {
105    sqItem->SetSQItemNumber(itemNumber);
106    items.push_back(sqItem);
107 }
108
109 /// \brief Sets the depth level of a Sequence Entry embedded in a SeQuence 
110 void gdcmSeqEntry::SetDepthLevel(int depth) {
111    SQDepthLevel = depth;
112 }
113
114 /// \brief return a pointer to the SQItem referenced by its ordinal number
115 /// (returns the first one if ordinal number is <0
116 ///  returns the last  one if ordinal number is > item number
117
118 gdcmSQItem *gdcmSeqEntry::GetSQItemByOrdinalNumber(int nb) {
119    if (nb<0)
120       return (*(items.begin()));
121    int count = 0 ;
122    for(ListSQItem::iterator cc = items.begin();
123        cc != items.end();
124        count ++, ++cc){
125       if (count==nb)
126          return *cc;
127    }
128    return (*(items.end())); // Euhhhhh ?!? Is this the last one . FIXME
129 }
130 //-----------------------------------------------------------------------------
131 // Protected
132
133
134 //-----------------------------------------------------------------------------
135 // Private
136
137 //-----------------------------------------------------------------------------