Arduino Libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
ard_assert.hpp
Go to the documentation of this file.
1 // Author: Mario S. Könz <mskoenz@gmx.net>
2 // Date: 20.05.2013 11:44:18 EDT
3 // File: aassert.hpp
4 
5 /* This program is free software. It comes without any warranty, to
6  * the extent permitted by applicable law. You can redistribute it
7  * and/or modify it under the terms of the Do What The Fuck You Want
8  * To Public License, Version 2, as published by Sam Hocevar. See
9  * http://www.wtfpl.net/ or COPYING for more details. */
10 
11 #ifndef __ARD_ASSERT_HEADER
12 #define __ARD_ASSERT_HEADER
13 
14 #ifdef DEBUG_ON
15  #ifdef STD_SUPPORT
16  #include <iostream>
17  #include <assert.h>
18  #define DEBUG_VAR(x) std::cout << REDB << F("DEBUG_VAR: ") << RED << F(#x) << F(" = ") << x << NONE << std::endl;
19  #define DEBUG_MSG(x) std::cout << REDB << F("DEBUG_MSG: ") << RED << F(x) << NONE << std::endl;
20  #define ASSERT(exp) if(!(exp)) {std::cout << REDB << F("ASSERT failed on line ") << __LINE__ << RED << F(" ") << F(#exp) << NONE << std::endl; assert(exp);}
21  #define ASSERT_MSG(exp, msg) if(!(exp)) {std::cout << REDB << F("ASSERT_MSG failed on line ") << __LINE__ << RED << F(" ") << F(#exp) << REDB << F(" ") << F(msg) << NONE << std::endl; assert(exp);}
22  #else
23  #include "iostream.hpp"
24  #include <avr/pgmspace.h>
25  #define DEBUG_VAR(x) ustd::cout << REDB << F("DEBUG_VAR: ") << RED << F(#x) << F(" = ") << x << NONE << ustd::endl;
26  #define DEBUG_MSG(x) ustd::cout << REDB << F("DEBUG_MSG: ") << RED << F(x) << NONE << ustd::endl;
27  #define ASSERT(exp) if(!(exp)) {ustd::cout << REDB << F("ASSERT failed on line ") << __LINE__ << RED << F(" ") << F(#exp) << NONE << ustd::endl; while(true);}
28  #define ASSERT_MSG(exp, msg) if(!(exp)) {ustd::cout << REDB << F("ASSERT_MSG failed on line ") << __LINE__ << RED << F(" ") << F(#exp) << REDB << F(" ") << F(msg) << NONE << ustd::endl; while(true);}
29  #endif
30 #else
31  #define DEBUG_VAR(x) ;
32  #define DEBUG_MSG(x) ;
33  #define ASSERT(exp) ;
34  #define ASSERT_MSG(exp, msg) ;
35 #endif
36 
37 #endif //__ARD_ASSERT_HEADER