File: debug.h

package info (click to toggle)
arts 1.5.9-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 8,436 kB
  • ctags: 9,848
  • sloc: ansic: 44,670; cpp: 33,776; sh: 10,486; perl: 3,470; makefile: 372; yacc: 347; lex: 160
file content (138 lines) | stat: -rw-r--r-- 4,440 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
    /*

    Copyright (C) 2000 Stefan Westerfeld
                       stefan@space.twc.de

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.
  
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.
   
    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.


	Some inspiration taken from glib.
	Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
	Modified by the GLib Team and others 1997-1999.

    */

#ifndef _ARTSDEBUG_H_
#define _ARTSDEBUG_H_

#include "arts_export.h"

/*
 * BC - Status (2002-03-08): Debug.
 *
 * Collection class, no instance, no members. Thus binary compatible (will
 * be kept).
 */

#define arts_fatal		::Arts::Debug::fatal
#define arts_warning	::Arts::Debug::warning
#define arts_info		::Arts::Debug::info
#define arts_debug		::Arts::Debug::debug

/* source compatibility with older sources */
#define artsdebug		::Arts::Debug::debug
#define setartsdebug(x)	arts_warning("setartsdebug is obsolete")

#ifdef __GNUC__

#define arts_return_if_fail(expr)										\
	 do {																\
       if (!(expr))                       								\
	   {																\
         arts_warning ("file %s: line %d (%s): assertion failed: (%s)", \
          __FILE__, __LINE__, __PRETTY_FUNCTION__, #expr);				\
	     return;														\
	   }																\
	 } while(0)

#define arts_return_val_if_fail(expr,val)								\
	 do {																\
       if (!(expr))                       								\
	   {																\
         arts_warning ("file %s: line %d (%s): assertion failed: (%s)", \
            __FILE__, __LINE__, __PRETTY_FUNCTION__, #expr);			\
	     return (val);													\
	   }																\
	 } while(0)

#define arts_assert(expr)												\
	 do {																\
       if (!(expr))                       								\
         arts_fatal ("file %s: line %d (%s): assertion failed: (%s)",  	\
            __FILE__, __LINE__, __PRETTY_FUNCTION__, #expr);			\
	 } while(0)

#else

#define arts_return_if_fail(expr)										\
	 do {																\
       if (!(expr))                       								\
	   {																\
         arts_warning ("file %s: line %d: assertion failed: (%s)",  	\
            __FILE__, __LINE__, #expr);									\
	     return;														\
	   }		\
	 } while(0)

#define arts_return_val_if_fail(expr,val)								\
	 do {																\
       if (!(expr))                       								\
	   {																\
         arts_warning ("file %s: line %d: assertion failed: (%s)", 	 	\
            __FILE__, __LINE__, #expr);									\
	     return (val);													\
	   }																\
	 } while(0)

#define arts_assert(expr)												\
	 do {																\
       if (!(expr))                       								\
         arts_fatal ("file %s: line %d: assertion failed: (%s)",  		\
            __FILE__, __LINE__, #expr);									\
	 } while(0)

#endif

ARTS_EXPORT char* arts_strdup_printf (const char *format, ...);

namespace Arts {
	class ARTS_EXPORT Debug {
	public:
		enum Level { lFatal = 3, lWarning = 2, lInfo = 1, lDebug = 0 };

		/**
		 * Initializes at which is the minimum level to react to. If you
		 * call this, call this before creating the Arts::Dispatcher object.
		 */
		static void init(const char *prefix, Level level);

		static void fatal(const char *fmt,...);		// print on stderr & abort
		static void warning(const char *fmt,...);	// print on stderr
		static void info(const char *fmt,...);		// print on stdout
		static void debug(const char *fmt,...);		// print on stdout

		/**
 		 * This method sets the name of an external application to
		 * display messages graphically.
 		 */
		static void messageApp(const char *appName);

		static void initMutex();	// called from the dispatcher constructor
		static void freeMutex();	// called from the dispatcher destructor
	};
}

#endif