]> Creatis software - gdcm.git/blob - src/gdcmSeqEntry.cxx
* In order to fix memory leaks:
[gdcm.git] / src / gdcmSeqEntry.cxx
1 // gdcmSeqEntry.cxx
2 //-----------------------------------------------------------------------------
3 //
4 #include "gdcmSeqEntry.h"
5 #include "gdcmSQItem.h"
6 #include "gdcmTS.h"
7 #include "gdcmGlobal.h"
8 #include "gdcmUtil.h"
9
10 #include <iostream>
11 #include <iomanip>
12 //-----------------------------------------------------------------------------
13 // Constructor / Destructor
14 /**
15  * \ingroup gdcmSeqEntry
16  * \brief   Constructor from a given gdcmSeqEntry
17  */
18 gdcmSeqEntry::gdcmSeqEntry(gdcmDictEntry* e, int depth) 
19              : gdcmDocEntry(e)
20 {
21    delimitor_mode = false;
22    seq_term  = NULL;
23    SQDepthLevel = depth;
24 }
25
26 /**
27  * \ingroup gdcmSeqEntry
28  * \brief   Canonical destructor.
29  */
30 gdcmSeqEntry::~gdcmSeqEntry() {
31    for(ListSQItem::iterator cc = items.begin();cc != items.end();++cc)
32    {
33       delete *cc;
34    }
35    if (!seq_term)
36       delete seq_term;
37 }
38
39 //-----------------------------------------------------------------------------
40 // Print
41 /*
42  * \ingroup gdcmSeqEntry
43  * \brief   canonical Printer
44  */
45 void gdcmSeqEntry::Print(std::ostream &os){
46
47    std::ostringstream s,s2;
48    std::string vr;
49    unsigned short int g, e;
50    long lgth;
51    size_t o;    
52    char greltag[10];  //group element tag
53    char st[20]; 
54
55    // First, Print the Dicom Element itself.
56    SetPrintLevel(2);   
57    PrintCommonPart(os);
58    s << std::endl;
59    os << s.str();   
60  
61     // Then, Print each SQ Item   
62      for(ListSQItem::iterator cc = items.begin();cc != items.end();++cc)
63    {                            
64       (*cc)->Print(os);   
65    }
66    // at end, print the sequence terminator item, if any
67
68    if (delimitor_mode) {
69       if (SQDepthLevel>0) {
70          for (int i=0;i<SQDepthLevel;i++)
71             s2 << "   | " ;
72       }         
73       os << s2.str();
74       if (seq_term != NULL) {
75          seq_term->Print(os);
76       } 
77       else 
78          std::cout
79              << "      -------------- should have a sequence terminator item"
80              << std::endl;      
81    }                    
82  }
83
84 //-----------------------------------------------------------------------------
85 // Public
86
87  /// \brief   adds the passed ITEM to the ITEM chained List for this SeQuence.      
88 void gdcmSeqEntry::AddEntry(gdcmSQItem *sqItem, int itemNumber) {
89    sqItem->SetSQItemNumber(itemNumber);
90    items.push_back(sqItem);
91 }
92
93 /// \brief Sets the depth level of a Sequence Entry embedded in a SeQuence 
94 void gdcmSeqEntry::SetDepthLevel(int depth) {
95    SQDepthLevel = depth;
96 }
97
98 /// \brief return a pointer to th SQItem referenced by its ordinal number
99 /// (returns the first one if ordinal number is <0
100 ///  returns the last  one if ordinal number is > item number
101
102 gdcmSQItem *gdcmSeqEntry::GetSQItemByOrdinalNumber(int nb) {
103    if (nb<0)
104                 return (*(items.begin()));
105         int count = 0 ;
106    for(ListSQItem::iterator cc = items.begin();
107             cc != items.end();
108                  count ++, ++cc){       
109       if (count==nb)
110                    return (*cc);      
111    }
112         return (*(items.end()));                 
113 }
114 //-----------------------------------------------------------------------------
115 // Protected
116
117
118 //-----------------------------------------------------------------------------
119 // Private
120
121 //-----------------------------------------------------------------------------