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