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
13
class
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
26
class
commandReader
{
27
public
:
28
commandReader
()
29
: m_filename{}
30
{}
31
~commandReader
()
32
{
if
(
isFileAttached
())
33
detach
();
34
}
35
36
// no copy or move ctor nor assignment defined
37
commandReader
(
commandReader
const
&) =
delete
;
38
commandReader
(
commandReader
&&) =
delete
;
39
commandReader
&
operator=
(
commandReader
const
&) =
delete
;
40
commandReader
&
operator=
(
commandReader
&&) =
delete
;
41
42
bool
attach
(std::string
const
& ifile);
43
void
detach
();
44
45
bool
isFileAttached
()
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
}
51
bool
isBatchMode
()
52
{
// no interactive input, mainly during start and '@' execute
53
if
(
isFileAttached
())
return
true
;
54
return
m_isBatch;
55
}
56
void
setBatchMode
()
57
{ m_isBatch =
true
; }
58
void
clearBatchMode
()
59
{ m_isBatch =
false
; }
60
61
cmdParam
getCommand
();
62
void
runner
();
63
64
private
:
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
cmdParam
command and parameters
Definition
usercmd.h:41
commandReader::isBatchMode
bool isBatchMode()
Definition
commandreader.h:51
commandReader::operator=
commandReader & operator=(commandReader const &)=delete
commandReader::commandReader
commandReader(commandReader const &)=delete
commandReader::clearBatchMode
void clearBatchMode()
Definition
commandreader.h:58
commandReader::runner
void runner()
Definition
commandreader.cpp:12
commandReader::commandReader
commandReader()
Definition
commandreader.h:28
commandReader::isFileAttached
bool isFileAttached()
Definition
commandreader.h:45
commandReader::~commandReader
~commandReader()
Definition
commandreader.h:31
commandReader::getCommand
cmdParam getCommand()
Definition
commandreader.cpp:53
commandReader::attach
bool attach(std::string const &ifile)
Definition
commandreader.cpp:76
commandReader::detach
void detach()
Definition
commandreader.cpp:83
commandReader::commandReader
commandReader(commandReader &&)=delete
commandReader::setBatchMode
void setBatchMode()
Definition
commandreader.h:56
commandReader::operator=
commandReader & operator=(commandReader &&)=delete
noCommandException
Definition
commandreader.h:14
src
commandreader.h
Generated on 06/01/2026 by
1.13.2