]> Creatis software - gdcm.git/blob - src/gdcmDebug.cxx
- Add construct and destructor to class gdcm::Debug to close the debug file
[gdcm.git] / src / gdcmDebug.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDebug.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/27 11:55:57 $
7   Version:   $Revision: 1.18 $
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 "gdcmDebug.h"
20 #include <iostream>
21
22 namespace gdcm 
23 {
24
25 /// warning message level to be displayed
26 static bool DebugFlag   = false;
27 static bool DebugToFile = false;
28 static std::ofstream DebugFile;
29
30
31 Debug::Debug()
32 {
33
34 }
35
36 Debug::~Debug()
37 {
38   if ( DebugFile.is_open() )
39       DebugFile.close();     
40 }
41 //-----------------------------------------------------------------------------
42 /**
43  * \brief   Accessor
44  * @param   flag Set the debug flag
45  */ 
46 void Debug::SetDebugFlag (bool flag) 
47 {
48    DebugFlag = flag;
49 }
50
51 /**
52  * \brief   Accessor
53  * @param   level Get the debug flag
54  */ 
55 bool Debug::GetDebugFlag ()
56 {
57    return DebugFlag;
58 }
59
60 /**
61  * \brief   Accessor
62  * @param   flag Set the debug flag to redirect to file
63  */ 
64 void Debug::SetDebugToFile (bool flag) 
65 {
66    DebugToFile = flag;
67 }
68
69 /**
70  * \brief   Accessor
71  * @param   level Get the debug flag to redirect to file
72  */ 
73 bool Debug::GetDebugToFile ()
74 {
75    return DebugToFile;
76 }
77
78 /**
79  * \brief   Accessor
80  * @param   flag Set the debug flag to redirect to file
81  *          Absolutely nothing is check. You have to pass in
82  *          a correct filename
83  */ 
84 void Debug::SetDebugFilename (std::string const &filename)
85 {
86    DebugToFile = true;  // Just in case ... 
87    DebugFlag = true;    // Just in case ...
88    if( DebugFile.is_open() )
89       DebugFile.close();
90    DebugFile.open( filename.c_str() );
91 }
92
93 std::ofstream &Debug::GetDebugFile ()
94 {
95   return DebugFile;
96 }
97
98 } // end namespace gdcm
99
100