Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JMessage.hh
Go to the documentation of this file.
1 #ifndef __JEEP__JMESSAGE__
2 #define __JEEP__JMESSAGE__
3 
4 #include <iostream>
5 
6 #include "Jeep/JColor.hh"
7 
8 
9 /**
10  * \file
11  * General purpose messaging.
12  * \author mdejong
13  */
14 
15 extern int debug;
16 
17 namespace JEEP {}
18 namespace JPP { using namespace JEEP; }
19 
20 namespace JEEP {
21 
22  /**
23  * Debug level.
24  */
25  enum JMessage_t {
26 
27  debug_t = 3, //!< debug
28  status_t = 2, //!< status
29  warning_t = 2, //!< warning
30  notice_t = 1, //!< notice
31  error_t = 0, //!< error
32  fatal_t = 0 //!< fatal; exit
33  };
34 
35 
36  /**
37  * Auxiliary class for handling debug parameter within a class.
38  * Note that the derived class should include the statement <tt>using JMessage<..>::debug;</tt>
39  * otherwise the linker will fail.
40  */
41  template<class T>
42  struct JMessage {
43  static int debug; // debug level
44  };
45 
46 
47  /**
48  * debug level (default is off).
49  */
50  template<class T>
51  int JMessage<T>::debug = 0;
52 }
53 
54 
55 /**
56  * Message macros.
57  *
58  * \param A ostream compatible output
59  */
60 #define DEBUG(A) do { if (debug >= JEEP::debug_t) { std::cout << A << std::flush; } } while (0)
61 #define STATUS(A) do { if (debug >= JEEP::status_t) { std::cout << A << std::flush; } } while (0)
62 #define NOTICE(A) do { if (debug >= JEEP::notice_t) { std::cerr << A << std::flush; } } while (0)
63 #define WARNING(A) do { if (debug >= JEEP::warning_t) { std::cerr << A << std::flush; } } while (0)
64 #define ERROR(A) do { { std::cerr << A << std::flush; } } while (0)
65 #define FATAL(A) do { { std::cerr << A << std::endl; exit(1); } } while (0)
66 
67 /**
68  * Assert macro.
69  *
70  * \param A test
71  */
72 #define ASSERT(A) do { \
73  if (A) { NOTICE(GREEN << "Test at " << __FILE__ << ":" << __LINE__ << " (" << #A << ") passed." << RESET << std::endl); } \
74  else { FATAL (RED << "Test at " << __FILE__ << ":" << __LINE__ << " (" << #A << ") failed." << RESET << std::endl); } } while (0)
75 
76 #endif
static int debug
debug level (default is off).
Definition: JMessage.hh:43
fatal; exit
Definition: JMessage.hh:32
debug
Definition: JMessage.hh:27
notice
Definition: JMessage.hh:30
warning
Definition: JMessage.hh:29
status
Definition: JMessage.hh:28
I/O coloring auxiliaries.
JMessage_t
Debug level.
Definition: JMessage.hh:25
error
Definition: JMessage.hh:31
int debug
debug level
Definition: JSirene.cc:59
Auxiliary class for handling debug parameter within a class.
Definition: JMessage.hh:42