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