HooverChessUtils_PgnReader 0.9.0
Loading...
Searching...
No Matches
pgnreader-priv.h
Go to the documentation of this file.
1// Hoover Chess Utilities / PGN reader
2// Copyright (C) 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_PRIV_H_INCLUDED
18#define HOOVER_CHESS_UTILS__PGN_READER__PGNREADER_PRIV_H_INCLUDED
19
20#include "pgnreader.h"
21
22#include <cstdint>
23
25{
26
29
33template <PgnReaderActionClass... args>
35{
36public:
37 static constexpr std::uint32_t actionBit(PgnReaderActionClass action) noexcept
38 {
39 const unsigned int shift { static_cast<unsigned int>(action) };
40 if (shift < 32U) [[likely]]
41 {
42 return UINT32_C(1) << shift;
43 }
44 else [[unlikely]]
45 {
46 return 0U;
47 }
48 }
49
50 static constexpr std::uint32_t actionsToBitmask() noexcept
51 {
52 return 0U;
53 }
54
55 template <typename... Args>
56 static constexpr std::uint32_t actionsToBitmask(PgnReaderActionClass action, Args... rest) noexcept
57 {
58 return actionBit(action) | actionsToBitmask(rest...);
59 }
60
61private:
62 static constexpr std::uint32_t s_filterBits { actionsToBitmask(args...) };
63
64public:
69 static constexpr inline bool isEnabled(PgnReaderActionClass action) noexcept
70 {
71 return (s_filterBits & actionBit(action)) != 0U;
72 }
73
78 static constexpr inline std::uint32_t getBitMask() noexcept
79 {
80 return s_filterBits;
81 }
82};
83
85
86}
87
88#endif
PGN reader action filter (compile-time)
Definition pgnreader-priv.h:35
static constexpr std::uint32_t s_filterBits
Definition pgnreader-priv.h:62
static constexpr std::uint32_t actionsToBitmask(PgnReaderActionClass action, Args... rest) noexcept
Definition pgnreader-priv.h:56
static constexpr bool isEnabled(PgnReaderActionClass action) noexcept
Returns whether an action class is enabled.
Definition pgnreader-priv.h:69
static constexpr std::uint32_t actionsToBitmask() noexcept
Definition pgnreader-priv.h:50
static constexpr std::uint32_t actionBit(PgnReaderActionClass action) noexcept
Definition pgnreader-priv.h:37
static constexpr std::uint32_t getBitMask() noexcept
Returns a bit mask of enabled action classes. When bit N is set, action class with numeric value N is...
Definition pgnreader-priv.h:78
PgnReaderActionClass
PGN reader filterable action classes.
Definition pgnreader.h:219
Definition chessboard-types-squareset.h:30