52 uint64_t offset_ : 46;
53 uint64_t gameDataSize_ : 18;
55 uint32_t nComments_ : 4;
56 uint32_t whiteID_ : 28;
58 uint32_t nVariations_ : 4;
59 uint32_t blackID_ : 28;
62 uint32_t eventID_ : 28;
66 uint32_t variant_ : 1;
67 uint32_t roundID_ : 31;
69 uint32_t whiteElo_ : 12;
72 uint32_t blackElo_ : 12;
73 uint32_t eventDate_ : 20;
75 uint32_t numHalfMoves_ : 10;
79 uint32_t whiteEloType_ : 3;
80 uint32_t blackEloType_ : 3;
81 uint32_t finalMatSig_ : 24;
85 uint8_t storedLineCode_;
87 scid::core::byte HomePawnData [HPSIG_SIZE];
90 uint64_t GetOffset()
const {
return offset_; }
91 uint32_t GetLength()
const {
return gameDataSize_; }
92 idNumberT GetWhite()
const {
return whiteID_; }
93 scid::core::ratingT GetWhiteElo()
const {
return whiteElo_; }
94 scid::core::ratingTypeT GetWhiteRatingType()
const {
return whiteEloType_; }
95 idNumberT GetBlack()
const {
return blackID_; }
96 scid::core::ratingT GetBlackElo()
const {
return blackElo_; }
97 scid::core::ratingTypeT GetBlackRatingType()
const {
return blackEloType_; }
98 idNumberT GetEvent()
const {
return eventID_; }
99 idNumberT GetSite()
const {
return siteID_; }
100 idNumberT GetRound()
const {
return roundID_; }
101 scid::core::dateT GetDate()
const {
return date_; }
102 scid::core::dateT GetEventDate()
const {
return eventDate_; }
103 scid::core::resultT GetResult()
const {
return result_; }
104 scid::core::uint GetVariationCount()
const {
return DecodeCount(nVariations_); }
105 scid::core::uint GetCommentCount()
const {
return DecodeCount(nComments_); }
106 scid::core::uint GetNagCount()
const {
return DecodeCount(nNags_); }
107 uint16_t GetNumHalfMoves()
const {
return numHalfMoves_; }
108 matSigT GetFinalMatSig()
const {
return finalMatSig_; }
109 scid::core::byte GetStoredLineCode()
const {
return storedLineCode_; }
110 EcoCode GetEcoCode()
const {
return ECOcode_; }
111 bool GetFlag(uint32_t mask)
const {
return (flags_ & mask) == mask; }
112 uint32_t GetRawFlags()
const {
return flags_; }
113 uint16_t GetRaw4bitsCounts()
const {
114 uint16_t res = nVariations_ & 0x0F;
115 res |=
static_cast<uint16_t
>(nComments_ & 0x0F) << 4;
116 res |=
static_cast<uint16_t
>(nNags_ & 0x0F) << 8;
120 void setChessStd() { variant_ = 0; }
121 void setChess960() { variant_ = 1; }
122 bool isChessStd()
const {
return variant_ == 0; }
124 const scid::core::byte* GetHomePawnData()
const {
return HomePawnData; }
125 void SetHomePawnData(scid::core::byte hpCount,
const scid::core::byte hpVal[8]) {
126 HomePawnData[0] = hpCount;
127 std::copy_n(hpVal, 8, HomePawnData + 1);
131 void SetOffset(uint64_t offset) {
133 ASSERT(GetOffset() == offset);
135 void SetLength(
size_t length) {
136 gameDataSize_ = length;
137 ASSERT(GetLength() == length);
139 void SetWhite(idNumberT
id) {
141 ASSERT(GetWhite() ==
id);
143 void SetWhiteElo(scid::core::ratingT elo) {
145 ASSERT(GetWhiteElo() == elo);
147 void SetWhiteRatingType(scid::core::ratingTypeT b) {
149 ASSERT(GetWhiteRatingType() == b);
151 void SetBlack(idNumberT
id) {
153 ASSERT(GetBlack() ==
id);
155 void SetBlackElo(scid::core::ratingT elo) {
157 ASSERT(GetBlackElo() == elo);
159 void SetBlackRatingType(scid::core::ratingTypeT b) {
161 ASSERT(GetBlackRatingType() == b);
163 void SetEvent(idNumberT
id) {
165 ASSERT(GetEvent() ==
id);
167 void SetSite(idNumberT
id) {
169 ASSERT(GetSite() ==
id);
171 void SetRound(idNumberT
id) {
173 ASSERT(GetRound() ==
id);
175 void SetDate(scid::core::dateT date) {
177 ASSERT(GetDate() == date);
179 void SetEventDate(scid::core::dateT edate) {
181 ASSERT(GetEventDate() == edate);
183 void SetResult(scid::core::resultT res) {
185 ASSERT(GetResult() == res);
187 void SetVariationCount(
unsigned x) { nVariations_ = EncodeCount(x); }
188 void SetCommentCount(
unsigned x) { nComments_ = EncodeCount(x); }
189 void SetNagCount(
unsigned x) { nNags_ = EncodeCount(x); }
190 void SetRawVariationCount(
unsigned x) {
192 ASSERT(x == nVariations_);
194 void SetRawCommentCount(
unsigned x) {
196 ASSERT(x == nComments_);
198 void SetRawNagCount(
unsigned x) {
202 void SetNumHalfMoves(scid::core::ushort b) {
204 ASSERT(GetNumHalfMoves() == b);
206 void SetFinalMatSig(matSigT ms) {
208 ASSERT(GetFinalMatSig() == ms);
210 void SetStoredLineCode(scid::core::byte b) {
212 ASSERT(GetStoredLineCode() == b);
214 void SetEcoCode(EcoCode eco) {
216 ASSERT(GetEcoCode() == eco);
218 void SetFlag(uint32_t flagMask,
bool set) {
226 scid::core::uint GetYear ()
const {
return scid::core::date_GetYear (GetDate()); }
227 scid::core::uint GetMonth()
const {
return scid::core::date_GetMonth (GetDate()); }
228 scid::core::uint GetDay ()
const {
return scid::core::date_GetDay (GetDate()); }
230 void SetPlayer(scid::core::colorT col, idNumberT
id) {
231 return (col == scid::core::BLACK) ? SetBlack(
id) : SetWhite(
id);
234 scid::core::byte GetRating()
const;
236 bool GetStartFlag ()
const {
return GetFlag(1 << IDX_FLAG_START); }
237 bool GetPromotionsFlag ()
const {
return GetFlag(1 << IDX_FLAG_PROMO); }
238 bool GetUnderPromoFlag()
const {
return GetFlag(1 << IDX_FLAG_UPROMO); }
239 bool GetCommentsFlag ()
const {
return (GetCommentCount() > 0); }
240 bool GetVariationsFlag ()
const {
return (GetVariationCount() > 0); }
241 bool GetNagsFlag ()
const {
return (GetNagCount() > 0); }
242 bool GetDeleteFlag ()
const {
return GetFlag(1 << IDX_FLAG_DELETE); }
244 static scid::core::uint CharToFlag (
char ch);
245 static uint32_t CharToFlagMask (
char flag);
246 static uint32_t StrToFlagMask (
const char* flags);
247 scid::core::uint GetFlagStr(
char* dest,
const char* flags)
const;
249 void SetStartFlag (
bool b) { SetFlag(1 << IDX_FLAG_START, b); }
250 void SetPromotionsFlag (
bool b) { SetFlag(1 << IDX_FLAG_PROMO, b); }
251 void SetUnderPromoFlag (
bool b) { SetFlag(1 << IDX_FLAG_UPROMO, b); }
252 void SetDeleteFlag (
bool b) { SetFlag(1 << IDX_FLAG_DELETE, b); }
253 void clearFlags() {
return SetFlag(IDX_MASK_ALLFLAGS,
false); }
256 static_assert(std::has_unique_object_representations_v<IndexEntry>);
257 return memcmp(
this, &ie,
sizeof(
IndexEntry)) == 0;
266 IDX_FLAG_WHITE_OP = 4,
267 IDX_FLAG_BLACK_OP = 5,
268 IDX_FLAG_MIDDLEGAME = 6,
269 IDX_FLAG_ENDGAME = 7,
270 IDX_FLAG_NOVELTY = 8,
272 IDX_FLAG_TACTICS = 10,
275 IDX_FLAG_BRILLIANCY = 13,
276 IDX_FLAG_BLUNDER = 14,
278 IDX_FLAG_CUSTOM1 = 16,
279 IDX_FLAG_CUSTOM2 = 17,
280 IDX_FLAG_CUSTOM3 = 18,
281 IDX_FLAG_CUSTOM4 = 19,
282 IDX_FLAG_CUSTOM5 = 20,
283 IDX_FLAG_CUSTOM6 = 21,
286 static const uint32_t IDX_MASK_ALLFLAGS = 0xFFFFFFFF;
289 static scid::core::uint EncodeCount (scid::core::uint x) {
290 if (x <= 10) {
return x; }
291 if (x <= 12) {
return 10; }
292 if (x <= 17) {
return 11; }
293 if (x <= 24) {
return 12; }
294 if (x <= 34) {
return 13; }
295 if (x <= 44) {
return 14; }
298 static scid::core::uint DecodeCount (scid::core::uint x) {
299 static scid::core::uint countCodes[16] = {0,1,2,3,4,5,6,7,8,9,10,15,20,30,40,50};
300 return countCodes[x & 15];