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