HooverChessUtils_PgnReader 0.9.0
Loading...
Searching...
No Matches
pgnreader-error.h
Go to the documentation of this file.
1// Hoover Chess Utilities / PGN reader
2// Copyright (C) 2022-2025 Sami Kiminki
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17#ifndef HOOVER_CHESS_UTILS__PGN_READER__PGNREADER_ERROR_H_INCLUDED
18#define HOOVER_CHESS_UTILS__PGN_READER__PGNREADER_ERROR_H_INCLUDED
19
20#include <exception>
21#include <string>
22#include <string_view>
23
25{
26 class PgnScanner;
27
30
34enum class PgnErrorCode : unsigned
35{
38 OK = 0U,
39
41 BAD_CHARACTER = 1U,
42
45
48
51
53 BAD_FEN,
54
57
60
63
66};
67
69class PgnError : public std::exception
70{
71private:
73 std::string m_str;
74
77
78public:
83 PgnError(PgnErrorCode code, std::string_view details);
84
89 PgnError(const PgnScanner &scanner, const PgnError &ex);
90
94 const char *what() const noexcept override
95 {
96 return m_str.c_str();
97 }
98
102 PgnErrorCode getCode() const noexcept
103 {
104 return m_code;
105 }
106
111 static std::string_view getStringForCode(PgnErrorCode code) noexcept;
112
113};
114
116
117}
118
119
120#endif
PGN error exception.
Definition pgnreader-error.h:70
const char * what() const noexcept override
Returns the error message.
Definition pgnreader-error.h:94
PgnErrorCode m_code
Error code.
Definition pgnreader-error.h:76
PgnError(PgnErrorCode code, std::string_view details)
Constructor: error code and error message.
static std::string_view getStringForCode(PgnErrorCode code) noexcept
Returns error string for code.
PgnError(const PgnScanner &scanner, const PgnError &ex)
Constructor: adds position to a PGN error.
std::string m_str
Error string.
Definition pgnreader-error.h:73
PgnErrorCode getCode() const noexcept
Returns the error code.
Definition pgnreader-error.h:102
The PGN scanner (lexer)
Definition pgnscanner.h:40
PgnErrorCode
Error code.
Definition pgnreader-error.h:35
@ BAD_CHARACTER
Unexpected character in PGN input (tokenizer error)
@ BAD_PGN_TAG
PGN tag parsing failed (parser error)
@ UNEXPECTED_MOVE_NUM
Unexpected (bad) move number (PGN reader error)
@ AMBIGUOUS_MOVE
Ambiguous move (missing source file/rank specifiers)
@ UNEXPECTED_TOKEN
Unexpected (bad) token (parser error)
@ UNIMPLEMENTED
Unimplemented functionality.
@ BAD_FEN
Bad or illegal FEN (position setup error)
@ OK
Code for success. Never set in PgnError by this code base.
Definition chessboard-types-squareset.h:30