Scid  4.7.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
codec_scid4.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Fulvio Benini
3 
4  * This file is part of Scid (Shane's Chess Information Database).
5  *
6  * Scid is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation.
9  *
10  * Scid is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with Scid. If not, see <http://www.gnu.org/licenses/>.
17  *
18  */
19 
20 /** @file
21  * Implements the CodecSCID4 class, which manages the databases encoded
22  * in Scid format version 4.
23  */
24 
25 #include "codec_scid4.h"
26 #include <algorithm>
27 
28 namespace {
29 
30 /**
31  * A NameBase file starts with an header containing:
32  * - header_magic (8 bytes): identify the file format
33  * - unused (4 bytes): obsolete timeStamp
34  * - number of NAME_PLAYER names stored in the file (3 bytes)
35  * - number of NAME_EVENT names stored in the file (3 bytes)
36  * - number of NAME_SITE names stored in the file (3 bytes)
37  * - number of NAME_ROUND names stored in the file (3 bytes)
38  * - unused (12 bytes): obsolete max frequency
39  * Names are stored in alphabetical order using front-coding and each record is
40  * composed by:
41  * - name_id (2-3 bytes): the idx (idNumberT) stored in the Index (.si4) file
42  * - unused (1-3 bytes): obsolete frequency
43  * - length (1 byte): the total number of bytes of the name (max 255)
44  * - prefix (1 byte): the number of bytes in common with the previous name
45  * - name (0-255 bytes): the part of the name that differs from the previous
46  * one.
47  */
48 const char* NAMEBASE_MAGIC = "Scid.sn";
49 
50 /**
51  * Read a SCIDv4 NameBase file into memory.
52  * @param filename: the full path of the file to open.
53  * @param fMode: a valid file mode.
54  * @param nb: reference to the object where the names will be stored.
55  * @returns OK if successful or an error code.
56  */
57 errorT namefileRead(const char* filename, fileModeT fmode, NameBase& nb) {
58  auto nb_data = nb.getData();
59  auto& map = std::get<0>(nb_data);
60  auto& names = std::get<1>(nb_data);
61  auto& eloV = std::get<2>(nb_data);
62 
63  Filebuf file;
64  if (file.Open(filename, fmode) != OK)
65  return ERROR_FileOpen;
66 
67  char Header_magic[9] = {0}; // magic identifier must be "Scid.sn"
68  file.sgetn(Header_magic, 8);
69  if (strcmp(Header_magic, NAMEBASE_MAGIC) != 0)
70  return ERROR_BadMagic;
71 
72  // *** Compatibility ***
73  // Even if timeStamp is not used we still need to read the bytes
74  file.ReadFourBytes();
75  // ***
76 
77  idNumberT Header_numNames[NUM_NAME_TYPES];
78  Header_numNames[NAME_PLAYER] = file.ReadThreeBytes();
79  Header_numNames[NAME_EVENT] = file.ReadThreeBytes();
80  Header_numNames[NAME_SITE] = file.ReadThreeBytes();
81  Header_numNames[NAME_ROUND] = file.ReadThreeBytes();
82 
83  // *** Compatibility ***
84  // Even if frequency is no longer used we still need to read the bytes
85  uint obsolete_maxFreq[NUM_NAME_TYPES];
86  obsolete_maxFreq[NAME_PLAYER] = file.ReadThreeBytes();
87  obsolete_maxFreq[NAME_EVENT] = file.ReadThreeBytes();
88  obsolete_maxFreq[NAME_SITE] = file.ReadThreeBytes();
89  obsolete_maxFreq[NAME_ROUND] = file.ReadThreeBytes();
90  // ***
91 
92  eloV.resize(Header_numNames[NAME_PLAYER], 0);
94  names[nt].resize(Header_numNames[nt]);
95  idNumberT id;
96  std::string prevName;
97  for (idNumberT i = 0; i < Header_numNames[nt]; i++) {
98  if (Header_numNames[nt] >= 65536) {
99  id = file.ReadThreeBytes();
100  } else {
101  id = file.ReadTwoBytes();
102  }
103 
104  // *** Compatibility ***
105  // Even if frequency is no longer used we still need to read the
106  // bytes Frequencies can be stored in 1, 2 or 3 bytes:
107  if (obsolete_maxFreq[nt] >= 65536) {
108  file.ReadThreeBytes();
109  } else if (obsolete_maxFreq[nt] >= 256) {
110  file.ReadTwoBytes();
111  } else { // Frequencies all <= 255: fit in one byte
112  file.ReadOneByte();
113  }
114  // ***
115 
116  // Read the name string.
117  // All strings EXCEPT the first are front-coded.
118  int length = file.ReadOneByte();
119  int prefix = (i > 0) ? file.ReadOneByte() : 0;
120  if (prefix > length)
121  return ERROR_Corrupt;
122 
123  char* name = new char[length + 1];
124  std::copy_n(prevName.c_str(), prefix, name);
125  std::streamsize extra_chars = length - prefix;
126  if (extra_chars != file.sgetn(name + prefix, extra_chars)) {
127  delete[] name;
128  return ERROR_FileRead;
129  }
130  name[length] = 0;
131  prevName.assign(name, length);
132 
133  if (id < Header_numNames[nt] && names[nt][id] == 0) {
134  names[nt][id].reset(name);
135  map[nt].insert(map[nt].end(), std::make_pair(name, id));
136  } else {
137  delete[] name;
138  return ERROR_Corrupt;
139  }
140  }
141 
142  if (map[nt].size() != names[nt].size())
143  return ERROR_Corrupt;
144  }
145 
146  return OK;
147 }
148 
149 bool assert_sorted(const char* str1, const char* str2) {
150  // *** Compatibility ***
151  // Older code used a custom StrTree class with a peculiar sorting:
152  // - the first char was interpreted as an unsigned char;
153  // - the remaining part was compared with the function
154  // strComapare(),
155  // which converts the chars to ints, and is not consistent with
156  // the standard function strcmp().
157  // The old StrTree class did also have unpredictable behaviors when
158  // fed with names not sorted according to that criteria, for example
159  // it could create Namebase objects with duplicate entries.
160  // ***
161  if (*str1 == *str2)
162  return strCompare(str1, str2) < 0;
163 
164  return static_cast<uint>(*str1) < static_cast<uint>(*str2);
165 }
166 
167 /**
168  * Write a SCIDv4 NameBase file.
169  * @param filename: the full path of the file to open.
170  * @param nb: reference to the object where the names will be stored.
171  * @returns OK if successful or an error code.
172  */
173 template <typename TCont, typename TFreq>
174 errorT namefileWrite(const char* filename, const TCont& names_ids,
175  const TFreq& freq) {
176  Filebuf file;
177  if (file.Open(filename, FMODE_WriteOnly) != OK)
178  return ERROR_FileOpen;
179 
180  file.sputn(NAMEBASE_MAGIC, 8);
181 
182  // *** Compatibility ***
183  // Even if timeStamp is not used we still need to write these bytes
184  file.WriteFourBytes(0);
185  // ***
186 
187  ASSERT(1ULL << 24 > names_ids[NAME_PLAYER].size());
188  ASSERT(1ULL << 24 > names_ids[NAME_EVENT].size());
189  ASSERT(1ULL << 24 > names_ids[NAME_SITE].size());
190  ASSERT(1ULL << 24 > names_ids[NAME_ROUND].size());
191  file.WriteThreeBytes((uint32_t)names_ids[NAME_PLAYER].size());
192  file.WriteThreeBytes((uint32_t)names_ids[NAME_EVENT].size());
193  file.WriteThreeBytes((uint32_t)names_ids[NAME_SITE].size());
194  file.WriteThreeBytes((uint32_t)names_ids[NAME_ROUND].size());
195 
196  // *** Compatibility ***
197  // even if maxFrequency is no longer used we still need to write these bytes
198  unsigned maxFreq[NUM_NAME_TYPES] = {0};
200  auto it = std::max_element(freq[nt].begin(), freq[nt].end());
201  maxFreq[nt] = (it == freq[nt].end()) ? 0 : *it;
202  file.WriteThreeBytes(maxFreq[nt]);
203  }
204  // ***
205 
207  const char* prevName = nullptr;
208  size_t numNames = names_ids[nt].size();
209  for (const auto& it : names_ids[nt]) {
210  const char* name = it.first;
211  idNumberT id = it.second;
212 
213  ASSERT(prevName == nullptr || assert_sorted(prevName, name));
214 
215  // write idNumber in 2 bytes if possible, otherwise 3.
216  if (numNames >= 65536) {
217  file.WriteThreeBytes(id);
218  } else {
219  file.WriteTwoBytes(id);
220  }
221 
222  // *** Compatibility ***
223  // write these bytes even if they are not used anymore
224  if (maxFreq[nt] >= 65536) {
225  file.WriteThreeBytes(freq[nt][id]);
226  } else if (maxFreq[nt] >= 256) {
227  file.WriteTwoBytes(freq[nt][id]);
228  } else {
229  file.WriteOneByte(static_cast<byte>(freq[nt][id]));
230  }
231  // ***
232 
233  ASSERT(strlen(name) < 256);
234  byte length = static_cast<byte>(strlen(name));
235  file.WriteOneByte(length);
236  byte prefix = 0;
237  if (prevName) {
238  prefix = (byte)strPrefix(name, prevName);
239  file.WriteOneByte(prefix);
240  }
241  file.sputn(name + prefix, (length - prefix));
242  prevName = name;
243  }
244  }
245  return OK;
246 }
247 
248 } // namespace
249 
250 /**
251  * Decode SCID4 (or SCID3) data into an IndexEntry object.
252  * @param buf_it: pointer to the buffer containing the data
253  * (should contain INDEX_ENTRY_SIZE chars)
254  * @param version: 400 for SCID4 or 300 for SCID3.
255  * @param ie: pointer to the IndexEntry object where the data will be
256  * stored.
257  */
258 void decodeIndexEntry(const char* buf_it, versionT version, IndexEntry* ie) {
259  auto ReadOneByte = [&buf_it]() {
260  uint8_t res = *buf_it++;
261  return res;
262  };
263  auto ReadTwoBytes = [&ReadOneByte]() {
264  uint16_t high = ReadOneByte();
265  uint16_t res = (high << 8) | ReadOneByte();
266  return res;
267  };
268  auto ReadFourBytes = [&ReadTwoBytes]() {
269  uint32_t high = ReadTwoBytes();
270  uint32_t res = (high << 16) | ReadTwoBytes();
271  return res;
272  };
273 
274  // Offset of the gamefile record (32 bits).
275  ie->SetOffset(ReadFourBytes());
276 
277  // Length of gamefile record for this game: 17 bits are used so the max
278  // length is 128 ko (131071).
279  // Lower bits of the extra byte are used for custom flags: LxFFFFFF ( L =
280  // length for long games, x = spare, F = custom flags)
281  uint32_t len_Low = ReadTwoBytes();
282  uint32_t len_flags = (version < 400) ? 0 : ReadOneByte();
283  ie->SetLength(((len_flags & 0x80) << 9) | len_Low);
284  uint32_t Flags = ReadTwoBytes();
285  ie->clearFlags();
286  ie->SetFlag(((len_flags & 0x3F) << 16) | Flags, true);
287 
288  // WhiteID and BlackID are 20-bit values, EventID and SiteID are
289  // 19-bit values, and RoundID is an 18-bit value.
290  // WhiteID high 4 bits = bits 4-7 of WhiteBlack_High.
291  // BlackID high 4 bits = bits 0-3 of WhiteBlack_High.
292  // EventID high 3 bits = bits 5-7 of EventSiteRnd_high.
293  // SiteID high 3 bits = bits 2-4 of EventSiteRnd_high.
294  // RoundID high 2 bits = bits 0-1 of EventSiteRnd_high.
295  uint32_t WhiteBlack_High = ReadOneByte();
296  uint32_t WhiteID_Low = ReadTwoBytes();
297  ie->SetWhite(((WhiteBlack_High & 0xF0) << 12) | WhiteID_Low);
298  uint32_t BlackID_Low = ReadTwoBytes();
299  ie->SetBlack(((WhiteBlack_High & 0x0F) << 16) | BlackID_Low);
300  uint32_t EventSiteRnd_High = ReadOneByte();
301  uint32_t EventID_Low = ReadTwoBytes();
302  ie->SetEvent(((EventSiteRnd_High & 0xE0) << 11) | EventID_Low);
303  uint32_t SiteID_Low = ReadTwoBytes();
304  ie->SetSite(((EventSiteRnd_High & 0x1C) << 14) | SiteID_Low);
305  uint32_t RoundID_Low = ReadTwoBytes();
306  ie->SetRound(((EventSiteRnd_High & 0x03) << 16) | RoundID_Low);
307 
308  // Counters for comments, variations, etc. (4 bits each)
309  // VarCounts also stores the result (4 bits).
310  uint32_t varCounts = ReadTwoBytes();
311  ie->SetRawVariationCount(varCounts & 0x0F);
312  ie->SetRawCommentCount((varCounts >> 4) & 0x0F);
313  ie->SetRawNagCount((varCounts >> 8) & 0x0F);
314  ie->SetResult((varCounts >> 12) & 0x0F);
315 
316  // ECO code (16 bits)
317  ie->SetEcoCode(ReadTwoBytes());
318 
319  // Date and EventDate are stored in four bytes.
320  // Due to a compact encoding format, the EventDate
321  // must be within a few years of the Date.
322  uint32_t date_edate = ReadFourBytes();
323  uint32_t date = date_edate & 0xFFFFF;
324  ie->SetDate(date);
325  uint32_t edate = date_edate >> 20;
326  uint32_t eyear = date_GetYear(edate) & 0x07;
327  if (eyear == 0) {
328  edate = ZERO_DATE;
329  } else {
330  eyear += date_GetYear(date);
331  eyear = (eyear < 4) ? 0 : eyear - 4;
332  edate = DATE_MAKE(eyear, date_GetMonth(edate), date_GetDay(edate));
333  }
334  ie->SetEventDate(edate);
335 
336  // The two ELO ratings and rating types take 2 bytes each.
337  uint16_t whiteElo = ReadTwoBytes();
338  ie->SetWhiteElo(whiteElo & 0xFFF);
339  ie->SetWhiteRatingType(whiteElo >> 12);
340  uint16_t blackElo = ReadTwoBytes();
341  ie->SetBlackElo(blackElo & 0xFFF);
342  ie->SetBlackRatingType(blackElo >> 12);
343 
344  // material of the final position in the game,
345  // and the StoredLineCode in the top 8 bits.
346  uint32_t finalMatSig = ReadFourBytes();
347  ie->SetFinalMatSig(finalMatSig & 0xFFFFFF);
348  ie->SetStoredLineCode(finalMatSig >> 24);
349 
350  // Read the 9-byte homePawnData array:
351  // The first byte of HomePawnData has high bits of the NumHalfMoves
352  // counter in its top two bits:
353  uint16_t NumHalfMoves = ReadOneByte();
354  uint16_t pawnData0 = ReadOneByte();
355  ie->SetNumHalfMoves(((pawnData0 & 0xC0) << 2) | NumHalfMoves);
356  byte* pb = ie->GetHomePawnData();
357  *pb++ = pawnData0 & 0x3F;
358  std::copy_n(buf_it, HPSIG_SIZE - 1, pb);
359 }
360 
361 errorT CodecSCID4::dyn_open(fileModeT fMode, const char* filename,
362  const Progress& progress, Index* idx,
363  NameBase* nb) {
364  if (filename == nullptr || idx == nullptr || nb == nullptr)
365  return ERROR;
366  if (*filename == '\0')
367  return ERROR_FileOpen;
368 
369  idx_ = idx;
370  nb_ = nb;
371  filenames_.resize(3);
372  filenames_[0] = std::string(filename) + ".si4";
373  filenames_[1] = std::string(filename) + ".sn4";
374  filenames_[2] = std::string(filename) + ".sg4";
375 
376  errorT err = gfile_.open(filenames_[2], fMode);
377  if (err != OK)
378  return err;
379 
380  if (fMode == FMODE_Create) {
381  err = idx->Create(filename);
382  if (err == OK) {
383  err = namefileWrite(filenames_[1].c_str(), nb_->getNames(),
384  idx_->calcNameFreq(*nb_));
385  }
386  } else {
387  err = idx->Open(filename, fMode);
388  if (err == OK)
389  err = namefileRead(filenames_[1].c_str(), fMode, *nb_);
390  if (err == OK)
391  err = readIndex(progress);
392  }
393 
394  return err;
395 }
396 
398  errorT err = idx_->flush();
399  if (err == OK) {
400  // *** Compatibility ***
401  // Even if name's frequency is no longer used, it's necessary to
402  // keep the compatibility with older Scid versions, forcing a
403  // recalculation.
404  err = namefileWrite(filenames_[1].c_str(), nb_->getNames(),
405  idx_->calcNameFreq(*nb_));
406  }
407  errorT errGfile = (gfile_.pubsync() == 0) ? OK : ERROR_FileWrite;
408 
409  return (err == OK) ? errGfile : err;
410 }
411 
412 /**
413  * Reads the entire index file into memory.
414  * Invalid name IDs are replaced with "?" if possible.
415  * @param progress: a Progress object used for GUI communications.
416  * @returns OK if successful or an error code.
417  */
418 inline errorT CodecSCID4::readIndex(const Progress& progress) {
419  gamenumT nUnknowIDs = 0;
420  idNumberT maxID[NUM_NAME_TYPES];
421  for (nameT nt = NAME_PLAYER; nt < NUM_NAME_TYPES; nt++) {
422  maxID[nt] = nb_->GetNumNames(nt);
423  }
424  auto validateNameIDs = [&](IndexEntry* ie) {
425  if (ie->GetWhite() >= maxID[NAME_PLAYER]) {
426  auto unknown = dyn_addName(NAME_PLAYER, "?");
427  if (unknown.first != OK)
428  return false;
429  ie->SetWhite(unknown.second);
430  ++nUnknowIDs;
431  }
432  if (ie->GetBlack() >= maxID[NAME_PLAYER]) {
433  auto unknown = dyn_addName(NAME_PLAYER, "?");
434  if (unknown.first != OK)
435  return false;
436  ie->SetBlack(unknown.second);
437  ++nUnknowIDs;
438  }
439  if (ie->GetEvent() >= maxID[NAME_EVENT]) {
440  auto unknown = dyn_addName(NAME_EVENT, "?");
441  if (unknown.first != OK)
442  return false;
443  ie->SetEvent(unknown.second);
444  ++nUnknowIDs;
445  }
446  if (ie->GetSite() >= maxID[NAME_SITE]) {
447  auto unknown = dyn_addName(NAME_SITE, "?");
448  if (unknown.first != OK)
449  return false;
450  ie->SetSite(unknown.second);
451  ++nUnknowIDs;
452  }
453  if (ie->GetRound() >= maxID[NAME_ROUND]) {
454  auto unknown = dyn_addName(NAME_ROUND, "?");
455  if (unknown.first != OK)
456  return false;
457  ie->SetRound(unknown.second);
458  ++nUnknowIDs;
459  }
460  return true;
461  };
462 
463  auto idxFile = idx_->FilePtr;
464  auto version = idx_->Header.version;
465  auto nGames = idx_->GetNumGames();
466  idx_->entries_.resize(nGames);
467 
468  auto nBytes = (version < 400) ? OLD_INDEX_ENTRY_SIZE : INDEX_ENTRY_SIZE;
469  for (gamenumT gNum = 0; idxFile->sgetc() != EOF; ++gNum) {
470  if (gNum == nGames)
471  return ERROR_CorruptData;
472 
473  if ((gNum % 8192) == 0) {
474  if (!progress.report(gNum, nGames))
475  return ERROR_UserCancel;
476  }
477 
478  char buf[INDEX_ENTRY_SIZE];
479  if (idxFile->sgetn(buf, nBytes) != nBytes)
480  return ERROR_FileRead;
481 
482  IndexEntry* ie = idx_->FetchEntry(gNum);
483  decodeIndexEntry(buf, version, ie);
484 
485  if (!validateNameIDs(ie))
486  return ERROR_CorruptData;
487 
488  nb_->AddElo(ie->GetWhite(), ie->GetWhiteElo());
489  nb_->AddElo(ie->GetBlack(), ie->GetBlackElo());
490  }
491  progress.report(1, 1);
492 
493  if (nGames != idx_->GetNumGames())
494  return ERROR_FileRead;
495 
496  idx_->nInvalidNameId_ = nUnknowIDs;
497  return (nUnknowIDs == 0) ? OK : ERROR_NameDataLoss;
498 }
void SetNumHalfMoves(ushort b)
Definition: indexentry.h:193
void SetBlack(idNumberT id)
Definition: indexentry.h:142
unsigned char byte
Definition: common.h:89
uint date_GetYear(dateT date)
Definition: date.h:52
int WriteFourBytes(uint32_t value)
Writes a 32-bit unsigned integer.
Definition: filebuf.h:161
const uint INDEX_ENTRY_SIZE
Definition: indexentry.h:42
void resize(size_t count)
Definition: containers.h:149
const byte * GetHomePawnData() const
Definition: indexentry.h:118
const errorT OK
Definition: error.h:23
const errorT ERROR_BadMagic
Definition: error.h:35
std::pair< errorT, idNumberT > dyn_addName(nameT nt, const char *name)
Given a name (string), retrieve the corresponding ID.
Definition: codec_scid4.h:145
unsigned short versionT
Definition: common.h:38
const uint HPSIG_SIZE
Definition: indexentry.h:35
const errorT ERROR_FileWrite
Definition: error.h:32
void SetBlackRatingType(byte b)
Definition: indexentry.h:150
std::array< std::vector< int >, NUM_NAME_TYPES > calcNameFreq(const NameBase &nb) const
Counts how many times every names contained in nb is used.
Definition: index.h:117
int WriteOneByte(byte value)
Writes a 8-bit unsigned integer.
Definition: filebuf.h:135
#define ASSERT(f)
Definition: common.h:59
void AddElo(idNumberT id, eloT elo)
A NameBase stores the max ELO for each player.
Definition: namebase.h:64
errorT open(const std::string &filename, fileModeT fmode)
Opens a file and store its size.
Definition: filebuf.h:197
void SetWhite(idNumberT id)
Definition: indexentry.h:130
Definition: misc.h:63
names
Definition: tablebase.tcl:257
gamenumT GetNumGames() const
Header getter functions.
Definition: index.h:136
int WriteThreeBytes(uint32_t value)
Writes a 24-bit unsigned integer.
Definition: filebuf.h:152
uint strPrefix(const char *s1, const char *s2)
Definition: misc.h:314
void SetRound(idNumberT id)
Definition: indexentry.h:162
void SetStoredLineCode(byte b)
Definition: indexentry.h:201
void SetEcoCode(ecoT eco)
Definition: indexentry.h:205
uint32_t idNumberT
Definition: common.h:152
#define DATE_MAKE(y, m, d)
Definition: date.h:45
const dateT ZERO_DATE
Definition: date.h:35
eloT GetWhiteElo() const
Definition: indexentry.h:99
versionT version
Definition: index.h:72
errorT flush() final
Writes all pending output to the files.
int WriteTwoBytes(uint32_t value)
Writes a 16-bit unsigned integer.
Definition: filebuf.h:144
This class stores the database&#39;s names (players, events, sites and rounds).
Definition: namebase.h:33
const errorT ERROR_FileRead
Definition: error.h:33
void SetRawNagCount(unsigned x)
Definition: indexentry.h:189
void SetRawCommentCount(unsigned x)
Definition: indexentry.h:185
int pubsync()
Invokes std::filebuf::sync() to write all pending output to the file.
Definition: filebuf.h:216
void SetDate(dateT date)
Definition: indexentry.h:166
const errorT ERROR_UserCancel
Definition: error.h:27
sizew
Definition: board.tcl:574
uint32_t uint
Definition: common.h:91
errorT flush()
flush() - writes all cached data to the file
Definition: index.h:217
idNumberT GetWhite() const
Definition: indexentry.h:98
void SetSite(idNumberT id)
Definition: indexentry.h:158
IndexEntry * FetchEntry(gamenumT g)
FetchEntry() - return a modifiable pointer to a game&#39;s IndexEntry.
Definition: index.h:204
Definition: index.h:58
void SetLength(size_t length)
Definition: indexentry.h:126
errorT Open(const char *filename, fileModeT fmode)
Opens a file.
Definition: filebuf.h:43
eloT GetBlackElo() const
Definition: indexentry.h:102
void SetEventDate(dateT edate)
Definition: indexentry.h:170
const errorT ERROR_CorruptData
Definition: error.h:46
idNumberT GetBlack() const
Definition: indexentry.h:101
unsigned short errorT
Definition: error.h:20
errorT Open(const char *filename, fileModeT fmode)
Definition: index.cpp:80
std::tuple< decltype(idx_) &, decltype(names_) &, decltype(eloV_) & > getData()
Definition: namebase.h:119
errorT Create(const char *filename)
Definition: index.cpp:56
bool report(size_t done, size_t total) const
Definition: misc.h:75
void SetWhiteElo(eloT elo)
Definition: indexentry.h:134
void decodeIndexEntry(const char *buf_it, versionT version, IndexEntry *ie)
Decode SCID4 (or SCID3) data into an IndexEntry object.
void SetFinalMatSig(matSigT ms)
Definition: indexentry.h:197
void SetResult(resultT res)
Definition: indexentry.h:174
Adds some helper functions to std::filebuf:
Definition: filebuf.h:35
const errorT ERROR_Corrupt
Definition: error.h:46
errorT dyn_open(fileModeT, const char *, const Progress &, Index *, NameBase *) final
Opens/Creates a database.
void SetEvent(idNumberT id)
Definition: indexentry.h:154
idNumberT GetNumNames(nameT nt) const
Definition: namebase.h:178
void clearFlags()
Definition: indexentry.h:269
unsigned nameT
Definition: common.h:153
void SetFlag(uint32_t flagMask, bool set)
Definition: indexentry.h:209
void SetBlackElo(eloT elo)
Definition: indexentry.h:146
decltype(idx_) const & getNames() const
Definition: namebase.h:171
uint gamenumT
Definition: common.h:163
const uint OLD_INDEX_ENTRY_SIZE
Definition: indexentry.h:43
fileModeT
Definition: common.h:136
const errorT ERROR
Definition: error.h:26
const errorT ERROR_NameDataLoss
Definition: error.h:54
Implements the CodecSCID4 class that manages databases encoded in SCID format v4. ...
void SetWhiteRatingType(byte b)
Definition: indexentry.h:138
void SetOffset(uint64_t offset)
Definition: indexentry.h:122
int strCompare(const char *s1, const char *s2)
Definition: misc.h:280
uint date_GetMonth(dateT date)
Definition: date.h:61
const errorT ERROR_FileOpen
Definition: error.h:31
void SetRawVariationCount(unsigned x)
Definition: indexentry.h:181
Definition: indexentry.h:54
uint date_GetDay(dateT date)
Definition: date.h:70