OdinAI
 All Classes Namespaces Functions Variables
DebugUtil.h
1 /*******************************************************************************
2  * ________ .___.__ _____ .___
3  * \_____ \ __| _/|__| ____ / _ \ | |
4  * / | \ / __ | | |/ \ / /_\ \| |
5  * / | \/ /_/ | | | | \/ | \ |
6  * \_______ /\____ | |__|___| /\____|__ /___|
7  * \/ \/ \/ \/
8  *
9  * Copyright (c) Emil Sandstø 2012
10  *******************************************************************************/
11 #ifndef ODINAI_DEBUG_UTIL_H
12 #define ODINAI_DEBUG_UTIL_H
13 
14 #ifdef _WINDOWS
15 #pragma once
16 #endif
17 
18 #include <cassert>
19 #include <iostream>
20 
21 namespace OdinAI
22 {
23  #ifdef SAFE_VERSION
24  #ifdef NDEBUG
25  #define Assert(x) (if(!x){return;})
26  #else
27  #define Assert(x) (assert(x))
28  #endif
29  #else
30  #define Assert(x)
31  #endif
32 
33  inline void DebugMessage(const char *msg)
34  {
35  std::cout << msg << std::endl;
36  }
37 
38  //Assertion with message
39  #define AssertMsg(x, msg) (DebugMessage(msg);assert(x);)
40 
41  //Free heap allocated memory safely.
42  #define SAFE_DELETE(x) if(x){delete x;x=0;}
43  #define SAFE_DELETE_ARRAY(x) if(x){delete[]x;x=0;}
44 
45  //User defined Compiler warning
46  #ifdef _MSC_VER
47  #define __STR2__(x) #x
48  #define __STR1__(x) __STR2__(x)
49  #define __LOC__ __FILE__ "("__STR1__(__LINE__)") : Warning Msg: "
50  #define CompilerWarning(x) message(__LOC__ x)
51  #else
52  #define CompilerWarning(x)
53  #endif
54 }
55 #endif