/usr/include/terralib/kernel/TeAgnostic.h is in libterralib-dev 4.3.0+dfsg.2-4build2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 | /************************************************************************************
TerraLib - a library for developing GIS applications.
Copyright © 2001-2007 INPE and Tecgraf/PUC-Rio.
This code is part of the TerraLib library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
You should have received a copy of the GNU Lesser General Public
License along with this library.
The authors reassure the license terms regarding the warranties.
They specifically disclaim any warranties, including, but not limited to,
the implied warranties of merchantability and fitness for a particular purpose.
The library provided hereunder is on an "as is" basis, and the authors have no
obligation to provide maintenance, support, updates, enhancements, or modifications.
In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct,
indirect, special, incidental, or consequential damages arising out of the use
of this library and its documentation.
*************************************************************************************/
/**
* @file TeAgnostic.h
* @brief This file contains a set of macros, routines and classes to deal with
* system checking and logging facility.
* They should NOT be used by anyone because the support and interfaces
* can be changed in future. THIS IS FOR INTERNAL USE ONLY.
* @author Emiliano F. Castejon <castejon@dpi.inpe.br>
*
* @note The following macros will be used:
*
* @param TEAGN_DEBUG_MODE If defined, debug code macros will be compiled and
* used or if not defined the compiler debug flag will be used.
* @param TEAGN_ENABLE_STDOUT_LOG If defined, messages also will be logged
* to STDOUT ( otherwise only TeErrorLog will log messages )
* or if not defined the compiler debug flag will be used.
*/
#ifndef TEAGNOSTIC_H
#define TEAGNOSTIC_H
#include <sstream>
#include <string>
#include <iostream>
#include <TeException.h>
#include <TeErrorLog.h>
/**
* @brief TeAgnostic debug mode selection based on NDEBUG define.
*/
#ifndef TEAGN_DEBUG_MODE
#ifndef NDEBUG
/** @brief Debug mode selection flag. */
#define TEAGN_DEBUG_MODE
/** @brief STDOUT logging selection flag. */
#ifndef TEAGN_ENABLE_STDOUT_LOG
#define TEAGN_ENABLE_STDOUT_LOG
#endif
#endif
#endif
/**
* @brief Logs a message to stdout
*
* @param message Message to be logged.
*/
#ifdef TEAGN_ENABLE_STDOUT_LOG
#define TEAGN_LOGMSG_STDOUT( message ) \
std::cout << std::endl << "Message : " \
<< __FILE__ \
<< ":" << __LINE__ \
<< " - " << TeAgnostic::to_string( message ) \
<< std::endl;
#else
#define TEAGN_LOGMSG_STDOUT( message ) {};
#endif
/**
* @brief Logs a error message to stderr
*
* @param message Message to be logged.
*/
#ifdef TEAGN_ENABLE_STDOUT_LOG
#define TEAGN_LOGERR_STDOUT( message ) \
std::cerr << std::endl << "Error : " \
<< __FILE__ \
<< ":" << __LINE__ \
<< " - " << TeAgnostic::to_string( message ) \
<< std::endl;
#else
#define TEAGN_LOGERR_STDOUT( message ) {};
#endif
/**
* @brief Logs a warning message to stdout
*
* @param message Message to be logged.
*/
#ifdef TEAGN_ENABLE_STDOUT_LOG
#define TEAGN_LOGWARN_STDOUT( message ) \
std::cout << std::endl << "Warning : " \
<< __FILE__ \
<< ":" << __LINE__ \
<< " - " << TeAgnostic::to_string( message ) \
<< std::endl;
#else
#define TEAGN_LOGWARN_STDOUT( message ) {};
#endif
/**
* @brief Logs a message.
*
* @param message Message to be logged.
*/
#define TEAGN_LOGMSG( message ) \
{ \
TeErrorLog::instance().insert( LOG_MESSAGE, \
TeAgnostic::to_string( message ) ); \
TEAGN_LOGMSG_STDOUT( message ); \
};
/**
* @brief Logs a message.
*
* @param message Message to be logged.
*/
#define TEAGN_LOGERR( message ) \
{ \
TeErrorLog::instance().insert( UNKNOWN_ERROR_TYPE, \
TeAgnostic::to_string( message ) ); \
TEAGN_LOGERR_STDOUT( message ); \
};
/**
* @brief Logs a warning message.
*
* @param message Message to be logged.
*/
#define TEAGN_LOGWARN( message ) \
{ \
TeErrorLog::instance().insert( LOG_MESSAGE, \
TeAgnostic::to_string( message ) ); \
TEAGN_LOGWARN_STDOUT( message ); \
};
/**
* @brief Logs a message to stderr and throws.
*
* @param message Message to be logged.
*/
#define TEAGN_LOG_AND_THROW( message ) \
{ \
TEAGN_LOGERR_STDOUT( message ); \
throw TeException( UNKNOWN_ERROR_TYPE, \
TeAgnostic::to_string( message ), false ); \
};
/**
* @brief Checks if value is true and throws an exception if not.
*
* @param value Value to be checked.
* @param message Message to be logged.
*/
#define TEAGN_TRUE_OR_THROW( value , message ) \
if( ( value ) == 0 ) { \
TEAGN_LOGERR_STDOUT( TeAgnostic::to_string( message ) + \
" - " + TeAgnostic::to_string( #value ) ); \
throw TeException( UNKNOWN_ERROR_TYPE, \
TeAgnostic::to_string( message ), false ); \
};
/**
* @brief Variable watching.
*
* @param variable Variable to be logged.
*/
#define TEAGN_WATCH( variable ) \
{ \
TEAGN_LOGMSG( "WATCH - " + TeAgnostic::to_string( #variable ) + \
"=[" + TeAgnostic::to_string( variable ) +"]" ); \
};
/**
* @brief Checks if value is true and logs an warning message if not.
*
* @param value Value to be checked.
* @param message Message to be logged.
*/
#define TEAGN_TRUE_OR_LOG( value , message ) \
if( ( value ) == 0 ) { \
TEAGN_LOGWARN( TeAgnostic::to_string( message ) + \
" - " + TeAgnostic::to_string( #value ) ); \
};
/**
* @brief Checks if value is true. For false values a warning message will be logged
* and a return of context with false value will be done.
*
* @param value Value to be checked.
* @param message Message to be logged.
*/
#define TEAGN_TRUE_OR_RETURN( value , message ) \
if( ( value ) == 0 ) { \
TEAGN_LOGWARN( TeAgnostic::to_string( message ) + \
" - " + TeAgnostic::to_string( #value ) ); \
return false; \
};
/**
* @brief Checks if value is false. For true values a warning message
* will be logged
* and a return of context with false value will be done.
*
* @param value Value to be checked.
* @param message Message to be logged.
*/
#define TEAGN_FALSE_OR_RETURN( value , message ) \
if( ( value ) != 0 ) { \
TEAGN_LOGWARN( TeAgnostic::to_string( message ) + \
" - " + TeAgnostic::to_string( #value ) ); \
return false; \
};
/**
* @brief Logs a warning message will and return false.
*
* @param message Message to be logged.
*/
#define TEAGN_LOG_AND_RETURN( message ) \
{ \
TEAGN_LOGWARN( message ); \
return false; \
};
/**
* @brief Checks if value is false and logs an warning message if not.
*
* @param value Value to be checked.
* @param message Message to be logged.
*/
#define TEAGN_FALSE_OR_LOG( value , message ) \
if( ( value ) != 0 ) { \
TEAGN_LOGWARN( TeAgnostic::to_string( message ) + \
" - " + TeAgnostic::to_string( #value ) ); \
};
/**
* @brief Checks if two values are equal and throws an exception if not.
*
* @param value1 Value to be checked.
* @param value2 Value to be checked.
* @param message Message to be logged.
*/
#define TEAGN_CHECK_EQUAL( value1 , value2 , message ) \
TEAGN_TRUE_OR_THROW( ( ((double)( value1 ) ) == ((double)( value2 ) ) ), \
std::string( "Values must be equal [" ) + \
TeAgnostic::to_string( value1 ) + "!=" + \
TeAgnostic::to_string( value2 ) + "] - " + \
TeAgnostic::to_string( message ) );
/**
* @brief Checks if two values are diferent and throws an exception if not.
*
* @param value1 Value to be checked.
* @param value2 Value to be checked.
* @param message Message to be logged.
*/
#define TEAGN_CHECK_NOTEQUAL( value1 , value2 , message ) \
TEAGN_TRUE_OR_THROW( ( ((double)( value1 )) != ((double)( value2 )) ), \
std::string( "Values can't be equal [" ) + \
TeAgnostic::to_string( #value1 ) + std::string( "==" ) + \
TeAgnostic::to_string( #value2 ) + std::string( "==" ) + \
TeAgnostic::to_string( value1 ) + std::string( "]" ) );
/**
* @brief Checks if two values are equal ( within an EPS ) and
* throws an exception if not.
*
* @param value1 Value to be checked.
* @param value2 Value to be checked.
* @param eps EPS ( threshold )
* @param message Message to be logged.
*/
#define TEAGN_CHECK_EPS( value1 , value2 , eps , message ) \
{ \
TEAGN_TRUE_OR_THROW( ( (eps) >= 0), "Invalid eps" ); \
double TEAGN_CHECK_EPS_double_diff = 0; \
double TEAGN_CHECK_EPS_double_value1 = (double)(value1); \
double TEAGN_CHECK_EPS_double_value2 = (double)(value2); \
double TEAGN_CHECK_EPS_double_eps = (double)(eps); \
if( TEAGN_CHECK_EPS_double_value1 < TEAGN_CHECK_EPS_double_value2 ) { \
TEAGN_CHECK_EPS_double_diff = ( TEAGN_CHECK_EPS_double_value2 - \
TEAGN_CHECK_EPS_double_value1 ); \
} else { \
TEAGN_CHECK_EPS_double_diff = ( TEAGN_CHECK_EPS_double_value1 - \
TEAGN_CHECK_EPS_double_value2 ); \
}; \
TEAGN_TRUE_OR_THROW( \
TEAGN_CHECK_EPS_double_diff <= TEAGN_CHECK_EPS_double_eps, \
std::string( "Values are not equal: " ) + \
TeAgnostic::to_string( #value1 ) + \
std::string( "=[") + \
TeAgnostic::to_string( TEAGN_CHECK_EPS_double_value1 ) + \
std::string( "] " ) + \
TeAgnostic::to_string( #value2 ) + \
std::string( "=[") + \
TeAgnostic::to_string( TEAGN_CHECK_EPS_double_value2 ) + \
std::string( "] eps=[") + \
TeAgnostic::to_string( TEAGN_CHECK_EPS_double_eps ) + \
std::string( "] diff=[") + \
TeAgnostic::to_string( TEAGN_CHECK_EPS_double_diff ) + \
std::string( "] - " ) + \
TeAgnostic::to_string( message ) \
); \
};
/**
* @brief Throws an exception for not implemented source.
*/
#define TEAGN_NOT_IMPLEMENTED \
TEAGN_LOG_AND_THROW( "Not Implemented." );
/**
* @brief Checks if Debug mode is enabled and throws an exception if not.
*/
#define TEAGN_DEBUG_MODE_CHECK \
TEAGN_TRUE_OR_THROW( TeAgnostic::debugModeCheck() , \
"Code not compiled with debug" );
/**
* @brief Checks if value is true and throws an exception if not.
*
* @note This macro will be disabled for non debug mode.
*
* @param value Value to be checked.
* @param message Message to be logged.
*/
#ifdef TEAGN_DEBUG_MODE
#define TEAGN_DEBUG_CONDITION( value , message ) \
TEAGN_TRUE_OR_THROW( value , message );
#else
#define TEAGN_DEBUG_CONDITION( value , message );
#endif
/**
* @brief Checks if value is true. For false values a warning message will be logged
* and a return of context with false value will be done.
*
* @note This macro will be disabled for non debug mode.
*
* @param value Value to be checked.
* @param message Message to be logged.
*/
#ifdef TEAGN_DEBUG_MODE
#define TEAGN_DEBUG_RETURN( value , message ) \
TEAGN_TRUE_OR_RETURN( value , message );
#else
#define TEAGN_DEBUG_RETURN( value , message );
#endif
/**
* @brief This namespace contains a set of routines and classes to deal with
* system checking and logging facility.
* @ingroup Utils
*/
namespace TeAgnostic{
/**
* @brief Data conversion to string.
*
* @param data Data to be converted.
* @return The converted string.
*/
template< class T >
std::string to_string( const T& data )
{
std::stringstream temp_ss;
temp_ss.setf(std::ios_base::fixed);
temp_ss << data;
return temp_ss.str();
}
/**
* @brief Checks if the code was compiled with debug mode.
*
* @return true if debug mode was used at compilation time. false if not.
*/
TL_DLL bool debugModeCheck();
};
#endif
|