OSDN Git Service

オランダ語プラグイン追加。
[wordring-tm/wordring-tm.git] / third-party / OleanderStemmingLibrary / utilities / debug_logic.h
1 /**
2 \date 2008-2015
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.
7 */
8
9 #ifndef __DEBUG_LOGIC_H__
10 #define __DEBUG_LOGIC_H__
11
12 #include <iostream>
13 #include <fstream>
14 #include <iterator>
15
16 /** \addtogroup Debugging
17    * Functions used for debugging.
18    * @{*/
19 /**
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.*/
31 /** @} */
32
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__
43 #endif
44
45 //----------------------------------------------------------------------
46 #if !defined (NDEBUG) || defined ENABLE_LOGIC_CHECKS || defined DEBUG_ENABLE_ALL
47     #define CASSERT(x) typedef char __C_ASSERT__[(x) ? 1 : -1]
48 #else
49     #define CASSERT(x) ((void)0)
50 #endif
51
52 //----------------------------------------------------------------------
53 #ifdef __UNITTEST
54     #define NON_UNIT_TEST_ASSERT(x) ((void)0)
55 #else
56     #define NON_UNIT_TEST_ASSERT(x) assert(x)
57 #endif
58
59 //----------------------------------------------------------------------
60 #if !defined (NDEBUG) || defined DEBUG_ENABLE_ALL
61     #define DUMP_TO_FILE(x,file) __debug::__dump_to_file((x), (file))
62 #else
63     #define DUMP_TO_FILE(x,file) ((void)0)
64 #endif
65
66 //----------------------------------------------------------------------
67 namespace __debug
68     {
69     //debug helpers
70     inline void __dump_to_file(const wchar_t* begin, const std::string& file_path)
71         {
72         if (begin == NULL)
73             { return; }
74         std::wofstream f(file_path.c_str());
75         f.write(begin, static_cast<std::streamsize>(std::wcslen(begin)));
76         }
77     }
78
79 #endif //__DEBUG_LOGIC_H__