]> git.sesse.net Git - stockfish/blobdiff - src/book.cpp
Reintroduce operator>>() in Book class
[stockfish] / src / book.cpp
index d6dcf6cb3c8bd84798c5551ef92396f0b051c901..757c8238fe82627143215c7bc73932605a593c9b 100644 (file)
@@ -459,7 +459,7 @@ Move Book::get_move(const Position& pos, bool findBestMove) {
                  move_to(Move(bookMove)), PieceType(p + 1)));
 
   // Verify the book move (if any) is legal
-  MoveStack mlist[MOVES_MAX];
+  MoveStack mlist[MAX_MOVES];
   MoveStack* last = generate<MV_LEGAL>(pos, mlist);
   for (MoveStack* cur = mlist; cur != last; cur++)
       if ((int(cur->move) & ~(3 << 14)) == bookMove) // Mask out special flags
@@ -502,13 +502,27 @@ int Book::find_entry(uint64_t key) {
 }
 
 
+/// Book::operator>>() reads sizeof(T) chars from the file's binary byte
+/// stream and converts them in a number of type T.
+template<typename T>
+Book& Book::operator>>(T& n) {
+
+  n = 0;
+
+  for (size_t i = 0; i < sizeof(T); i++)
+      n = (n << 8) + (T)bookFile.get();
+
+  return *this;
+}
+
+
 /// Book::read_entry() takes an integer index, and returns the BookEntry
 /// at the given index in the book file.
 
 BookEntry Book::read_entry(int idx) {
 
   assert(idx >= 0 && idx < bookSize);
-  assert(is_open());
+  assert(bookFile.is_open());
 
   BookEntry e;