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