Don't keep compiling/run if something failed.
[kdevelopdvcssupport.git] / plugins / teamwork / verify.h
blob5049b49e93619403a564dd5fcee12daba997302f
1 /***************************************************************************
2 Copyright 2006 David Nolden <david.nolden.kdevelop@art-master.de>
3 ***************************************************************************/
5 /***************************************************************************
6 * *
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. *
11 * *
12 ***************************************************************************/
14 #ifndef VERIFY_H
15 #define VERIFY_H
17 #include <string>
18 #include <sstream>
20 struct ExpressionError {
21 std::string function;
22 int line;
23 std::string file;
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;
30 #ifndef HAVE_TOTEXT
31 #define HAVE_TOTEXT
33 template <class Item>
34 std::string toText( const Item& it ) {
35 std::ostringstream os;
36 os << it;
37 return os.str();
39 #endif
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() ); }
62 #endif
64 // kate: space-indent on; indent-width 2; tab-width 2; replace-tabs on