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