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