Belofte version 2.1.8
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 final {
15public:
17 ~bel_debug();
18
19 void execute(std::string const& args);
20 void info() const;
21
22public:
23 static void run_bench(bSearchAlgorithm& search, depth_t const nDepth);
24
25private:
26 std::string show_help() const;
27 std::string show_gamehistory() const;
28 std::string show_poshistory() const;
29 std::string show_fenhistory() const;
30 std::string show_hashhistory() const;
31};
32
33/** output to std::cout and if required to debug and log-file
34 */
35class outputWriter : public std::ostream {
36public:
37 explicit outputWriter(std::ostream& os);
38 ~outputWriter() override;
39
40 // explicitly deny access to these functions
41 outputWriter(outputWriter const&) = delete;
45
46 void setLevel(int const l) { m_level = l; }
47 int getLevel() const { return m_level; }
48
49 bool attach(std::string const& fn);
50 void detach();
51
52 bool isAttached() const { return m_attached; }
53 std::string const& fn() const { return m_filename; }
54
56 {
57 m_tmplevel = l;
58 return *this;
59 }
61 {
62 if (m_tmplevel <= m_level) {
63 m_os << std::endl;
64 if (isAttached()) m_fos << std::endl;
65 }
66 m_tmplevel = 0;
67 return *this;
68 }
69
70 std::ostream& getOs() { return m_os; }
71 std::ostream& getFos() { return m_fos; }
72
73private:
74 template<typename T> friend std::ostream& operator<<(outputWriter& log, T o)
75 {
76 if (log.m_tmplevel <= log.m_level) {
77 log.getOs() << o;
78 if (log.isAttached()) log.getFos() << o;
79 }
80 return log.getOs();
81 }
82
83private:
84 int m_tmplevel = 0;
85 int m_level = 0;
86
87 std::ostream& m_os;
88
89 bool m_attached = false;
90 std::string m_filename = "";
91 std::ofstream m_fos;
92};
93
94#endif // defined BEL_DEBUG_H
95
96// eof
int_fast8_t depth_t
Definition belofte.h:112
board
Definition board.h:147
void info() const
Definition bel_debug.cpp:79
static void run_bench(bSearchAlgorithm &search, depth_t const nDepth)
void execute(std::string const &args)
Definition bel_debug.cpp:16
output to std::cout and if required to debug and log-file
Definition bel_debug.h:35
outputWriter & operator=(outputWriter const &)=delete
outputWriter & operator()(int const l)
Definition bel_debug.h:55
~outputWriter() override
std::ostream & getOs()
Definition bel_debug.h:70
outputWriter & operator=(outputWriter &&)=delete
int getLevel() const
Definition bel_debug.h:47
bool isAttached() const
Definition bel_debug.h:52
std::string const & fn() const
Definition bel_debug.h:53
outputWriter(outputWriter const &)=delete
outputWriter(outputWriter &&)=delete
friend std::ostream & operator<<(outputWriter &log, T o)
Definition bel_debug.h:74
bool attach(std::string const &fn)
outputWriter & endl()
Definition bel_debug.h:60
std::ostream & getFos()
Definition bel_debug.h:71
void setLevel(int const l)
Definition bel_debug.h:46