1 /***************************************************************************
2 Copyright 2006 David Nolden <david.nolden.kdevelop@art-master.de>
3 ***************************************************************************/
5 /***************************************************************************
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
12 ***************************************************************************/
20 struct ExpressionError
{
24 std::string expression
;
25 std::string realExpression
;
26 ExpressionError( const std::string
& fun
, int l
, const std::string
& f
, const std::string
& exp
, const std::string
& realExp
= "" );
27 std::string
what() const;
34 std::string
toText( const Item
& it
) {
35 std::ostringstream os
;
41 #define VERIFY( x ) if( x ){}else{ throw ExpressionError( __FUNCTION__, __LINE__, __FILE__, #x ); }
42 #define VERIFY_SAME( a, b ) if( a == b ){}else{ throw ExpressionError( __FUNCTION__, __LINE__, __FILE__, #a + std::string(" == " ) + #b, toText( a ) + std::string( " == " ) + toText( b ) ); }
43 #define VERIFY_SMALLER( a, b ) if( a < b ){}else{ throw ExpressionError( __FUNCTION__, __LINE__, __FILE__, #a + std::string(" < " ) + #b, toText( a ) + std::string( " < " ) + toText( b ) ); }
44 #define VERIFY_SMALLERSAME( a, b ) if( a <= b ){}else{ throw ExpressionError( __FUNCTION__, __LINE__, __FILE__, #a + std::string(" <= " ) + #b, toText( a ) + std::string( " <= " ) + toText( b ) ); }
45 #define VERIFY_NOTSAME( a, b ) if( !(a == b) ){}else{ throw ExpressionError( __FUNCTION__, __LINE__, __FILE__, #a + std::string(" != " ) + #b, toText( a ) + std::string( " != " ) + toText( b ) ); }
48 ///These throw a std::string
49 #define S_VERIFY( x ) if( x ){}else{ throw ExpressionError( __FUNCTION__, __LINE__, __FILE__, #x ).what(); }
50 #define S_VERIFY_SAME( a, b ) if( a == b ){}else{ throw ExpressionError( __FUNCTION__, __LINE__, __FILE__, #a + std::string(" == " ) + #b, toText( a ) + std::string( " == " ) + toText( b ) ).what(); }
51 #define S_VERIFY_SMALLER( a, b ) if( a < b ){}else{ throw ExpressionError( __FUNCTION__, __LINE__, __FILE__, #a + std::string(" < " ) + #b, toText( a ) + std::string( " < " ) + toText( b ) ).what(); }
52 #define S_VERIFY_SMALLERSAME( a, b ) if( a <= b ){}else{ throw ExpressionError( __FUNCTION__, __LINE__, __FILE__, #a + std::string(" <= " ) + #b, toText( a ) + std::string( " <= " ) + toText( b ) ).what(); }
53 #define S_VERIFY_NOTSAME( a, b ) if( !(a == b) ){}else{ throw ExpressionError( __FUNCTION__, __LINE__, __FILE__, #a + std::string(" != " ) + #b, toText( a ) + std::string( " != " ) + toText( b ) ).what(); }
55 ///These throw a QString
56 #define Q_VERIFY( x ) if( x ){}else{ throw QString( ExpressionError( __FUNCTION__, __LINE__, __FILE__, #x ).what().c_str() ); }
57 #define Q_VERIFY_SAME( a, b ) if( a == b ){}else{ throw QString( ExpressionError( __FUNCTION__, __LINE__, __FILE__, #a + std::string(" == " ) + #b, toText( a ) + std::string( " == " ) + toText( b ) ).what().c_str() ); }
58 #define Q_VERIFY_SMALLER( a, b ) if( a < b ){}else{ throw QString( ExpressionError( __FUNCTION__, __LINE__, __FILE__, #a + std::string(" < " ) + #b, toText( a ) + std::string( " < " ) + toText( b ) ).what().c_str() ); }
59 #define Q_VERIFY_SMALLERSAME( a, b ) if( a <= b ){}else{ throw QString( ExpressionError( __FUNCTION__, __LINE__, __FILE__, #a + std::string(" <= " ) + #b, toText( a ) + std::string( " <= " ) + toText( b ) ).what().c_str() ); }
60 #define Q_VERIFY_NOTSAME( a, b ) if( !(a == b) ){}else{ throw QString( ExpressionError( __FUNCTION__, __LINE__, __FILE__, #a + std::string(" != " ) + #b, toText( a ) + std::string( " != " ) + toText( b ) ).what().c_str() ); }
64 // kate: space-indent on; indent-width 2; tab-width 2; replace-tabs on