]> Creatis software - gdcm.git/blob - src/gdcmDebug.cxx
ENH: Minor patch, mostly cosmetic clean up
[gdcm.git] / src / gdcmDebug.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDebug.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/07/19 11:51:26 $
7   Version:   $Revision: 1.3 $
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 #include <iostream>
20 #include "gdcmDebug.h"
21
22 //-----------------------------------------------------------------------------
23 gdcmDebug gdcmDebug::debug;
24
25 //-----------------------------------------------------------------------------
26 /**
27  * \brief   constructor
28  * @param level debug level
29  */ 
30 gdcmDebug::gdcmDebug(int level) 
31 {
32    DebugLevel = level;
33 }
34
35 /**
36  * \brief   Accessor
37  * @param   level Set the debug level
38  */ 
39 void gdcmDebug::SetDebug(int level) 
40 {
41    DebugLevel = level;
42 }
43
44 /**
45  * \brief   Verbose 
46  * @param Level level
47  * @param Msg1 first message part
48  * @param Msg2 second message part 
49  */
50 void gdcmDebug::Verbose(int Level, const char * Msg1, const char * Msg2) 
51 {
52    if (Level > DebugLevel)
53       return ;
54    std::cerr << Msg1 << ' ' << Msg2 << std::endl;
55 }
56
57 /**
58  * \brief   Error 
59  * @param Test test
60  * @param Msg1 first message part
61  * @param Msg2 second message part 
62  */
63 void gdcmDebug::Error( bool Test, const char * Msg1, const char * Msg2) 
64 {
65    if (!Test)
66       return;
67    std::cerr << Msg1 << ' ' << Msg2 << std::endl;
68    Exit(1);
69 }
70
71 /**
72  * \brief   Error 
73  * @param Msg1 first message part
74  * @param Msg2 second message part
75  * @param Msg3 Third message part  
76  */
77 void gdcmDebug::Error(const char* Msg1, const char* Msg2,
78                       const char* Msg3) 
79 {
80    std::cerr << Msg1 << ' ' << Msg2 << ' ' << Msg3 << std::endl;
81    Exit(1);
82 }
83
84 /**
85  * \brief   Assert 
86  * @param Level level 
87  * @param Test test
88  * @param Msg1 first message part
89  * @param Msg2 second message part
90  */
91 void gdcmDebug::Assert(int Level, bool Test,
92                  const char * Msg1, const char * Msg2) 
93 {
94    if (Level > DebugLevel)
95       return ;
96    if (!Test)
97       std::cerr << Msg1 << ' ' << Msg2 << std::endl;
98 }
99
100 /**
101  * \brief   Exit 
102  * @param a return code 
103  */
104 void gdcmDebug::Exit(int a) 
105 {
106 #ifdef __GNUC__
107    std::exit(a);
108 #endif
109 #ifdef _MSC_VER
110    exit(a);    // Found in #include <stdlib.h>
111 #endif
112 }
113
114 /**
115  * \brief  Get the debug instance 
116  * \return Reference to the debug instance
117  */
118 gdcmDebug &gdcmDebug::GetReference()
119 {
120    return gdcmDebug::debug;
121 }
122