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