1 /*=========================================================================
4 Module: $RCSfile: gdcmDebug.cxx,v $
6 Date: $Date: 2005/11/28 15:20:32 $
7 Version: $Revision: 1.27 $
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.
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.
17 =========================================================================*/
19 #include "gdcmDebug.h"
20 #include "gdcmCommandManager.h"
26 //-----------------------------------------------------------------------------
27 // Warning message level to be displayed
28 const int Debug::LINE_LENGTH = 79;
30 bool Debug::DebugFlag = false;
31 bool Debug::WarningFlag = false;
32 bool Debug::OutputToFile = false;
34 std::ofstream Debug::OutputFileStream;
35 std::ostream &Debug::StandardStream = std::cerr;
37 //-----------------------------------------------------------------------------
38 // Constructor / Destructor
45 if ( OutputFileStream.is_open() )
46 OutputFileStream.close();
49 //-----------------------------------------------------------------------------
52 * \brief Sets both the debug flag and warning flag
53 * (both used for debugging purpose)
54 * @param flag Set the debug flag and warning flag
56 void Debug::SetDebugFlag (bool flag)
58 // To help tracking a bug, both flags are necessary
64 * \brief Sets the warning flag
65 * @param flag Set the warning flag
67 void Debug::SetWarningFlag (bool flag)
69 // Cannot unset Warning flag if Debug flag is on.
70 if (flag == false && DebugFlag == true)
77 * @param flag whether we want to redirect to file
79 void Debug::SetOutputToFile (bool flag)
85 * \brief Accessor to know whether debug info are redirected to file
87 bool Debug::GetOutputToFile ()
93 * \brief Set the filename the debug stream should be redirect to
94 * Settting a filename also sets DebugToFile to true
95 * @param filename File to redirect debug info
96 * Absolutely nothing is check. You have to pass in
99 void Debug::SetOutputFileName (std::string const &filename)
101 OutputToFile = true; // Just in case ...
102 DebugFlag = true; // Just in case ...
103 if ( OutputFileStream.is_open() )
104 OutputFileStream.close();
105 OutputFileStream.open( filename.c_str() );
109 * \brief Internal use only. Allow us to retrieve the static from anywhere
113 std::ostream &Debug::GetOutput ()
116 return OutputFileStream;
118 return StandardStream;
121 void Debug::SendToOutput(unsigned int type,std::string const &msg,const CommandManager *mgr)
125 executed=mgr->ConstExecuteCommand(type,msg);
128 GetOutput() << Command::GetCommandAsString(type) << ": " << msg;
131 //-----------------------------------------------------------------------------
134 //-----------------------------------------------------------------------------
137 //-----------------------------------------------------------------------------
140 //-----------------------------------------------------------------------------
141 } // end namespace gdcm