]> Creatis software - gdcm.git/blob - src/gdcmDicomDirStudy.cxx
* src/gdcmDocument.cxx : bug fix on potential memory leak
[gdcm.git] / src / gdcmDicomDirStudy.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDirStudy.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/25 11:11:58 $
7   Version:   $Revision: 1.31 $
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 "gdcmDebug.h"
24
25 namespace gdcm 
26 {
27 //-----------------------------------------------------------------------------
28 // Constructor / Destructor
29 /**
30  * \brief  Constructor 
31  */
32 DicomDirStudy::DicomDirStudy(bool empty):
33    DicomDirObject()
34 {
35    if( !empty )
36    {
37       ListDicomDirStudyElem const &elemList = 
38          Global::GetDicomDirElements()->GetDicomDirStudyElements();
39       FillObject(elemList);
40    }
41 }
42
43 /**
44  * \brief   Canonical destructor.
45  */
46 DicomDirStudy::~DicomDirStudy() 
47 {
48    ClearSerie();
49 }
50
51 //-----------------------------------------------------------------------------
52 // Print
53 /**
54  * \brief   Prints the Object
55  * @param os ostream to write to 
56  * @param indent Indentation string to be prepended during printing
57  * @return
58  */ 
59 void DicomDirStudy::Print(std::ostream &os, std::string const & )
60 {
61    os << "STUDY" << std::endl;
62    DicomDirObject::Print(os);
63
64    for(ListDicomDirSerie::iterator cc = Series.begin();
65                                    cc != Series.end();
66                                    ++cc)
67    {
68       (*cc)->SetPrintLevel(PrintLevel);
69       (*cc)->Print(os);
70    }
71 }
72
73 //-----------------------------------------------------------------------------
74 // Public
75 /**
76  * \brief   Writes the Object
77  * @param fp ofstream to write to
78  * @param t Type of the File (explicit VR, implicitVR, ...) 
79  * @return
80  */ 
81 void DicomDirStudy::WriteContent(std::ofstream *fp, FileType t)
82 {
83    DicomDirObject::WriteContent(fp, t);
84
85    for(ListDicomDirSerie::iterator cc = Series.begin();
86                                    cc!= Series.end();
87                                  ++cc )
88    {
89       (*cc)->WriteContent( fp, t );
90    }
91 }
92
93 /**
94  * \brief   adds a new Serie at the begining of the SerieList
95  *          of a partially created DICOMDIR
96  */
97 DicomDirSerie *DicomDirStudy::NewSerie()
98 {
99    DicomDirSerie* st = new DicomDirSerie();
100    Series.push_back(st);
101    return st;
102
103
104 /**
105  * \brief  Remove all series in the study 
106  */
107 void DicomDirStudy::ClearSerie()
108 {
109    for(ListDicomDirSerie::iterator cc = Series.begin();
110                                    cc != Series.end();
111                                  ++cc )
112    {
113       delete *cc;
114    }
115    Series.clear();
116 }
117
118 /**
119  * \brief   Get the first entry while visiting the DicomDirSeries
120  * \return  The first DicomDirSerie if found, otherwhise NULL
121  */
122 DicomDirSerie *DicomDirStudy::GetFirstSerie()
123 {
124    ItSerie = Series.begin();
125    if (ItSerie != Series.end())
126       return *ItSerie;
127    return NULL;
128 }
129
130 /**
131  * \brief   Get the next entry while visiting the DicomDirSeries
132  * \note : meaningfull only if GetFirstEntry already called
133  * \return  The next DicomDirSerie if found, otherwhise NULL
134  */
135 DicomDirSerie *DicomDirStudy::GetNextSerie()
136 {
137    gdcmAssertMacro (ItSerie != Series.end());
138    {
139       ++ItSerie;
140       if (ItSerie != Series.end())
141          return *ItSerie;
142    }
143    return NULL;
144 }  
145
146 /**
147  * \brief   Get the last entry while visiting the DicomDirSeries
148  * \return  The first DicomDirSerie if found, otherwhise NULL
149  */
150 DicomDirSerie *DicomDirStudy::GetLastSerie()
151 {
152    ItSerie = Series.end();
153    if (ItSerie != Series.begin())
154    {
155      --ItSerie;
156       return *ItSerie;
157    }
158    return NULL;
159 }
160
161 //-----------------------------------------------------------------------------
162 // Protected
163
164 //-----------------------------------------------------------------------------
165 // Private
166
167 //-----------------------------------------------------------------------------
168 } // end namespace gdcm
169