Rcpp Version 1.0.9
debug.h
Go to the documentation of this file.
1 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 //
3 // debug.h: Rcpp R/C++ interface class library -- debug macros
4 //
5 // Copyright (C) 2012 - 2013 Dirk Eddelbuettel and Romain Francois
6 //
7 // This file is part of Rcpp.
8 //
9 // Rcpp is free software: you can redistribute it and/or modify it
10 // under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // Rcpp is distributed in the hope that it will be useful, but
15 // 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 Rcpp. If not, see <http://www.gnu.org/licenses/>.
21 
22 #ifndef Rcpp_macros_debug_h
23 #define Rcpp_macros_debug_h
24 
25 // simple logging help
26 #ifndef RCPP_DEBUG_LEVEL
27  #define RCPP_DEBUG_LEVEL 0
28 #endif
29 
30 #ifndef RCPP_DEBUG_MODULE_LEVEL
31  #define RCPP_DEBUG_MODULE_LEVEL RCPP_DEBUG_LEVEL
32 #endif
33 
34 
35 #if RCPP_DEBUG_LEVEL > 0
36  #define RCPP_DEBUG( MSG ) Rprintf( "%40s:%4d %s\n" , ::Rcpp::internal::debug::short_file_name(__FILE__).c_str(), __LINE__, MSG ) ;
37  #define RCPP_DEBUG_1( fmt, MSG ) Rprintf( "%40s:%4d " fmt "\n" , ::Rcpp::internal::debug::short_file_name(__FILE__).c_str(), __LINE__, MSG ) ;
38  #define RCPP_DEBUG_2( fmt, M1, M2 ) Rprintf( "%40s:%4d " fmt "\n" , ::Rcpp::internal::debug::short_file_name(__FILE__).c_str(), __LINE__, M1, M2 ) ;
39  #define RCPP_DEBUG_3( fmt, M1, M2, M3 ) Rprintf( "%40s:%4d " fmt "\n" , ::Rcpp::internal::debug::short_file_name(__FILE__).c_str(), __LINE__, M1, M2, M3) ;
40  #define RCPP_DEBUG_4( fmt, M1, M2, M3, M4 ) Rprintf( "%40s:%4d " fmt "\n" , ::Rcpp::internal::debug::short_file_name(__FILE__).c_str(), __LINE__, M1, M2, M3, M4) ;
41  #define RCPP_DEBUG_5( fmt, M1, M2, M3, M4, M5 ) Rprintf( "%40s:%4d " fmt "\n" , ::Rcpp::internal::debug::short_file_name(__FILE__).c_str(), __LINE__, M1, M2, M3, M4, M5) ;
42 #else
43  #define RCPP_DEBUG( MSG )
44  #define RCPP_DEBUG_1( fmt, MSG )
45  #define RCPP_DEBUG_2( fmt, M1, M2 )
46  #define RCPP_DEBUG_3( fmt, M1, M2, M3 )
47  #define RCPP_DEBUG_4( fmt, M1, M2, M3, M4 )
48  #define RCPP_DEBUG_5( fmt, M1, M2, M3, M4, M5 )
49 #endif
50 
51 #if RCPP_DEBUG_MODULE_LEVEL > 0
52  #define RCPP_DEBUG_MODULE( MSG ) { \
53  Rcpp::Module * mod__ = getCurrentScope() ; \
54  if( mod__ ){ \
55  Rprintf( "[module (%s) <%p> ] %40s:%4d %s\n" , mod__->name.c_str(), mod__, ::Rcpp::internal::debug::short_file_name(__FILE__).c_str(), __LINE__, MSG ) ;\
56  } else { \
57  Rprintf( "[module () ] %40s:%4d %s\n" , ::Rcpp::internal::debug::short_file_name(__FILE__).c_str(), __LINE__, MSG ) ; \
58  } \
59  }
60  #define RCPP_DEBUG_MODULE_1( fmt, MSG ) { \
61  Rcpp::Module * mod__ = getCurrentScope() ; \
62  if( mod__ ){ \
63  Rprintf( "[module (%s) <%p> ] %40s:%4d " fmt "\n" , mod__->name.c_str(), mod__, ::Rcpp::internal::debug::short_file_name(__FILE__).c_str(), __LINE__, MSG ) ;\
64  } else { \
65  Rprintf( "[module () ] %40s:%4d " fmt "\n" , ::Rcpp::internal::debug::short_file_name(__FILE__).c_str(), __LINE__, MSG ) ; \
66  } \
67  }
68  #define RCPP_DEBUG_MODULE_2( fmt, M1, M2 ) { \
69  Rcpp::Module * mod__ = getCurrentScope() ; \
70  if( mod__ ){ \
71  Rprintf( "[module (%s) <%p> ] %40s:%4d " fmt "\n" , mod__->name.c_str(), mod__, ::Rcpp::internal::debug::short_file_name(__FILE__).c_str(), __LINE__, M1, M2 ) ;\
72  } else { \
73  Rprintf( "[module () ] %40s:%4d " fmt "\n" , ::Rcpp::internal::debug::short_file_name(__FILE__).c_str(), __LINE__, M1, M2 ) ; \
74  } \
75  }
76  #define RCPP_DEBUG_MODULE_3( fmt, M1, M2, M3 ) { \
77  Rcpp::Module * mod__ = getCurrentScope() ; \
78  if( mod__ ){ \
79  Rprintf( "[module (%s) <%p> ] %40s:%4d " fmt "\n" , mod__->name.c_str(), mod__, ::Rcpp::internal::debug::short_file_name(__FILE__).c_str(), __LINE__, M1, M2, M3 ) ;\
80  } else { \
81  Rprintf( "[module () ] %40s:%4d " fmt "\n" , ::Rcpp::internal::debug::short_file_name(__FILE__).c_str(), __LINE__, M1, M2, M3 ) ; \
82  } \
83  }
84  #define RCPP_DEBUG_MODULE_4( fmt, M1, M2, M3, M4 ) { \
85  Rcpp::Module * mod__ = getCurrentScope() ; \
86  if( mod__ ) { \
87  Rprintf( "[module (%s) <%p> ] %40s:%4d " fmt "\n" , mod__->name.c_str(), mod__, ::Rcpp::internal::debug::short_file_name(__FILE__).c_str(), __LINE__, M1, M2, M3, M4 ) ;\
88  } else { \
89  Rprintf( "[module () ] %40s:%4d " fmt "\n" , ::Rcpp::internal::debug::short_file_name(__FILE__).c_str(), __LINE__, M1, M2, M3, M4 ) ; \
90  } \
91  }
92  #define RCPP_DEBUG_MODULE_5( fmt, M1, M2, M3, M4, M5 ) { \
93  Rcpp::Module * mod__ = getCurrentScope() ; \
94  if( mod__ ){ \
95  Rprintf( "[module (%s) <%p> ] %40s:%4d " fmt "\n" , mod__->name.c_str(), mod__, ::Rcpp::internal::debug::short_file_name(__FILE__).c_str(), __LINE__, M1, M2, M3, M4, M5 ) ;\
96  } else { \
97  Rprintf( "[module () ] %40s:%4d " fmt "\n" , ::Rcpp::internal::debug::short_file_name(__FILE__).c_str(), __LINE__, M1, M2, M3, M4, M5 ) ; \
98  } \
99  }
100 #else
101  #define RCPP_DEBUG_MODULE( MSG )
102  #define RCPP_DEBUG_MODULE_1( fmt, MSG )
103  #define RCPP_DEBUG_MODULE_2( fmt, M1, M2 )
104  #define RCPP_DEBUG_MODULE_3( fmt, M1, M2, M3 )
105  #define RCPP_DEBUG_MODULE_4( fmt, M1, M2, M3, M4 )
106  #define RCPP_DEBUG_MODULE_5( fmt, M1, M2, M3, M4, M5 )
107 #endif
108 
109 #endif