Belofte version 2.2.0
A promising chess program using the UCI or Winboard interface
commandreader.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------+
2 * File: commandreader.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(COMMANDREADER_H)
9#define COMMANDREADER_H
10
11//-----------------------------------------------------------------------
12
13class noCommandException : public std::exception
14{
15 const char * what () const noexcept override
16 { return "No command"; }
17};
18
19//-----------------------------------------------------------------------
20
21#if defined(__GNUC__)
22#pragma GCC diagnostic push
23#pragma GCC diagnostic ignored "-Weffc++"
24#endif
25
27public:
29 : m_filename{}
30 {}
32 { if (isFileAttached())
33 detach();
34 }
35
36 // no copy or move ctor nor assignment defined
37 commandReader(commandReader const&) = delete;
41
42 bool attach(std::string const& ifile);
43 void detach();
44
46 { if (m_filename == "") return false;
47 if (!m_inputfile) return false;
48 if (m_inputfile.eof()) detach();
49 return m_inputfile.is_open();
50 }
52 { // no interactive input, mainly during start and '@' execute
53 if (isFileAttached()) return true;
54 return m_isBatch;
55 }
57 { m_isBatch = true; }
59 { m_isBatch = false; }
60
62 void runner();
63
64private:
65 std::string readLine();
66
67 std::string m_filename;
68 std::ifstream m_inputfile;
69 bool m_isBatch = true;
70};
71
72#if defined(__GNUC__)
73#pragma GCC diagnostic pop
74#endif
75
76//-----------------------------------------------------------------------
77
78#endif // defined COMMANDREADER_H
79
80// eof
command and parameters
Definition usercmd.h:41
commandReader & operator=(commandReader const &)=delete
commandReader(commandReader const &)=delete
void clearBatchMode()
bool isFileAttached()
cmdParam getCommand()
bool attach(std::string const &ifile)
commandReader(commandReader &&)=delete
void setBatchMode()
commandReader & operator=(commandReader &&)=delete