1 /****************************************************************************
2 **
3 ** This file is part of the LibreCAD project, a 2D CAD program
4 **
5 ** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
6 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
7 **
8 **
9 ** This file may be distributed and/or modified under the terms of the
10 ** GNU General Public License version 2 as published by the Free Software
11 ** Foundation and appearing in the file gpl-2.0.txt included in the
12 ** packaging of this file.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ** GNU General Public License for more details.
18 **
19 ** You should have received a copy of the GNU General Public License
20 ** along with this program; if not, write to the Free Software
21 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 **
23 ** This copyright notice MUST APPEAR in all copies of the script!
24 **
25 **********************************************************************/
26 
27 
28 #ifndef RS_DEBUG_H
29 #define RS_DEBUG_H
30 
31 #include <iosfwd>
32 #ifdef __hpux
33 #include <sys/_size_t.h>
34 #endif
35 
36 class QString;
37 
38 /** print out a debug header*/
39 #define DEBUG_HEADER debugHeader(__FILE__, __func__, __LINE__);
40 void debugHeader(char const* file, char const* func, int line);
41 #define RS_DEBUG RS_Debug::instance()
42 #define RS_DEBUG_VERBOSE DEBUG_HEADER \
43 	RS_Debug::instance()
44 
45 /**
46  * Debugging facilities.
47  *
48  * @author Andrew Mustun
49  */
50 class RS_Debug {
51 
52 public:
53     /**
54      * Enum for debug levels. Only messages of the current
55      * or a higher level are printed.
56      * <ul>
57      *  <li>D_NOTHING:  nothing
58      *  <li>D_CRITICAL: critical messages
59      *  <li>D_ERROR:    errors
60      *  <li>D_WARNING:  warnings
61      *  <li>D_NOTICE:   notes
62      *  <li>D_INFORMATIONAL: infos
63      *  <li>D_DEBUGGING: very verbose
64      * </ul>
65      */
66     enum RS_DebugLevel { D_NOTHING,
67                          D_CRITICAL,
68                          D_ERROR,
69                          D_WARNING,
70                          D_NOTICE,
71                          D_INFORMATIONAL,
72                          D_DEBUGGING };
73 
74 private:
75     RS_Debug();
76 	RS_Debug(const RS_Debug&)=delete;
77 	RS_Debug& operator = (const RS_Debug&)=delete;
78 	RS_Debug(RS_Debug&&)=delete;
79 	RS_Debug& operator = (RS_Debug&&)=delete;
80 
81 public:
82     static RS_Debug* instance();
83 
84     static void deleteInstance();
85     void setLevel(RS_DebugLevel level);
86     RS_DebugLevel getLevel();
87     void print(RS_DebugLevel level, const char* format ...);
88     void print(const char* format ...);
89     void printUnicode(const QString& text);
90     void timestamp();
setStream(FILE * s)91     void setStream(FILE* s) {
92         stream = s;
93     }
94 
95 private:
96     static RS_Debug* uniqueInstance;
97 
98     RS_DebugLevel debugLevel;
99     FILE* stream;
100 };
101 
102 #endif
103 // EOF
104