gdcmDebug.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002                                                                                 
00003   Program:   gdcm
00004   Module:    $RCSfile: gdcmDebug.cxx,v $
00005   Language:  C++
00006   Date:      $Date: 2007/05/23 14:18:08 $
00007   Version:   $Revision: 1.31 $
00008                                                                                 
00009   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
00010   l'Image). All rights reserved. See Doc/License.txt or
00011   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
00012                                                                                 
00013      This software is distributed WITHOUT ANY WARRANTY; without even
00014      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00015      PURPOSE.  See the above copyright notices for more information.
00016                                                                                 
00017 =========================================================================*/
00018 
00019 #include "gdcmDebug.h"
00020 #include "gdcmCommandManager.h"
00021 
00022 #include <iostream>
00023 
00024 namespace GDCM_NAME_SPACE 
00025 {
00026 //-----------------------------------------------------------------------------
00027 // Warning message level to be displayed
00028 const int Debug::LINE_LENGTH = 79;
00029 
00030 bool Debug::DebugFlag     = false;
00031 bool Debug::LogFlag       = false;
00032 bool Debug::WarningFlag   = false;
00033 bool Debug::OutputToFile  = false;
00034 
00035 std::ofstream Debug::OutputFileStream;
00036 std::ostream &Debug::StandardStream = std::cerr;
00037 
00038 //-----------------------------------------------------------------------------
00039 // Constructor / Destructor
00040 Debug::Debug()
00041 {
00042 }
00043 
00044 Debug::~Debug()
00045 {
00046   if ( OutputFileStream.is_open() )
00047       OutputFileStream.close();     
00048 }
00049 
00050 //-----------------------------------------------------------------------------
00051 // Public
00057 void Debug::SetDebugFlag (bool flag) 
00058 {
00059    // To help tracking a bug, both flags are necessary
00060    DebugFlag   = flag;
00061    WarningFlag = flag;
00062 }
00063 
00068 void Debug::SetWarningFlag (bool flag) 
00069 {
00070    // Cannot unset Warning flag if Debug flag is on or if LogFlag is on.
00071    if (flag == false)
00072    { 
00073       if (DebugFlag == true)
00074          return;
00075       if (LogFlag == true)
00076          return;
00077    }
00078    WarningFlag = flag;
00079 }
00080 
00085 void Debug::SetLogFlag (bool flag) 
00086 {
00087    // To log oddities, both flags are necessary      
00088    WarningFlag = flag;   
00089    LogFlag = flag;
00090 }
00091 
00096 void Debug::SetOutputToFile (bool flag) 
00097 {
00098    OutputToFile = flag;
00099 }
00100 
00104 bool Debug::GetOutputToFile ()
00105 {
00106    return OutputToFile;
00107 }
00108 
00116 void Debug::SetOutputFileName (std::string const &filename)
00117 {
00118    OutputToFile = true;  // Just in case ... 
00119    DebugFlag   = true;  // Just in case ...
00120    if ( OutputFileStream.is_open() )
00121       OutputFileStream.close();
00122    OutputFileStream.open( filename.c_str() );
00123 }
00124 
00130 std::ostream &Debug::GetOutput ()
00131 {
00132    if(OutputToFile)
00133       return OutputFileStream;
00134    else
00135       return StandardStream;
00136 }
00137 
00138 void Debug::SendToOutput(unsigned int type,std::string const &msg,const Base *object)
00139 {
00140    bool executed=false;
00141    if( type != CMD_DEBUG && type != CMD_ASSERT )
00142       executed=CommandManager::ExecuteCommandConst(object,type,msg);
00143 
00144    if(!executed)
00145       GetOutput() << Command::GetCommandAsString(type) << ": " << msg;
00146 }
00147 
00148 //-----------------------------------------------------------------------------
00149 // Protected
00150 
00151 //-----------------------------------------------------------------------------
00152 // Private
00153    
00154 //-----------------------------------------------------------------------------
00155 // Print
00156 
00157 //-----------------------------------------------------------------------------
00158 } // end namespace gdcm

Generated on Fri Aug 24 12:53:09 2007 for gdcm by  doxygen 1.4.6