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