| TerraLib 4.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

E:/Projetos_Primeiro_Semestre_2012/TerraView/terralib/src/terralib/kernel/TeAgnostic.h
Go to the documentation of this file.

    00001 /************************************************************************************
    00002 TerraLib - a library for developing GIS applications.
    00003 Copyright � 2001-2007 INPE and Tecgraf/PUC-Rio.
    00004
    00005 This code is part of the TerraLib library.
    00006 This library is free software; you can redistribute it and/or
    00007 modify it under the terms of the GNU Lesser General Public
    00008 License as published by the Free Software Foundation; either
    00009 version 2.1 of the License, or (at your option) any later version.
    00010
    00011 You should have received a copy of the GNU Lesser General Public
    00012 License along with this library.
    00013
    00014 The authors reassure the license terms regarding the warranties.
    00015 They specifically disclaim any warranties, including, but not limited to,
    00016 the implied warranties of merchantability and fitness for a particular purpose.
    00017 The library provided hereunder is on an "as is" basis, and the authors have no
    00018 obligation to provide maintenance, support, updates, enhancements, or modifications.
    00019 In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct,
    00020 indirect, special, incidental, or consequential damages arising out of the use
    00021 of this library and its documentation.
    00022 *************************************************************************************/
    00023
    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
    00054   #ifndef TEAGN_DEBUG_MODE
    00055     #ifndef NDEBUG
    00056
    00057       #define TEAGN_DEBUG_MODE
    00058
    00060       #ifndef TEAGN_ENABLE_STDOUT_LOG
    00061         #define TEAGN_ENABLE_STDOUT_LOG
    00062       #endif
    00063     #endif
    00064   #endif
    00065
    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
    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
    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
    00120   #define TEAGN_LOGMSG( message ) \
    00121   { \
    00122     TeErrorLog::instance().insert( LOG_MESSAGE, \
    00123       TeAgnostic::to_string( message ) ); \
    00124     TEAGN_LOGMSG_STDOUT( message ); \
    00125   };
    00126
    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
    00144   #define TEAGN_LOGWARN( message ) \
    00145   { \
    00146     TeErrorLog::instance().insert( LOG_MESSAGE, \
    00147      TeAgnostic::to_string( message ) ); \
    00148     TEAGN_LOGWARN_STDOUT( message ); \
    00149   };
    00150
    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
    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
    00182   #define TEAGN_WATCH( variable ) \
    00183     { \
    00184       TEAGN_LOGMSG( "WATCH - " + TeAgnostic::to_string( #variable ) + \
    00185         "=[" + TeAgnostic::to_string( variable ) +"]" ); \
    00186     };
    00187
    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
    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
    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
    00234   #define TEAGN_LOG_AND_RETURN( message ) \
    00235     { \
    00236       TEAGN_LOGWARN( message ); \
    00237       return false; \
    00238     };
    00239
    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
    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
    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
    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
    00325   #define TEAGN_NOT_IMPLEMENTED \
    00326     TEAGN_LOG_AND_THROW( "Not Implemented." );
    00327
    00331   #define TEAGN_DEBUG_MODE_CHECK \
    00332     TEAGN_TRUE_OR_THROW( TeAgnostic::debugModeCheck() , \
    00333     "Code not compiled with debug" );
    00334
    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
    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
    00371   namespace TeAgnostic{
    00372
    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
    00393      TL_DLL bool debugModeCheck();
    00394
    00395   };
    00396
    00397 #endif

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines