]> Creatis software - gdcm.git/blob - src/gdcmDicomDirStudy.cxx
COMP: Fix compilation on broken compiler (scope/for loop)
[gdcm.git] / src / gdcmDicomDirStudy.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDirStudy.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/07/09 23:47:30 $
7   Version:   $Revision: 1.39 $
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 #include "gdcmDicomDirVisit.h"
24 #include "gdcmDebug.h"
25
26 namespace gdcm 
27 {
28 //-----------------------------------------------------------------------------
29 // Constructor / Destructor
30 /**
31  * \brief  Constructor 
32  * \note End user must use : DicomDirPatient::NewStudy()
33  */
34 DicomDirStudy::DicomDirStudy(bool empty)
35               :DicomDirObject()
36 {
37    if ( !empty )
38    {
39       ListDicomDirStudyElem const &elemList = 
40          Global::GetDicomDirElements()->GetDicomDirStudyElements();
41       FillObject(elemList);
42    }
43 }
44
45 /**
46  * \brief   Canonical destructor.
47  */
48 DicomDirStudy::~DicomDirStudy() 
49 {
50    ClearSerie();
51 }
52
53 //-----------------------------------------------------------------------------
54 // Public
55 /**
56  * \brief   Writes the Object
57  * @param fp ofstream to write to
58  * @param t Type of the File (explicit VR, implicitVR, ...) 
59  * @return
60  */ 
61 void DicomDirStudy::WriteContent(std::ofstream *fp, FileType t)
62 {
63    DicomDirObject::WriteContent(fp, t);
64
65    for(ListDicomDirSerie::iterator cc = Series.begin();
66                                    cc!= Series.end();
67                                  ++cc )
68    {
69       (*cc)->WriteContent( fp, t );
70    }
71
72    for(ListDicomDirVisit::iterator icc = Visits.begin();
73                                    icc!= Visits.end();
74                                  ++icc )
75    {
76       (*icc)->WriteContent( fp, t );
77    }
78 }
79
80 /**
81  * \brief   adds a new Serie at the beginning of the SerieList
82  *          of a partially created DICOMDIR
83  */
84 DicomDirSerie *DicomDirStudy::NewSerie()
85 {
86    DicomDirSerie *st = new DicomDirSerie();
87    Series.push_back(st);
88    return st;
89
90
91 /**
92  * \brief   adds a new Visit at the beginning of the VisitList
93  *          of a partially created DICOMDIR
94  */
95 DicomDirVisit *DicomDirStudy::NewVisit()
96 {
97    DicomDirVisit *st = new DicomDirVisit();
98    Visits.push_back(st);
99    return st;
100
101
102 /**
103  * \brief  Remove all series in the study 
104  */
105 void DicomDirStudy::ClearSerie()
106 {
107    for(ListDicomDirSerie::iterator cc = Series.begin();
108                                    cc != Series.end();
109                                  ++cc )
110    {
111       delete *cc;
112    }
113    Series.clear();
114 }
115
116 /**
117  * \brief  Remove all visits in the study 
118  */
119 void DicomDirStudy::ClearVisit()
120 {
121    for(ListDicomDirVisit::iterator cc =  Visits.begin();
122                                    cc != Visits.end();
123                                  ++cc )
124    {
125       delete *cc;
126    }
127    Visits.clear();
128 }
129
130 /**
131  * \brief   Get the first entry while visiting the DicomDirSeries
132  * \return  The first DicomDirSerie if found, otherwhise NULL
133  */
134 DicomDirSerie *DicomDirStudy::GetFirstSerie()
135 {
136    ItSerie = Series.begin();
137    if (ItSerie != Series.end())
138       return *ItSerie;
139    return NULL;
140 }
141
142 /**
143  * \brief   Get the first entry while visiting the DicomDirVisit
144  * \return  The first DicomDirVisit if found, otherwhise NULL
145  */
146 DicomDirVisit *DicomDirStudy::GetFirstVisit()
147 {
148    ItVisit = Visits.begin();
149    if (ItVisit != Visits.end())
150       return *ItVisit;
151    return NULL;
152 }
153
154 /**
155  * \brief   Get the next entry while visiting the DicomDirSeries
156  * \note : meaningfull only if GetFirstEntry already called
157  * \return  The next DicomDirSerie if found, otherwhise NULL
158  */
159 DicomDirSerie *DicomDirStudy::GetNextSerie()
160 {
161    gdcmAssertMacro (ItSerie != Series.end());
162
163    ++ItSerie;
164    if (ItSerie != Series.end())
165       return *ItSerie;
166    return NULL;
167 }  
168
169 /**
170  * \brief   Get the next entry while visiting the DicomDirVisit
171  * \note : meaningfull only if GetFirstEntry already called
172  * \return  The next DicomDirVisit if found, otherwhise NULL
173  */
174 DicomDirVisit *DicomDirStudy::GetNextVisit()
175 {
176    gdcmAssertMacro (ItVisit != Visits.end());
177
178    ++ItVisit;
179    if (ItVisit != Visits.end())
180       return *ItVisit;
181    return NULL;
182 }
183
184 /**
185  * \brief   Get the last entry while visiting the DicomDirSeries
186  * \return  The last DicomDirSerie if found, otherwhise NULL
187  */
188 DicomDirSerie *DicomDirStudy::GetLastSerie()
189 {
190    ItSerie = Series.end();
191    if (ItSerie != Series.begin())
192    {
193      --ItSerie;
194       return *ItSerie;
195    }
196    return NULL;
197 }
198
199 /**
200  * \brief   Get the last entry while visiting the DicomDirVisit
201  * \return  The last DicomDirVisit if found, otherwhise NULL
202  */
203 DicomDirVisit *DicomDirStudy::GetLastVisit()
204 {
205    ItVisit = Visits.end();
206    if (ItVisit != Visits.begin())
207    {
208      --ItVisit;
209       return *ItVisit;
210    }
211    return NULL;
212 }
213
214 //-----------------------------------------------------------------------------
215 // Protected
216
217 //-----------------------------------------------------------------------------
218 // Private
219
220 //-----------------------------------------------------------------------------
221 // Print
222 /**
223  * \brief   Prints the Object
224  * @param os ostream to write to 
225  * @param indent Indentation string to be prepended during printing
226  * @return
227  */ 
228 void DicomDirStudy::Print(std::ostream &os, std::string const & )
229 {
230    os << "STUDY" << std::endl;
231    DicomDirObject::Print(os);
232
233    for(ListDicomDirSerie::iterator cc = Series.begin();
234                                    cc != Series.end();
235                                    ++cc)
236    {
237       (*cc)->SetPrintLevel(PrintLevel);
238       (*cc)->Print(os);
239    }
240
241    for(ListDicomDirVisit::iterator cc2 =  Visits.begin();
242                                    cc2 != Visits.end();
243                                    ++cc2)
244    {
245       (*cc2)->SetPrintLevel(PrintLevel);
246       (*cc2)->Print(os);
247    }
248
249 }
250
251 //-----------------------------------------------------------------------------
252 } // end namespace gdcm