]> Creatis software - gdcm.git/blob - src/gdcmDebug.cxx
Flags Debug and Warning may be used separately.
[gdcm.git] / src / gdcmDebug.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDebug.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/11/05 13:21:32 $
7   Version:   $Revision: 1.26 $
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 WarningFlag   = false;
28 static bool DebugToFile   = false;
29 static std::ofstream DebugFile;
30
31 //-----------------------------------------------------------------------------
32 // Constructor / Destructor
33 Debug::Debug()
34 {
35
36 }
37
38 Debug::~Debug()
39 {
40   if ( DebugFile.is_open() )
41       DebugFile.close();     
42 }
43
44 //-----------------------------------------------------------------------------
45 // Public
46 /**
47  * \brief   Sets both the debug flag and warning flag
48  *          (both used for debugging purpose)
49  * @param   flag Set the debug flag and warning flag
50  */ 
51 void Debug::SetDebugFlag (bool flag) 
52 {
53    // To help tracking a bug, both flags are necessary
54    DebugFlag   = flag;
55    WarningFlag = flag;
56 }
57
58 /**
59  * \brief   Gets the debug flag value
60  *          (used to warn user when file contains some oddity)
61  * @return debug flag value
62  */ 
63 bool Debug::GetDebugFlag ()
64 {
65    return DebugFlag;
66 }
67
68 /**
69  * \brief   Sets the warning flag
70  * @param   flag Set the warning flag
71  */ 
72 void Debug::SetWarningFlag (bool flag) 
73 {
74    // Cannot unset Warning flag if Debug flag is on.
75    if (flag == false && DebugFlag == true)
76       return;
77    WarningFlag = flag;
78 }
79
80 /**
81  * \brief   Gets the warning flag value
82  * @return warning flag value
83  */ 
84 bool Debug::GetWarningFlag ()
85 {
86    return WarningFlag;
87 }
88 /**
89  * \brief   Accessor
90  * @param   flag whether we want to redirect to file
91  */ 
92 void Debug::SetDebugToFile (bool flag) 
93 {
94    DebugToFile = flag;
95 }
96
97 /**
98  * \brief   Accessor to know whether debug info are redirected to file
99  */ 
100 bool Debug::GetDebugToFile ()
101 {
102    return DebugToFile;
103 }
104
105 /**
106  * \brief Set the filename the debug stream should be redirect to
107  *        Settting a filename also sets DebugToFile to true
108  * @param   filename  File to redirect debug info
109  *          Absolutely nothing is check. You have to pass in
110  *          a correct filename
111  */ 
112 void Debug::SetDebugFilename (std::string const &filename)
113 {
114    DebugToFile = true;  // Just in case ... 
115    DebugFlag   = true;  // Just in case ...
116    if ( DebugFile.is_open() )
117       DebugFile.close();
118    DebugFile.open( filename.c_str() );
119 }
120
121 /**
122  * \brief Internal use only. Allow us to retrieve the static from anywhere
123  *        in gdcm code
124  * @return Debug file
125  */
126 std::ofstream &Debug::GetDebugFile ()
127 {
128   return DebugFile;
129 }
130
131 //-----------------------------------------------------------------------------
132 // Protected
133
134 //-----------------------------------------------------------------------------
135 // Private
136    
137 //-----------------------------------------------------------------------------
138 // Print
139
140 //-----------------------------------------------------------------------------
141 } // end namespace gdcm