3 \copyright Oleander Software, Ltd.
4 \author Oleander Software, Ltd.
5 \details This program is free software; you can redistribute it and/or modify
6 it under the terms of the BSD License.
9 #ifndef __DEBUG_LOGIC_H__
10 #define __DEBUG_LOGIC_H__
16 /** \addtogroup Debugging
17 * Functions used for debugging.
20 \def __DEBUG_FUNCTION_NAME__
21 Expands to the name of the current function. Will not be defined if
22 compiler does not have a native function name macro.
23 \def CASSERT(expression)
24 Validates that an expression is true at compile time. If the expression is false
25 then compilation will fail.
26 \def NON_UNIT_TEST_ASSERT(expression)
27 If unit test symbol (__UNITTEST) is defined then does nothing; otherwise asserts.
28 This is useful for suppressing asserts when unit testing.
29 \def DUMP_TO_FILE(stream,file)
30 Prints data stream to a specified file.*/
33 #ifdef __PRETTY_FUNCTION__
34 #define __DEBUG_FUNCTION_NAME__ __PRETTY_FUNCTION__
35 #elif defined(__FUNCTION__)
36 #define __DEBUG_FUNCTION_NAME__ __FUNCTION__
37 #elif defined(__func__)
38 #define __DEBUG_FUNCTION_NAME__ __func__
39 #elif defined(__FUNCSIG__)
40 #define __DEBUG_FUNCTION_NAME__ __FUNCSIG__
41 #elif defined(__FUNCDNAME__)
42 #define __DEBUG_FUNCTION_NAME__ __FUNCDNAME__
45 //----------------------------------------------------------------------
46 #if !defined (NDEBUG) || defined ENABLE_LOGIC_CHECKS || defined DEBUG_ENABLE_ALL
47 #define CASSERT(x) typedef char __C_ASSERT__[(x) ? 1 : -1]
49 #define CASSERT(x) ((void)0)
52 //----------------------------------------------------------------------
54 #define NON_UNIT_TEST_ASSERT(x) ((void)0)
56 #define NON_UNIT_TEST_ASSERT(x) assert(x)
59 //----------------------------------------------------------------------
60 #if !defined (NDEBUG) || defined DEBUG_ENABLE_ALL
61 #define DUMP_TO_FILE(x,file) __debug::__dump_to_file((x), (file))
63 #define DUMP_TO_FILE(x,file) ((void)0)
66 //----------------------------------------------------------------------
70 inline void __dump_to_file(const wchar_t* begin, const std::string& file_path)
74 std::wofstream f(file_path.c_str());
75 f.write(begin, static_cast<std::streamsize>(std::wcslen(begin)));
79 #endif //__DEBUG_LOGIC_H__