Belofte version 2.1.9
A promising chess program using the UCI or Winboard interface
bel_debug.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------+
2 * File: bel_debug.h
3 * Project: part of belofte - A Promising Chess Program
4 * Author: yves
5 * SPDX-License-Identifier: GPL-2.0-only
6+----------------------------------------------------------------------*/
7
8#if !defined(BEL_DEBUG_H)
9#define BEL_DEBUG_H
10
11class bBoard;
13
14class bel_debug {
15public:
17 {}
19 {}
20
21 void execute(std::string const& args);
22 void info() const;
23
24public:
25 static void run_bench(bSearchAlgorithm& search, depth_t const nDepth);
26
27private:
28 std::string show_help() const;
29 std::string show_gamehistory() const;
30 std::string show_poshistory() const;
31 std::string show_fenhistory() const;
32 std::string show_hashhistory() const;
33};
34
35/**
36 * output to std::cout and if required to debug and log-file
37 */
38class outputWriter : public std::ostream {
39public:
40 explicit outputWriter(std::ostream& os);
41 ~outputWriter() override;
42
43 // explicitly deny access to these functions
44 outputWriter(outputWriter const&) = delete;
48
49 inline void setLevel(int const l)
50 { m_level = l; }
51 inline int getLevel() const
52 { return m_level; }
53
54 bool attach(std::string const& fn);
55 void detach();
56
57 inline bool isAttached() const
58 { return m_attached; }
59 inline std::string const& fn() const
60 { return m_filename; }
61
63 {
64 m_curlinelevel = l;
65 return *this;
66 }
67
69 {
70 if (m_curlinelevel <= m_level) {
71 m_os << std::endl;
72 if (isAttached()) m_fos << std::endl;
73 }
74 m_curlinelevel = 0;
75 return *this;
76 }
77
78 std::ostream& getOs()
79 { return m_os; }
80 std::ostream& getFos()
81 { return m_fos; }
82
83private:
84 template<typename T> friend std::ostream& operator<<(outputWriter& log, T o)
85 {
86 if (log.m_curlinelevel <= log.m_level) {
87 log.getOs() << o;
88 if (log.isAttached()) log.getFos() << o;
89 }
90 return log.getOs();
91 }
92
93 int m_curlinelevel = 0;
94 int m_level = 0;
95 bool m_attached = false;
96 std::string m_filename = "";
97
98 std::ostream& m_os;
99 std::ofstream m_fos;
100};
101
102#endif // defined BEL_DEBUG_H
103
104// eof
int_fast8_t depth_t
Definition belofte.h:103
board
Definition board.h:45
void info() const
Definition bel_debug.cpp:81
static void run_bench(bSearchAlgorithm &search, depth_t const nDepth)
void execute(std::string const &args)
Definition bel_debug.cpp:12
outputWriter & operator=(outputWriter const &)=delete
outputWriter & operator()(int const l)
Definition bel_debug.h:62
~outputWriter() override
std::ostream & getOs()
Definition bel_debug.h:78
outputWriter & operator=(outputWriter &&)=delete
int getLevel() const
Definition bel_debug.h:51
bool isAttached() const
Definition bel_debug.h:57
outputWriter(std::ostream &os)
Outputwriter class will log to debug file, stdout and log file in this order if they have been initia...
std::string const & fn() const
Definition bel_debug.h:59
outputWriter(outputWriter const &)=delete
outputWriter(outputWriter &&)=delete
friend std::ostream & operator<<(outputWriter &log, T o)
Definition bel_debug.h:84
bool attach(std::string const &fn)
outputWriter & endl()
Definition bel_debug.h:68
std::ostream & getFos()
Definition bel_debug.h:80
void setLevel(int const l)
Definition bel_debug.h:49