]> Creatis software - gdcm.git/blob - src/gdcmDicomDirStudy.cxx
-add method GetFirstEntry to replace call to InitTraversal+GetNextEntry
[gdcm.git] / src / gdcmDicomDirStudy.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDirStudy.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/18 07:53:42 $
7   Version:   $Revision: 1.25 $
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.html 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 "gdcmDicomDirStudy.h"
20 #include "gdcmDicomDirElement.h"
21 #include "gdcmGlobal.h"
22 #include "gdcmDicomDirSerie.h"
23
24 namespace gdcm 
25 {
26 //-----------------------------------------------------------------------------
27 // Constructor / Destructor
28 /**
29  * \brief  Constructor 
30  */
31 DicomDirStudy::DicomDirStudy():
32    DicomDirObject()
33 {
34 }
35 /**
36  * \brief   Canonical destructor.
37  */
38 DicomDirStudy::~DicomDirStudy() 
39 {
40    for(ListDicomDirSerie::iterator cc = Series.begin();
41                                    cc != Series.end();
42                                  ++cc )
43    {
44       delete *cc;
45    }
46 }
47
48 //-----------------------------------------------------------------------------
49 // Print
50 /**
51  * \brief   Prints the Object
52  * @param os ostream to write to 
53  * @return
54  */ 
55 void DicomDirStudy::Print(std::ostream &os, std::string const & )
56 {
57    os << "STUDY" << std::endl;
58    DicomDirObject::Print(os);
59
60    for(ListDicomDirSerie::iterator cc = Series.begin();
61                                    cc != Series.end();
62                                    ++cc)
63    {
64       (*cc)->SetPrintLevel(PrintLevel);
65       (*cc)->Print(os);
66    }
67 }
68
69 //-----------------------------------------------------------------------------
70 // Public
71
72 /**
73  * \brief   Writes the Object
74  * @param fp ofstream to write to
75  * @param t Type of the File (explicit VR, implicitVR, ...) 
76  * @return
77  */ 
78 void DicomDirStudy::WriteContent(std::ofstream *fp, FileType t)
79 {
80    DicomDirObject::WriteContent(fp, t);
81
82    for(ListDicomDirSerie::iterator cc = Series.begin();
83                                    cc!= Series.end();
84                                  ++cc )
85    {
86       (*cc)->WriteContent( fp, t );
87    }
88 }
89
90 /**
91  * \brief   adds a new Serie at the begining of the SerieList
92  *          of a partially created DICOMDIR
93  */
94 DicomDirSerie *DicomDirStudy::NewSerie()
95 {
96    ListDicomDirSerieElem const &elemList = 
97       Global::GetDicomDirElements()->GetDicomDirSerieElements();   
98
99    DicomDirSerie* st = new DicomDirSerie();
100    FillObject(elemList);
101    Series.push_front(st);
102
103    return st;  
104
105
106  /**
107  * \brief   Get the first entry while visiting the DicomDirSeries
108  * \return  The first DicomDirSerie if found, otherwhise NULL
109  */
110 DicomDirSerie *DicomDirStudy::GetFirstEntry()
111 {
112    ItDicomDirSerie = Series.begin();
113    return *ItDicomDirSerie;
114 }
115
116 /**
117  * \brief   Get the next entry while visiting the DicomDirSeries
118  * \note : meaningfull only if GetFirstEntry already called
119  * \return  The next DicomDirSerie if found, otherwhise NULL
120  */
121 DicomDirSerie *DicomDirStudy::GetNextEntry()
122 {
123    if (ItDicomDirSerie != Series.end())
124    {
125       DicomDirSerie *tmp = *ItDicomDirSerie;
126       ++ItDicomDirSerie;
127       return tmp;
128    }
129    else
130    {
131       return NULL;
132    }
133 }  
134 //-----------------------------------------------------------------------------
135 // Protected
136
137 //-----------------------------------------------------------------------------
138 // Private
139
140 //-----------------------------------------------------------------------------
141 } // end namespace gdcm
142