Author: jetryl
Date: Sun Dec 7 02:29:28 2008
New Revision: 31326
URL: http://svn.gna.org/viewcvs/wesnoth?rev=31326&view=rev
Log:
Added a set of assert macros.
Added:
trunk/src/asserts.hpp
Added: trunk/src/asserts.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/asserts.hpp?rev=31326&view=auto
==============================================================================
--- trunk/src/asserts.hpp (added)
+++ trunk/src/asserts.hpp Sun Dec 7 02:29:28 2008
@@ -1,0 +1,40 @@
+/*
+ Copyright (C) 2008 by David White <[EMAIL PROTECTED]>
+ 2008 by Richard Kettering <[EMAIL PROTECTED]>
+ Part of the Battle for Wesnoth Project http://www.wesnoth.org/
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License version 2
+ or at your option any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY.
+
+ See the COPYING file for more details.
+*/
+
+
+#ifndef ASSERTS_HPP_INCLUDED
+#define ASSERTS_HPP_INCLUDED
+
+#include <iostream>
+
+//various asserts of standard "equality" tests, such as "equals", "not
equals", "greater than", etc. Example usage:
+//assert_ne(x, y);
+#define assert_eq(a,b) if((a) != (b)) { std::cerr << __FILE__ << ":" <<
__LINE__ << " ASSERT EQ FAILED: " << #a << " != " << #b << ": " << (a) << " !=
" << (b) << "\n"; abort(); }
+
+#define assert_ne(a,b) if((a) == (b)) { std::cerr << __FILE__ << ":" <<
__LINE__ << " ASSERT NE FAILED: " << #a << " == " << #b << ": " << (a) << " ==
" << (b) << "\n"; abort(); }
+
+#define assert_ge(a,b) if((a) < (b)) { std::cerr << __FILE__ << ":" <<
__LINE__ << " ASSERT GE FAILED: " << #a << " == " << #b << ": " << (a) << " ==
" << (b) << "\n"; abort(); }
+
+#define assert_le(a,b) if((a) > (b)) { std::cerr << __FILE__ << ":" <<
__LINE__ << " ASSERT LE FAILED: " << #a << " == " << #b << ": " << (a) << " ==
" << (b) << "\n"; abort(); }
+
+#define assert_gt(a,b) if((a) <= (b)) { std::cerr << __FILE__ << ":" <<
__LINE__ << " ASSERT GT FAILED: " << #a << " == " << #b << ": " << (a) << " ==
" << (b) << "\n"; abort(); }
+
+#define assert_lt(a,b) if((a) >= (b)) { std::cerr << __FILE__ << ":" <<
__LINE__ << " ASSERT LT FAILED: " << #a << " == " << #b << ": " << (a) << " ==
" << (b) << "\n"; abort(); }
+
+//for custom logging. Example usage:
+//assert_log(x != y, "x not equal to y. Value of x: " << x << ", y: " << y);
+#define assert_log(a,b) if( !(a) ) { std::cerr << __FILE__ << ":" << __LINE__
<< " ASSSERTION FAILED: " << (b) << "\n"; abort(); }
+
+
+#endif
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits