]> Creatis software - gdcm.git/blob - src/gdcmDicomDir.h
* In order to fix memory leaks:
[gdcm.git] / src / gdcmDicomDir.h
1 /*=========================================================================
2   
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDir.h,v $
5   Language:  C++
6   Date:      $Date: 2004/06/19 23:51:03 $
7   Version:   $Revision: 1.22 $
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.htm 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 #ifndef GDCMDICOMDIR_H
20 #define GDCMDICOMDIR_H
21
22 #include "gdcmCommon.h"
23 #include "gdcmDocument.h"
24 #include "gdcmDicomDirPatient.h"
25 #include "gdcmDicomDirMeta.h"
26 #include "gdcmDicomDirElement.h"
27
28 #include <list>
29 #include <vector>
30
31 //-----------------------------------------------------------------------------
32 typedef std::list<gdcmDicomDirPatient *>   ListDicomDirPatient;
33 typedef std::vector<gdcmDocument *>  VectDocument;
34
35 typedef GDCM_EXPORT void(gdcmMethod)(void * = NULL);
36 //-----------------------------------------------------------------------------
37
38 /**
39  * \ingroup gdcmDicomDir
40  * \brief    gdcmDicomDir defines an object representing a DICOMDIR in memory.
41  *
42  */
43 class GDCM_EXPORT gdcmDicomDir: public gdcmDocument
44 {
45 public:
46 //   gdcmDicomDir(ListTag *l,
47 //                bool exception_on_error = false);
48    gdcmDicomDir(const char *FileName, 
49                 bool parseDir = false,
50                 bool exception_on_error = false);
51    gdcmDicomDir(bool exception_on_error = false); 
52                    
53    ~gdcmDicomDir(void);
54
55    /**
56     * \ingroup gdcmDicomDir
57     * \brief   Sets the print level for the Dicom Header 
58     * \note    0 for Light Print; 1 for 'medium' Print, 2 for Heavy
59     */
60    void SetPrintLevel(int level) 
61       { printLevel = level; };
62   /**
63     * \ingroup gdcmDicomDir
64     * \brief   canonical Printer 
65     * \sa    SetPrintLevel
66   */     
67    virtual void Print(std::ostream &os = std::cout);
68
69 // Informations contained in the parser
70    virtual bool IsReadable(void);
71
72 /// \brief   returns a pointer to the gdcmDicomDirMeta for this DICOMDIR. 
73    inline gdcmDicomDirMeta   *GetDicomDirMeta()      
74       {return metaElems;};
75
76  /// \brief   returns the PATIENT chained List for this DICOMDIR.    
77    inline ListDicomDirPatient &GetDicomDirPatients() 
78       {return patients;};
79
80 // Parsing
81    void ParseDirectory(void);
82    
83    void SetStartMethod(gdcmMethod *,void * =NULL,gdcmMethod * =NULL);
84    void SetStartMethodArgDelete(gdcmMethod *);
85    void SetProgressMethod(gdcmMethod *,void * =NULL,gdcmMethod * =NULL);
86    void SetProgressMethodArgDelete(gdcmMethod *);
87    void SetEndMethod(gdcmMethod *,void * =NULL,gdcmMethod * =NULL);
88    void SetEndMethodArgDelete(gdcmMethod *);
89
90 /// \brief GetProgress GetProgress
91    inline float GetProgress(void)  
92       {return(progress);};
93
94 /// \brief AbortProgress AbortProgress
95    inline void  AbortProgress(void)
96       {abort=true;      };
97
98 /// \brief IsAborted IsAborted
99       inline bool  IsAborted(void)
100       {return(abort);   };
101    
102 // Adding
103   gdcmDicomDirMeta *    NewMeta(void);
104   gdcmDicomDirPatient * NewPatient(void);
105
106 // Write
107    void WriteEntries(FILE *_fp);   
108    bool Write(std::string fileName);
109
110 /// Types of the gdcmObject within the gdcmDicomDir
111    typedef enum
112    {
113       GDCM_DICOMDIR_NONE,
114       GDCM_DICOMDIR_META,
115       GDCM_DICOMDIR_PATIENT,
116       GDCM_DICOMDIR_STUDY,
117       GDCM_DICOMDIR_SERIE,
118       GDCM_DICOMDIR_IMAGE,
119    } gdcmDicomDirType;
120    
121 protected:
122    void CreateDicomDirChainedList(std::string path);
123
124    void CallStartMethod(void);
125    void CallProgressMethod(void);
126    void CallEndMethod(void);
127
128 private:
129    void Initialize(void);
130    void CreateDicomDir(void);
131 //   void AddObjectToEnd(gdcmDicomDirType type, gdcmSQItem *s);
132    void AddDicomDirMeta   ();
133    void AddDicomDirPatientToEnd(gdcmSQItem *s);
134    void AddDicomDirStudyToEnd  (gdcmSQItem *s);
135    void AddDicomDirSerieToEnd  (gdcmSQItem *s);
136    void AddDicomDirImageToEnd  (gdcmSQItem *s);
137
138    void SetElements(std::string &path, VectDocument &list);
139    void SetElement (std::string &path,gdcmDicomDirType type,
140                     gdcmDocument *header);
141    
142    void UpdateDirectoryRecordSequenceLength(void);
143
144    static bool HeaderLessThan(gdcmDocument *header1,gdcmDocument *header2);
145    
146 // Variables
147
148 /// \brief pointer on *the* gdcmObject 'DicomDirMeta Elements'
149    gdcmDicomDirMeta *metaElems;
150
151 /// \brief chained list of DicomDirPatient (to be exploited recursively) 
152    ListDicomDirPatient patients;
153
154 /// pointer to the initialisation method for any progress bar   
155    gdcmMethod *startMethod;
156 /// pointer to the incrementation method for any progress bar
157     gdcmMethod *progressMethod;
158 /// pointer to the tremination method for any progress bar
159    gdcmMethod *endMethod;
160 /// pointer to the ??? method for any progress bar   
161    gdcmMethod *startMethodArgDelete;
162 /// pointer to the ??? method for any progress bar
163    gdcmMethod *progressMethodArgDelete;
164 /// pointer to the ??? method for any progress bar
165    gdcmMethod *endMethodArgDelete;
166 /// pointer to the ??? for any progress bar   
167    void *startArg;
168 /// pointer to the ??? for any progress bar
169    void *progressArg;
170 /// pointer to the ??? for any progress bar   
171    void *endArg;
172 /// value of the ??? for any progress bar
173    float progress;
174 /// value of the ??? for any progress bar   
175    bool abort;
176 };
177
178 //-----------------------------------------------------------------------------
179 #endif