Belofte  version 2.1.5
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 
11 class bBoard;
12 class bSearchAlgorithm;
13 
14 class bel_debug final {
15 public:
16  bel_debug() {}
17  ~bel_debug();
18 
19  void execute(std::string const& args);
20  void info() const;
21 
22 public:
23  static void run_bench(bSearchAlgorithm& search, depth_t const nDepth);
24 
25 private:
26  std::string show_gamehistory() const;
27  std::string show_poshistory() const;
28  std::string show_fenhistory() const;
29  std::string show_hashhistory() const;
30 };
31 
32 /** output to std::cout and if required to debug and log-file
33  */
34 class outputWriter : public std::ostream {
35 public:
36  outputWriter();
37  ~outputWriter() override;
38 
39  // explicitly deny access to these functions
40  outputWriter(outputWriter const&) = delete;
42  outputWriter& operator=(outputWriter const&) = delete;
44 
45  outputWriter& operator<<(std::ostream& (*fun)(std::ostream& os));
46 
47  void setVerbosity(int const l) { m_verbosity = l; }
48  int getVerbosity() const { return m_verbosity; }
49 
50  bool attach(std::string const& fn);
51  void detach();
52  bool isAttached() const { return static_cast<bool>(m_fos); }
53  std::string fn() const { return m_filename ? *m_filename : ""; }
54 
55  void setExpecting(std::string const& s);
56  std::string getExpecting() const { return m_expecting ? *m_expecting : ""; }
57 
58  bool checkExpected(std::string const& s);
59  bool isExpected() const { return m_expected; }
60 
61  std::ostream& getOs() { return *m_os; }
62  std::ostream& getFos() { return *m_fos; }
63 
64 private:
65  template<typename T> friend std::ostream& operator<<(outputWriter& log, T o)
66  {
67  if (log.m_verbosity >= 0) {
68  log.getOs() << o;
69  if (log.isAttached()) log.getFos() << o;
70  }
71  return log.getOs();
72  }
73 
74 private:
75  int m_verbosity = 0;
76 
77  std::ostream* m_os = nullptr;
78  std::shared_ptr<std::ofstream> m_fos = nullptr;
79  std::shared_ptr<std::string> m_filename = nullptr;
80  std::shared_ptr<std::string> m_expecting = nullptr;
81  bool m_expected = false;
82 };
83 
84 #endif // defined BEL_DEBUG_H
85 
86 // eof
int_fast8_t depth_t
Definition: belofte.h:105
board
Definition: board.h:111
void info() const
Definition: bel_debug.cpp:56
static void run_bench(bSearchAlgorithm &search, depth_t const nDepth)
Definition: bel_debug.cpp:101
void execute(std::string const &args)
Definition: bel_debug.cpp:16
bel_debug()
Definition: bel_debug.h:16
output to std::cout and if required to debug and log-file
Definition: bel_debug.h:34
~outputWriter() override
Definition: bel_debug.cpp:189
outputWriter & operator=(outputWriter &&)=delete
outputWriter()
Outputwriter class will log to debug file, stdout and log file in this order if they have been initia...
Definition: bel_debug.cpp:184
bool checkExpected(std::string const &s)
Definition: bel_debug.cpp:246
int getVerbosity() const
Definition: bel_debug.h:48
void setExpecting(std::string const &s)
Definition: bel_debug.cpp:236
outputWriter & operator=(outputWriter const &)=delete
std::ostream & getOs()
Definition: bel_debug.h:61
bool isAttached() const
Definition: bel_debug.h:52
outputWriter(outputWriter const &)=delete
std::string fn() const
Definition: bel_debug.h:53
outputWriter(outputWriter &&)=delete
void detach()
Definition: bel_debug.cpp:228
std::ostream & getFos()
Definition: bel_debug.h:62
bool attach(std::string const &fn)
Definition: bel_debug.cpp:215
void setVerbosity(int const l)
Definition: bel_debug.h:47
friend std::ostream & operator<<(outputWriter &log, T o)
Definition: bel_debug.h:65
outputWriter & operator<<(std::ostream &(*fun)(std::ostream &os))
required for std::endl
Definition: bel_debug.cpp:200
std::string getExpecting() const
Definition: bel_debug.h:56
bool isExpected() const
Definition: bel_debug.h:59