21 #ifndef SCID_INDEXENTRY_H 22 #define SCID_INDEXENTRY_H 30 #define MAX_GAME_LENGTH 131072 55 uint64_t offset_ : 46;
56 uint64_t gameDataSize_ : 18;
58 uint64_t storedLineCode_ : 8;
59 uint64_t whiteID_ : 28;
60 uint64_t blackID_ : 28;
62 uint32_t eventID_ : 28;
63 uint32_t whiteEloType_ : 4;
65 uint32_t siteID_ : 28;
66 uint32_t blackEloType_ : 4;
68 uint32_t roundID_ : 28;
71 uint32_t whiteElo_ : 12;
74 uint32_t blackElo_ : 12;
75 uint32_t eventDate_ : 20;
77 uint32_t numHalfMoves_ : 10;
80 uint32_t finalMatSig_ : 24;
81 uint32_t nVariations_ : 4;
82 uint32_t nComments_ : 4;
97 uint32_t
GetLength()
const {
return gameDataSize_; }
117 bool GetFlag(uint32_t mask)
const {
return (flags_ & mask) == mask; }
127 gameDataSize_ = length;
183 ASSERT(x == nVariations_);
301 if (x <= 10) {
return x; }
302 if (x <= 12) {
return 10; }
303 if (x <= 17) {
return 11; }
304 if (x <= 24) {
return 12; }
305 if (x <= 34) {
return 13; }
306 if (x <= 44) {
return 14; }
310 static uint countCodes[16] = {0,1,2,3,4,5,6,7,8,9,10,15,20,30,40,50};
311 return countCodes[x & 15];
326 auto WriteOneByte = [&buf_it](uint8_t v) { *buf_it++ = v; };
327 auto WriteTwoBytes = [&WriteOneByte](uint16_t v) {
328 WriteOneByte(static_cast<uint8_t>(v >> 8));
329 WriteOneByte(static_cast<uint8_t>(v));
331 auto WriteFourBytes = [&WriteTwoBytes](uint32_t v) {
332 WriteTwoBytes(static_cast<uint16_t>(v >> 16));
333 WriteTwoBytes(static_cast<uint16_t>(v));
339 WriteFourBytes(static_cast<uint32_t>(ie->
GetOffset()));
342 WriteTwoBytes(static_cast<uint16_t>(ie->
GetLength()));
343 uint8_t len_flags =
static_cast<uint8_t
>(ie->
GetLength() >> 9) & 0x80;
344 len_flags |=
static_cast<uint8_t
>(ie->flags_ >> 16) & 0x3F;
345 WriteOneByte(len_flags);
346 WriteTwoBytes(static_cast<uint16_t>(ie->flags_));
356 uint32_t WhiteID_Low = ie->
GetWhite();
357 uint32_t BlackID_Low = ie->
GetBlack();
358 uint32_t WhiteBlack_High = (WhiteID_Low & 0x0F0000) >> 12;
359 WhiteBlack_High |= (BlackID_Low & 0x0F0000) >> 16;
360 WriteOneByte(static_cast<uint8_t>(WhiteBlack_High));
361 WriteTwoBytes(static_cast<uint16_t>(WhiteID_Low));
362 WriteTwoBytes(static_cast<uint16_t>(BlackID_Low));
366 uint32_t EventID_Low = ie->
GetEvent();
367 uint32_t SiteID_Low = ie->
GetSite();
368 uint32_t RoundID_Low = ie->
GetRound();
369 uint32_t EventSiteRnd_High = (EventID_Low & 0x070000) >> 11;
370 EventSiteRnd_High |= (SiteID_Low & 0x070000) >> 14;
371 EventSiteRnd_High |= (RoundID_Low & 0x030000) >> 16;
372 WriteOneByte(static_cast<uint8_t>(EventSiteRnd_High));
373 WriteTwoBytes(static_cast<uint16_t>(EventID_Low));
374 WriteTwoBytes(static_cast<uint16_t>(SiteID_Low));
375 WriteTwoBytes(static_cast<uint16_t>(RoundID_Low));
377 uint16_t varCounts = ie->nVariations_ & 0x0F;
378 varCounts |=
static_cast<uint16_t
>(ie->nComments_ & 0x0F) << 4;
379 varCounts |=
static_cast<uint16_t
>(ie->nNags_ & 0x0F) << 8;
380 varCounts |=
static_cast<uint16_t
>(ie->
GetResult() & 0x0F) << 12;
381 WriteTwoBytes(varCounts);
391 if ((eyear + 3) < dyear || eyear > (dyear + 3)) {
394 eyear = (eyear + 4 - dyear) & 7;
397 WriteFourBytes((edate << 20) | date);
411 WriteFourBytes(FinalMatSig);
416 ASSERT(nMoves < (1ULL << 10));
417 WriteOneByte(static_cast<uint8_t>(nMoves));
418 uint8_t pawnData0 =
static_cast<uint8_t
>(nMoves >> 8) << 6;
422 pawnData0 |= *pb & 0x3F;
423 WriteOneByte(pawnData0);
436 int rating =
static_cast<int>(welo + belo) / 140;
454 if (moves < 40) rating -= 2;
459 if (rating < 0)
return 0;
460 else return static_cast<byte> (rating);
470 switch (toupper(ch)) {
499 switch (toupper(flag)) {
533 if (flags == 0)
return 0;
536 while (*flags != 0) {
550 if (flags == NULL) { flags =
"DWBMENPTKQ!?U123456"; }
552 while (*flags != 0) {
void SetNumHalfMoves(ushort b)
void SetBlack(idNumberT id)
uint date_GetYear(dateT date)
void SetCommentCount(unsigned x)
static const uint32_t IDX_MASK_ALLFLAGS
bool GetStartFlag() const
const uint INDEX_ENTRY_SIZE
const char * GetBlackName(const NameBase *nb) const
const byte * GetHomePawnData() const
resultT GetResult() const
static uint32_t StrToFlagMask(const char *flags)
void SetDeleteFlag(bool b)
idNumberT GetSite() const
const errorT ERROR_FileWrite
void SetBlackRatingType(byte b)
const char * GetWhiteName(const NameBase *nb) const
const char * GetEventName(const NameBase *nb) const
void SetStartFlag(bool b)
idNumberT GetEvent() const
void SetWhite(idNumberT id)
void SetUnderPromoFlag(bool b)
void SetRound(idNumberT id)
static uint CharToFlag(char ch)
matSigT GetFinalMatSig() const
uint16_t GetNumHalfMoves() const
const char * GetName(nameT nt, idNumberT id) const
Retrieve a name.
void SetNagCount(unsigned x)
void SetStoredLineCode(byte b)
void SetEcoCode(ecoT eco)
const resultT RESULT_Draw
static uint32_t CharToFlagMask(char flag)
const byte CUSTOM_FLAG_MASK[]
bool GetFlag(uint32_t mask) const
This class stores the database's names (players, events, sites and rounds).
uint GetFlagStr(char *dest, const char *flags) const
void SetRawNagCount(unsigned x)
void SetRawCommentCount(unsigned x)
idNumberT GetRound() const
idNumberT GetWhite() const
void SetSite(idNumberT id)
bool GetDeleteFlag() const
void SetLength(size_t length)
void SetVariationCount(unsigned x)
eloT GetWhiteElo(const NameBase *nb) const
byte GetStoredLineCode() const
errorT Write(T *file, versionT version) const
uint GetCommentCount() const
byte GetRating(const NameBase *nb) const
byte GetWhiteRatingType() const
void SetEventDate(dateT edate)
idNumberT GetBlack() const
const errorT ERROR_FileVersion
void SetPromotionsFlag(bool b)
eloT GetElo(idNumberT id) const
void SetWhiteElo(eloT elo)
bool GetVariationsFlag() const
void SetFinalMatSig(matSigT ms)
void SetResult(resultT res)
const char * GetSiteName(const NameBase *nb) const
bool GetCommentsFlag() const
void SetPlayer(colorT col, idNumberT id)
void SetEvent(idNumberT id)
void SetFlag(uint32_t flagMask, bool set)
uint32_t GetLength() const
bool GetUnderPromoFlag() const
void SetBlackElo(eloT elo)
const uint OLD_INDEX_ENTRY_SIZE
byte GetBlackRatingType() const
uint64_t GetOffset() const
eloT GetBlackElo(const NameBase *nb) const
const char * GetRoundName(const NameBase *nb) const
void SetWhiteRatingType(byte b)
void SetOffset(uint64_t offset)
uint date_GetMonth(dateT date)
void SetRawVariationCount(unsigned x)
bool GetPromotionsFlag() const
uint GetVariationCount() const
dateT GetEventDate() const
uint date_GetDay(dateT date)