]> Creatis software - gdcm.git/blob - src/gdcmDicomDirStudy.cxx
Summer nights are really too hot to sleep.
[gdcm.git] / src / gdcmDicomDirStudy.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDirStudy.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/06/24 10:55:58 $
7   Version:   $Revision: 1.37 $
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 // Public
54 /**
55  * \brief   Writes the Object
56  * @param fp ofstream to write to
57  * @param t Type of the File (explicit VR, implicitVR, ...) 
58  * @return
59  */ 
60 void DicomDirStudy::WriteContent(std::ofstream *fp, FileType t)
61 {
62    DicomDirObject::WriteContent(fp, t);
63
64    for(ListDicomDirSerie::iterator cc = Series.begin();
65                                    cc!= Series.end();
66                                  ++cc )
67    {
68       (*cc)->WriteContent( fp, t );
69    }
70 }
71
72 /**
73  * \brief   adds a new Serie at the beginning of the SerieList
74  *          of a partially created DICOMDIR
75  */
76 DicomDirSerie *DicomDirStudy::NewSerie()
77 {
78    DicomDirSerie *st = new DicomDirSerie();
79    Series.push_back(st);
80    return st;
81
82
83 /**
84  * \brief  Remove all series in the study 
85  */
86 void DicomDirStudy::ClearSerie()
87 {
88    for(ListDicomDirSerie::iterator cc = Series.begin();
89                                    cc != Series.end();
90                                  ++cc )
91    {
92       delete *cc;
93    }
94    Series.clear();
95 }
96
97 /**
98  * \brief   Get the first entry while visiting the DicomDirSeries
99  * \return  The first DicomDirSerie if found, otherwhise NULL
100  */
101 DicomDirSerie *DicomDirStudy::GetFirstSerie()
102 {
103    ItSerie = Series.begin();
104    if (ItSerie != Series.end())
105       return *ItSerie;
106    return NULL;
107 }
108
109 /**
110  * \brief   Get the next entry while visiting the DicomDirSeries
111  * \note : meaningfull only if GetFirstEntry already called
112  * \return  The next DicomDirSerie if found, otherwhise NULL
113  */
114 DicomDirSerie *DicomDirStudy::GetNextSerie()
115 {
116    gdcmAssertMacro (ItSerie != Series.end());
117
118    ++ItSerie;
119    if (ItSerie != Series.end())
120       return *ItSerie;
121    return NULL;
122 }  
123
124 /**
125  * \brief   Get the last entry while visiting the DicomDirSeries
126  * \return  The first DicomDirSerie if found, otherwhise NULL
127  */
128 DicomDirSerie *DicomDirStudy::GetLastSerie()
129 {
130    ItSerie = Series.end();
131    if (ItSerie != Series.begin())
132    {
133      --ItSerie;
134       return *ItSerie;
135    }
136    return NULL;
137 }
138
139 //-----------------------------------------------------------------------------
140 // Protected
141
142 //-----------------------------------------------------------------------------
143 // Private
144
145 //-----------------------------------------------------------------------------
146 // Print
147 /**
148  * \brief   Prints the Object
149  * @param os ostream to write to 
150  * @param indent Indentation string to be prepended during printing
151  * @return
152  */ 
153 void DicomDirStudy::Print(std::ostream &os, std::string const & )
154 {
155    os << "STUDY" << std::endl;
156    DicomDirObject::Print(os);
157
158    for(ListDicomDirSerie::iterator cc = Series.begin();
159                                    cc != Series.end();
160                                    ++cc)
161    {
162       (*cc)->SetPrintLevel(PrintLevel);
163       (*cc)->Print(os);
164    }
165 }
166
167 //-----------------------------------------------------------------------------
168 } // end namespace gdcm