00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #ifndef TEAGNOSTIC_H
00042 #define TEAGNOSTIC_H
00043
00044 #include <sstream>
00045 #include <string>
00046 #include <iostream>
00047
00048 #include "TeException.h"
00049 #include "TeErrorLog.h"
00050
00051
00052
00053
00054 #ifndef TEAGN_DEBUG_MODE
00055 #ifndef NDEBUG
00056
00057 #define TEAGN_DEBUG_MODE
00058
00059
00060 #ifndef TEAGN_ENABLE_STDOUT_LOG
00061 #define TEAGN_ENABLE_STDOUT_LOG
00062 #endif
00063 #endif
00064 #endif
00065
00066
00067
00068
00069
00070
00071 #ifdef TEAGN_ENABLE_STDOUT_LOG
00072 #define TEAGN_LOGMSG_STDOUT( message ) \
00073 std::cout << std::endl << "Message : " \
00074 << __FILE__ \
00075 << ":" << __LINE__ \
00076 << " - " << TeAgnostic::to_string( message ) \
00077 << std::endl;
00078 #else
00079 #define TEAGN_LOGMSG_STDOUT( message ) {};
00080 #endif
00081
00082
00083
00084
00085
00086
00087 #ifdef TEAGN_ENABLE_STDOUT_LOG
00088 #define TEAGN_LOGERR_STDOUT( message ) \
00089 std::cerr << std::endl << "Error : " \
00090 << __FILE__ \
00091 << ":" << __LINE__ \
00092 << " - " << TeAgnostic::to_string( message ) \
00093 << std::endl;
00094 #else
00095 #define TEAGN_LOGERR_STDOUT( message ) {};
00096 #endif
00097
00098
00099
00100
00101
00102
00103 #ifdef TEAGN_ENABLE_STDOUT_LOG
00104 #define TEAGN_LOGWARN_STDOUT( message ) \
00105 std::cout << std::endl << "Warning : " \
00106 << __FILE__ \
00107 << ":" << __LINE__ \
00108 << " - " << TeAgnostic::to_string( message ) \
00109 << std::endl;
00110 #else
00111 #define TEAGN_LOGWARN_STDOUT( message ) {};
00112 #endif
00113
00114
00115
00116
00117
00118
00119
00120 #define TEAGN_LOGMSG( message ) \
00121 { \
00122 TeErrorLog::instance().insert( LOG_MESSAGE, \
00123 TeAgnostic::to_string( message ) ); \
00124 TEAGN_LOGMSG_STDOUT( message ); \
00125 };
00126
00127
00128
00129
00130
00131
00132 #define TEAGN_LOGERR( message ) \
00133 { \
00134 TeErrorLog::instance().insert( UNKNOWN_ERROR_TYPE, \
00135 TeAgnostic::to_string( message ) ); \
00136 TEAGN_LOGERR_STDOUT( message ); \
00137 };
00138
00139
00140
00141
00142
00143
00144 #define TEAGN_LOGWARN( message ) \
00145 { \
00146 TeErrorLog::instance().insert( LOG_MESSAGE, \
00147 TeAgnostic::to_string( message ) ); \
00148 TEAGN_LOGWARN_STDOUT( message ); \
00149 };
00150
00151
00152
00153
00154
00155
00156 #define TEAGN_LOG_AND_THROW( message ) \
00157 { \
00158 TEAGN_LOGERR_STDOUT( message ); \
00159 throw TeException( UNKNOWN_ERROR_TYPE, \
00160 TeAgnostic::to_string( message ), false ); \
00161 };
00162
00163
00164
00165
00166
00167
00168
00169 #define TEAGN_TRUE_OR_THROW( value , message ) \
00170 if( ( value ) == 0 ) { \
00171 TEAGN_LOGERR_STDOUT( TeAgnostic::to_string( message ) + \
00172 " - " + TeAgnostic::to_string( #value ) ); \
00173 throw TeException( UNKNOWN_ERROR_TYPE, \
00174 TeAgnostic::to_string( message ), false ); \
00175 };
00176
00177
00178
00179
00180
00181
00182 #define TEAGN_WATCH( variable ) \
00183 { \
00184 TEAGN_LOGMSG( "WATCH - " + TeAgnostic::to_string( #variable ) + \
00185 "=[" + TeAgnostic::to_string( variable ) +"]" ); \
00186 };
00187
00188
00189
00190
00191
00192
00193
00194 #define TEAGN_TRUE_OR_LOG( value , message ) \
00195 if( ( value ) == 0 ) { \
00196 TEAGN_LOGWARN( TeAgnostic::to_string( message ) + \
00197 " - " + TeAgnostic::to_string( #value ) ); \
00198 };
00199
00200
00201
00202
00203
00204
00205
00206
00207 #define TEAGN_TRUE_OR_RETURN( value , message ) \
00208 if( ( value ) == 0 ) { \
00209 TEAGN_LOGWARN( TeAgnostic::to_string( message ) + \
00210 " - " + TeAgnostic::to_string( #value ) ); \
00211 return false; \
00212 };
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222 #define TEAGN_FALSE_OR_RETURN( value , message ) \
00223 if( ( value ) != 0 ) { \
00224 TEAGN_LOGWARN( TeAgnostic::to_string( message ) + \
00225 " - " + TeAgnostic::to_string( #value ) ); \
00226 return false; \
00227 };
00228
00229
00230
00231
00232
00233
00234 #define TEAGN_LOG_AND_RETURN( message ) \
00235 { \
00236 TEAGN_LOGWARN( message ); \
00237 return false; \
00238 };
00239
00240
00241
00242
00243
00244
00245
00246 #define TEAGN_FALSE_OR_LOG( value , message ) \
00247 if( ( value ) != 0 ) { \
00248 TEAGN_LOGWARN( TeAgnostic::to_string( message ) + \
00249 " - " + TeAgnostic::to_string( #value ) ); \
00250 };
00251
00252
00253
00254
00255
00256
00257
00258
00259 #define TEAGN_CHECK_EQUAL( value1 , value2 , message ) \
00260 TEAGN_TRUE_OR_THROW( ( ((double)( value1 ) ) == ((double)( value2 ) ) ), \
00261 std::string( "Values must be equal [" ) + \
00262 TeAgnostic::to_string( value1 ) + "!=" + \
00263 TeAgnostic::to_string( value2 ) + "] - " + \
00264 TeAgnostic::to_string( message ) );
00265
00266
00267
00268
00269
00270
00271
00272
00273 #define TEAGN_CHECK_NOTEQUAL( value1 , value2 , message ) \
00274 TEAGN_TRUE_OR_THROW( ( ((double)( value1 )) != ((double)( value2 )) ), \
00275 std::string( "Values can't be equal [" ) + \
00276 TeAgnostic::to_string( #value1 ) + std::string( "==" ) + \
00277 TeAgnostic::to_string( #value2 ) + std::string( "==" ) + \
00278 TeAgnostic::to_string( value1 ) + std::string( "]" ) );
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289 #define TEAGN_CHECK_EPS( value1 , value2 , eps , message ) \
00290 { \
00291 TEAGN_TRUE_OR_THROW( ( (eps) >= 0), "Invalid eps" ); \
00292 double TEAGN_CHECK_EPS_double_diff = 0; \
00293 double TEAGN_CHECK_EPS_double_value1 = (double)(value1); \
00294 double TEAGN_CHECK_EPS_double_value2 = (double)(value2); \
00295 double TEAGN_CHECK_EPS_double_eps = (double)(eps); \
00296 if( TEAGN_CHECK_EPS_double_value1 < TEAGN_CHECK_EPS_double_value2 ) { \
00297 TEAGN_CHECK_EPS_double_diff = ( TEAGN_CHECK_EPS_double_value2 - \
00298 TEAGN_CHECK_EPS_double_value1 ); \
00299 } else { \
00300 TEAGN_CHECK_EPS_double_diff = ( TEAGN_CHECK_EPS_double_value1 - \
00301 TEAGN_CHECK_EPS_double_value2 ); \
00302 }; \
00303 TEAGN_TRUE_OR_THROW( \
00304 TEAGN_CHECK_EPS_double_diff <= TEAGN_CHECK_EPS_double_eps, \
00305 std::string( "Values are not equal: " ) + \
00306 TeAgnostic::to_string( #value1 ) + \
00307 std::string( "=[") + \
00308 TeAgnostic::to_string( TEAGN_CHECK_EPS_double_value1 ) + \
00309 std::string( "] " ) + \
00310 TeAgnostic::to_string( #value2 ) + \
00311 std::string( "=[") + \
00312 TeAgnostic::to_string( TEAGN_CHECK_EPS_double_value2 ) + \
00313 std::string( "] eps=[") + \
00314 TeAgnostic::to_string( TEAGN_CHECK_EPS_double_eps ) + \
00315 std::string( "] diff=[") + \
00316 TeAgnostic::to_string( TEAGN_CHECK_EPS_double_diff ) + \
00317 std::string( "] - " ) + \
00318 TeAgnostic::to_string( message ) \
00319 ); \
00320 };
00321
00322
00323
00324
00325 #define TEAGN_NOT_IMPLEMENTED \
00326 TEAGN_LOG_AND_THROW( "Not Implemented." );
00327
00328
00329
00330
00331 #define TEAGN_DEBUG_MODE_CHECK \
00332 TEAGN_TRUE_OR_THROW( TeAgnostic::debugModeCheck() , \
00333 "Code not compiled with debug" );
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343 #ifdef TEAGN_DEBUG_MODE
00344 #define TEAGN_DEBUG_CONDITION( value , message ) \
00345 TEAGN_TRUE_OR_THROW( value , message );
00346 #else
00347 #define TEAGN_DEBUG_CONDITION( value , message );
00348 #endif
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359 #ifdef TEAGN_DEBUG_MODE
00360 #define TEAGN_DEBUG_RETURN( value , message ) \
00361 TEAGN_TRUE_OR_RETURN( value , message );
00362 #else
00363 #define TEAGN_DEBUG_RETURN( value , message );
00364 #endif
00365
00366
00367
00368
00369
00370
00371 namespace TeAgnostic{
00372
00373
00374
00375
00376
00377
00378
00379 template< class T >
00380 std::string to_string( const T& data )
00381 {
00382 std::stringstream temp_ss;
00383 temp_ss.setf(std::ios_base::fixed);
00384 temp_ss << data;
00385 return temp_ss.str();
00386 }
00387
00388
00389
00390
00391
00392
00393 TL_DLL bool debugModeCheck();
00394
00395 };
00396
00397 #endif