]> Creatis software - gdcm.git/blob - src/gdcmSeqEntry.cxx
remove 'tab' caracters
[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 03:36:24 $
7   Version:   $Revision: 1.17 $
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  * \ingroup gdcmSeqEntry
43  * \brief   Canonical destructor.
44  */
45 gdcmSeqEntry::~gdcmSeqEntry() {
46    for(ListSQItem::iterator cc = items.begin();cc != items.end();++cc)
47    {
48       delete *cc;
49      std::cout << "delete SQItem" <<std:: endl;
50    }
51    if (!seq_term)
52       delete seq_term;
53 }
54
55 //-----------------------------------------------------------------------------
56 // Print
57 /*
58  * \brief   canonical Printer
59  */
60 void gdcmSeqEntry::Print(std::ostream &os){
61
62    std::ostringstream s,s2;
63    std::string vr;
64    // First, Print the Dicom Element itself.
65    SetPrintLevel(2);   
66    PrintCommonPart(os);
67    s << std::endl;
68    os << s.str();   
69
70     if (GetReadLength() == 0)
71        return;
72
73     // Then, Print each SQ Item   
74      for(ListSQItem::iterator cc = items.begin();cc != items.end();++cc)
75    {
76       (*cc)->Print(os);   
77    }
78
79    // at end, print the sequence terminator item, if any
80    if (delimitor_mode) {
81       for (int i=0;i<SQDepthLevel+1;i++)
82          s2 << "   | " ;
83       os << s2.str();
84       if (seq_term != NULL) {
85          seq_term->Print(os);
86       } 
87       else 
88          std::cout
89              << "      -------------- should have a sequence terminator item"
90              << std::endl;      
91    }                    
92  }
93
94
95 /*
96  * \brief   canonical Writer
97  */
98 void gdcmSeqEntry::Write(FILE *fp, FileType filetype) {
99   for(ListSQItem::iterator cc  = GetSQItems().begin();
100                            cc != GetSQItems().end();
101                          ++cc) {
102       std::cout << "Et un SQItem !" << std::endl;
103       (*cc)->Write(fp, filetype);  // Don't remove param filetype !
104    }  
105 }
106 //-----------------------------------------------------------------------------
107 // Public
108
109  /// \brief   adds the passed ITEM to the ITEM chained List for this SeQuence.      
110 void gdcmSeqEntry::AddEntry(gdcmSQItem *sqItem, int itemNumber) {
111    sqItem->SetSQItemNumber(itemNumber);
112    items.push_back(sqItem);
113 }
114
115 /// \brief Sets the depth level of a Sequence Entry embedded in a SeQuence 
116 void gdcmSeqEntry::SetDepthLevel(int depth) {
117    SQDepthLevel = depth;
118 }
119
120 /// \brief return a pointer to the SQItem referenced by its ordinal number
121 /// (returns the first one if ordinal number is <0
122 ///  returns the last  one if ordinal number is > item number
123
124 gdcmSQItem *gdcmSeqEntry::GetSQItemByOrdinalNumber(int nb) {
125    if (nb<0)
126       return (*(items.begin()));
127    int count = 0 ;
128    for(ListSQItem::iterator cc = items.begin();
129        cc != items.end();
130        count ++, ++cc){
131       if (count==nb)
132          return *cc;
133    }
134    return (*(items.end())); // Euhhhhh ?!? Is this the last one . FIXME
135 }
136 //-----------------------------------------------------------------------------
137 // Protected
138
139
140 //-----------------------------------------------------------------------------
141 // Private
142
143 //-----------------------------------------------------------------------------