1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-07-11 19:49:14 +00:00

Reintroduce operator>>() in Book class

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2011-05-08 09:12:28 +01:00
parent f78488bbdb
commit d5f0b91c06
2 changed files with 6 additions and 7 deletions

View file

@ -502,15 +502,17 @@ int Book::find_entry(uint64_t key) {
} }
/// Book::get_number() reads sizeof(T) chars from the file's binary byte /// Book::operator>>() reads sizeof(T) chars from the file's binary byte
/// stream and converts them in a number of type T. /// stream and converts them in a number of type T.
template<typename T> template<typename T>
void Book::get_number(T& n) { Book& Book::operator>>(T& n) {
n = 0; n = 0;
for (size_t i = 0; i < sizeof(T); i++) for (size_t i = 0; i < sizeof(T); i++)
n = (n << 8) + (T)bookFile.get(); n = (n << 8) + (T)bookFile.get();
return *this;
} }
@ -526,10 +528,7 @@ BookEntry Book::read_entry(int idx) {
bookFile.seekg(idx * sizeof(BookEntry), ios_base::beg); bookFile.seekg(idx * sizeof(BookEntry), ios_base::beg);
get_number(e.key); *this >> e.key >> e.move >> e.count >> e.learn;
get_number(e.move);
get_number(e.count);
get_number(e.learn);
if (!bookFile.good()) if (!bookFile.good())
{ {

View file

@ -48,7 +48,7 @@ public:
const std::string name() const { return bookName; } const std::string name() const { return bookName; }
private: private:
template<typename T> void get_number(T& n); template<typename T> Book& operator>>(T& n);
BookEntry read_entry(int idx); BookEntry read_entry(int idx);
int find_entry(uint64_t key); int find_entry(uint64_t key);