]> Creatis software - gdcm.git/blob - src/gdcmDebug.cxx
* src/gdcmUtil.[cxx|h] split in two. Additional file gdcmDebug.[cxx|h]
[gdcm.git] / src / gdcmDebug.cxx
1 #include <iostream>
2 #include "gdcmDebug.h"
3
4 /**
5  * \ingroup Globals
6  * \brief   Instance of debugging utility.
7  */
8 gdcmDebug dbg;
9
10 /**
11  * \ingroup gdcmDebug
12  * \brief   constructor
13  * @param level debug level
14  */ 
15 gdcmDebug::gdcmDebug(int level) {
16    DebugLevel = level;
17 }
18
19 /**
20  * \ingroup gdcmDebug
21  * \brief   Accessor
22  * @param   level Set the debug level
23  */ 
24 void gdcmDebug::SetDebug(int level) {
25    DebugLevel = level;
26 }
27
28 /**
29  * \ingroup gdcmDebug
30  * \brief   Verbose 
31  * @param Level level
32  * @param Msg1 first message part
33  * @param Msg2 second message part 
34  */
35 void gdcmDebug::Verbose(int Level, const char * Msg1, const char * Msg2) {
36    if (Level > DebugLevel)
37       return ;
38    std::cerr << Msg1 << ' ' << Msg2 << std::endl;
39 }
40
41 /**
42  * \ingroup gdcmDebug
43  * \brief   Error 
44  * @param Test test
45  * @param Msg1 first message part
46  * @param Msg2 second message part 
47  */
48 void gdcmDebug::Error( bool Test, const char * Msg1, const char * Msg2) {
49    if (!Test)
50       return;
51    std::cerr << Msg1 << ' ' << Msg2 << std::endl;
52    Exit(1);
53 }
54
55 /**
56  * \ingroup gdcmDebug
57  * \brief   Error 
58  * @param Msg1 first message part
59  * @param Msg2 second message part
60  * @param Msg3 Third message part  
61  */
62 void gdcmDebug::Error(const char* Msg1, const char* Msg2,
63                       const char* Msg3) {
64    std::cerr << Msg1 << ' ' << Msg2 << ' ' << Msg3 << std::endl;
65    Exit(1);
66 }
67
68 /**
69  * \ingroup gdcmDebug
70  * \brief   Assert 
71  * @param Level level 
72  * @param Test test
73  * @param Msg1 first message part
74  * @param Msg2 second message part
75  */
76  void gdcmDebug::Assert(int Level, bool Test,
77                  const char * Msg1, const char * Msg2) {
78    if (Level > DebugLevel)
79       return ;
80    if (!Test)
81       std::cerr << Msg1 << ' ' << Msg2 << std::endl;
82 }
83
84 /**
85  * \ingroup gdcmDebug
86  * \brief   Exit 
87  * @param a return code 
88  */
89 void gdcmDebug::Exit(int a) {
90 #ifdef __GNUC__
91    std::exit(a);
92 #endif
93 #ifdef _MSC_VER
94    exit(a);    // Found in #include <stdlib.h>
95 #endif
96 }