26#ifndef __TERRALIB_RP_INTERNAL_MACROS_H
27#define __TERRALIB_RP_INTERNAL_MACROS_H
29 #include "../core/logger/Logger.h"
30 #include "../common/Config.h"
31 #include "../common/MathUtils.h"
35 #include <boost/lexical_cast.hpp>
44 #ifndef TERP_DEBUG_MODE
47 #define TERP_DEBUG_MODE
50 #ifndef TERP_ENABLE_STDOUT_LOG
51 #define TERP_ENABLE_STDOUT_LOG
60 #ifdef TERP_ENABLE_STDOUT_LOG
61 #define TERP_LOGMSG_STDOUT( message ) \
62 std::cout << std::endl << "Message : " \
65 << " - " << boost::lexical_cast< std::string >( message ) \
68 #define TERP_LOGMSG_STDOUT( message )
75 #ifdef TERP_ENABLE_STDOUT_LOG
76 #define TERP_LOGERR_STDOUT( message ) \
77 std::cerr << std::endl << "Error : " \
80 << " - " << boost::lexical_cast< std::string >( message ) \
83 #define TERP_LOGERR_STDOUT( message )
90 #ifdef TERP_ENABLE_STDOUT_LOG
91 #define TERP_LOGWARN_STDOUT( message ) \
92 std::cout << std::endl << "Warning : " \
95 << " - " << boost::lexical_cast< std::string >( message ) \
98 #define TERP_LOGWARN_STDOUT( message )
106 #define TERP_LOGMSG( message ) \
108 te::rp::Module::setLastLogStr( boost::lexical_cast< std::string >( message ) ); \
109 TE_LOG_INFO( boost::lexical_cast< std::string >( message ).c_str() ); \
110 TERP_LOGMSG_STDOUT( message ); \
117 #define TERP_LOGERR( message ) \
119 te::rp::Module::setLastLogStr( boost::lexical_cast< std::string >( message ) ); \
120 TE_LOG_ERROR( boost::lexical_cast< std::string >( message ).c_str() ); \
121 TERP_LOGERR_STDOUT( message ); \
128 #define TERP_INSTANCE_LOGERR( message ) \
130 setErrorMessage( boost::lexical_cast< std::string >( message ) ); \
131 TERP_LOGERR( boost::lexical_cast< std::string >( message ) ); \
138 #define TERP_LOGWARN( message ) \
140 te::rp::Module::setLastLogStr( boost::lexical_cast< std::string >( message ) ); \
141 TE_LOG_WARN( boost::lexical_cast< std::string >( message ).c_str() ); \
142 TERP_LOGWARN_STDOUT( message ); \
149 #define TERP_INSTANCE_LOGWARN( message ) \
151 setErrorMessage( boost::lexical_cast< std::string >( message ) ); \
152 TERP_LOGWARN( boost::lexical_cast< std::string >( message ) ); \
159 #define TERP_LOG_AND_THROW( message ) \
161 TERP_LOGERR( message ); \
162 throw te::rp::Exception( boost::lexical_cast< std::string >( message ) ); \
170 #define TERP_TRUE_OR_THROW( value , message ) \
171 if( ( value ) == 0 ) { \
172 TERP_LOGERR( boost::lexical_cast< std::string >( #value ) ); \
173 TERP_LOGERR( boost::lexical_cast< std::string >( message ) ); \
174 throw te::rp::Exception( boost::lexical_cast< std::string >( message ) ); \
182 #define TERP_INSTANCE_TRUE_OR_THROW( value, message ) \
183 if( ( value ) == 0 ) { \
184 setErrorMessage( boost::lexical_cast< std::string >( message ) ); \
185 TERP_LOGERR( boost::lexical_cast< std::string >( #value ) ); \
186 TERP_LOGERR( boost::lexical_cast< std::string >( message ) ); \
187 throw te::rp::Exception( boost::lexical_cast< std::string >( message ) ); \
194 #define TERP_WATCH( variable ) \
196 TERP_LOGMSG( "WATCH - " + boost::lexical_cast< std::string >( #variable ) + \
197 "=[" + boost::lexical_cast< std::string >( variable ) +"]" ); \
205 #define TERP_TRUE_OR_LOG( value , message ) \
206 if( ( value ) == 0 ) { \
207 TERP_LOGWARN( boost::lexical_cast< std::string >( #value ) ); \
208 TERP_LOGWARN( boost::lexical_cast< std::string >( message ) ); \
216 #define TERP_INSTANCE_TRUE_OR_LOG( value, message ) \
217 if( ( value ) == 0 ) { \
218 setErrorMessage( boost::lexical_cast< std::string >( message ) ); \
219 TERP_LOGERR( boost::lexical_cast< std::string >( #value ) ); \
220 TERP_LOGERR( boost::lexical_cast< std::string >( message ) ); \
230 #define TERP_TRUE_OR_RETURN_FALSE( value , message ) \
231 if( ( value ) == 0 ) { \
232 TERP_LOGWARN( boost::lexical_cast< std::string >( #value ) ); \
233 TERP_LOGWARN( boost::lexical_cast< std::string >( message ) ); \
245 #define TERP_INSTANCE_TRUE_OR_RETURN_FALSE( value , message ) \
246 if( ( value ) == 0 ) { \
247 setErrorMessage( boost::lexical_cast< std::string >( message ) ); \
248 TERP_LOGWARN( boost::lexical_cast< std::string >( #value ) ); \
249 TERP_LOGWARN( boost::lexical_cast< std::string >( message ) ); \
260 #define TERP_TRUE_OR_RETURN( value , message ) \
261 if( ( value ) == 0 ) { \
262 TERP_LOGWARN( boost::lexical_cast< std::string >( #value ) ); \
263 TERP_LOGWARN( boost::lexical_cast< std::string >( message ) ); \
274 #define TERP_FALSE_OR_RETURN_FALSE( value , message ) \
275 if( ( value ) != 0 ) { \
276 TERP_LOGWARN( boost::lexical_cast< std::string >( #value ) ); \
277 TERP_LOGWARN( boost::lexical_cast< std::string >( message ) ); \
288 #define TERP_INSTANCE_FALSE_OR_RETURN_FALSE( value , message ) \
289 if( ( value ) != 0 ) { \
290 setErrorMessage( boost::lexical_cast< std::string >( message ) ); \
291 TERP_LOGWARN( boost::lexical_cast< std::string >( #value ) ); \
292 TERP_LOGWARN( boost::lexical_cast< std::string >( message ) ); \
303 #define TERP_FALSE_OR_RETURN( value , message ) \
304 if( ( value ) != 0 ) { \
305 TERP_LOGWARN( boost::lexical_cast< std::string >( #value ) ); \
306 TERP_LOGWARN( boost::lexical_cast< std::string >( message ) ); \
314 #define TERP_LOG_AND_RETURN_FALSE( message ) \
316 TERP_LOGWARN( message ); \
324 #define TERP_INSTANCE_LOG_AND_RETURN_FALSE( message ) \
326 setErrorMessage( boost::lexical_cast< std::string >( message ) ); \
327 TERP_LOGWARN( message ); \
335 #define TERP_LOG_AND_RETURN( message ) \
337 TERP_LOGWARN( message ); \
346 #define TERP_FALSE_OR_LOG( value , message ) \
347 if( ( value ) != 0 ) { \
348 TERP_LOGWARN( boost::lexical_cast< std::string >( #value ) ); \
349 TERP_LOGWARN( boost::lexical_cast< std::string >( message ) ); \
358 #define TERP_CHECK_EQUAL( value1 , value2 , message ) \
359 if( value1 != value2 ) \
361 TERP_LOGERR(std::string( "[" ) + \
362 boost::lexical_cast< std::string >( #value1 ) \
363 + std::string( "!=" ) + \
364 + boost::lexical_cast< std::string >( #value2 ) \
366 + boost::lexical_cast< std::string >( value1 ) \
367 + std::string( "!=" ) + \
368 + boost::lexical_cast< std::string >( value2 ) ); \
369 TERP_LOG_AND_THROW( message ); \
378 #define TERP_CHECK_NOT_EQUAL( value1 , value2 , message ) \
379 if( value1 == value2 ) \
381 TERP_LOGERR(std::string( "[" ) + \
382 boost::lexical_cast< std::string >( #value1 ) \
383 + std::string( "==" ) + \
384 + boost::lexical_cast< std::string >( #value2 ) \
386 + boost::lexical_cast< std::string >( value1 ) \
387 + std::string( "==" ) + \
388 + boost::lexical_cast< std::string >( value2 ) ); \
389 TERP_LOG_AND_THROW( message ); \
399 #define TERP_CHECK_EPS( value1 , value2 , eps , message ) \
401 TERP_TRUE_OR_THROW( ( (eps) >= 0), "Invalid eps" ); \
402 double TERP_CHECK_EPS_double_diff = 0; \
403 double TERP_CHECK_EPS_double_value1 = (double)(value1); \
404 double TERP_CHECK_EPS_double_value2 = (double)(value2); \
405 double TERP_CHECK_EPS_double_eps = (double)(eps); \
406 if( TERP_CHECK_EPS_double_value1 < TERP_CHECK_EPS_double_value2 ) { \
407 TERP_CHECK_EPS_double_diff = ( TERP_CHECK_EPS_double_value2 - \
408 TERP_CHECK_EPS_double_value1 ); \
410 TERP_CHECK_EPS_double_diff = ( TERP_CHECK_EPS_double_value1 - \
411 TERP_CHECK_EPS_double_value2 ); \
413 if( TERP_CHECK_EPS_double_diff > TERP_CHECK_EPS_double_eps ) \
416 std::string( "Values are not equal: " ) + \
417 boost::lexical_cast< std::string >( #value1 ) + \
418 std::string( "=[") + \
419 boost::lexical_cast< std::string >( TERP_CHECK_EPS_double_value1 ) + \
420 std::string( "] " ) + \
421 boost::lexical_cast< std::string >( #value2 ) + \
422 std::string( "=[") + \
423 boost::lexical_cast< std::string >( TERP_CHECK_EPS_double_value2 ) + \
424 std::string( "] eps=[") + \
425 boost::lexical_cast< std::string >( TERP_CHECK_EPS_double_eps ) + \
426 std::string( "] diff=[") + \
427 boost::lexical_cast< std::string >( TERP_CHECK_EPS_double_diff ) \
429 TERP_LOG_AND_THROW( message ); \
436 #define TERP_NOT_IMPLEMENTED TERP_LOG_AND_THROW( "Not Implemented." );
444 #ifdef TERP_DEBUG_MODE
445 #define TERP_DEBUG_TRUE_OR_THROW( value , message ) \
446 TERP_TRUE_OR_THROW( value , message );
448 #define TERP_DEBUG_TRUE_OR_THROW( value , message );
459 #ifdef TERP_DEBUG_MODE
460 #define TERP_DEBUG_TRUE_OR_RETURN_FALSE( value , message ) \
461 TERP_TRUE_OR_RETURN_FALSE( value , message );
463 #define TERP_DEBUG_TRUE_OR_RETURN_FALSE( value , message );
470 #define MIN(x,y) (std::min)( x , y )
477 #define MAX(x,y) (std::max)( x , y )
484 #define ABS(x) std::abs( x )
An exception class for the XML module.
This singleton defines the TerraLib XML module entry.