Skip to content

Commit b385c57

Browse files
committed
Cleanup includes
1 parent 6d613d9 commit b385c57

File tree

9 files changed

+1692
-1679
lines changed

9 files changed

+1692
-1679
lines changed

src/book/book.cpp

+15-12
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,25 @@
66
#include "ctg/ctg.h"
77
#include "book.h"
88

9-
namespace Polyfish::Book
9+
namespace Polyfish
1010
{
11-
/*static*/ Book* Book::create_book(const std::string& filename)
11+
namespace Book
1212
{
13-
size_t extIndex = filename.find_last_of('.');
14-
if (extIndex == std::string::npos)
15-
return nullptr;
13+
/*static*/ Book* Book::create_book(const std::string& filename)
14+
{
15+
size_t extIndex = filename.find_last_of('.');
16+
if (extIndex == std::string::npos)
17+
return nullptr;
1618

17-
std::string ext = filename.substr(extIndex + 1);
19+
std::string ext = filename.substr(extIndex + 1);
1820

19-
if (ext == "ctg" || ext == "cto" || ext == "ctb")
20-
return new CTG::CtgBook();
21-
else if (ext == "bin")
22-
return new Polyglot::PolyglotBook();
23-
else
24-
return nullptr;
21+
if (ext == "ctg" || ext == "cto" || ext == "ctb")
22+
return new CTG::CtgBook();
23+
else if (ext == "bin")
24+
return new Polyglot::PolyglotBook();
25+
else
26+
return nullptr;
27+
}
2528
}
2629
}
2730

src/book/book.h

+57-52
Original file line numberDiff line numberDiff line change
@@ -3,78 +3,83 @@
33
#ifndef BOOK_H_INCLUDED
44
#define BOOK_H_INCLUDED
55

6-
namespace Polyfish::Book
6+
namespace Polyfish
77
{
8-
namespace
9-
{
10-
static const union { uint32_t i; char c[4]; } Le = { 0x01020304 };
11-
static const bool IsBigEndian = (Le.c[0] == 1);
12-
}
8+
class BookManager;
139

14-
class BookUtil
10+
namespace Book
1511
{
16-
public:
17-
template <typename IntType>
18-
static IntType read_big_endian(const unsigned char* buffer, size_t& offset, size_t bufferLen)
12+
namespace
1913
{
20-
IntType result;
21-
constexpr size_t typeSize = sizeof(IntType);
14+
static const union { uint32_t i; char c[4]; } Le = { 0x01020304 };
15+
static const bool IsBigEndian = (Le.c[0] == 1);
16+
}
2217

23-
if (offset + typeSize > bufferLen)
18+
class BookUtil
19+
{
20+
public:
21+
template <typename IntType>
22+
static IntType read_big_endian(const unsigned char* buffer, size_t& offset, size_t bufferLen)
2423
{
25-
assert(false);
26-
return IntType();
27-
}
24+
IntType result;
25+
constexpr size_t typeSize = sizeof(IntType);
2826

29-
//Read the integer type and convert (if needed)
30-
memcpy(&result, buffer + offset, typeSize);
27+
if (offset + typeSize > bufferLen)
28+
{
29+
assert(false);
30+
return IntType();
31+
}
3132

32-
if (!IsBigEndian)
33-
{
34-
unsigned char u[typeSize];
35-
typename std::make_unsigned<IntType>::type v = 0;
33+
//Read the integer type and convert (if needed)
34+
memcpy(&result, buffer + offset, typeSize);
35+
36+
if (!IsBigEndian)
37+
{
38+
unsigned char u[typeSize];
39+
typename std::make_unsigned<IntType>::type v = 0;
40+
41+
memcpy(&u, &result, typeSize);
42+
for (size_t i = 0; i < typeSize; ++i)
43+
v = (v << 8) | u[i];
3644

37-
memcpy(&u, &result, typeSize);
38-
for (size_t i = 0; i < typeSize; ++i)
39-
v = (v << 8) | u[i];
45+
memcpy(&result, &v, typeSize);
46+
}
4047

41-
memcpy(&result, &v, typeSize);
48+
offset += typeSize;
49+
return result;
4250
}
4351

44-
offset += typeSize;
45-
return result;
46-
}
52+
template <typename IntType>
53+
static IntType read_big_endian(const unsigned char* buffer, size_t bufferLen)
54+
{
55+
size_t offset = 0;
56+
return read_big_endian<IntType>(buffer, offset, bufferLen);
57+
}
58+
};
4759

48-
template <typename IntType>
49-
static IntType read_big_endian(const unsigned char* buffer, size_t bufferLen)
60+
class Book
5061
{
51-
size_t offset = 0;
52-
return read_big_endian<IntType>(buffer, offset, bufferLen);
53-
}
54-
};
62+
friend class Polyfish::BookManager;
5563

56-
class Book
57-
{
58-
friend class Polyfish::BookManager;
59-
60-
private:
61-
static Book* create_book(const std::string& filename);
64+
private:
65+
static Book* create_book(const std::string& filename);
6266

63-
public:
64-
Book() { }
65-
virtual ~Book() { }
67+
public:
68+
Book() { }
69+
virtual ~Book() { }
6670

67-
Book(const Book&) = delete;
68-
Book& operator=(const Book&) = delete;
71+
Book(const Book&) = delete;
72+
Book& operator=(const Book&) = delete;
6973

70-
virtual std::string type() const = 0;
74+
virtual std::string type() const = 0;
7175

72-
virtual bool open(const std::string& filename) = 0;
73-
virtual void close() = 0;
76+
virtual bool open(const std::string& filename) = 0;
77+
virtual void close() = 0;
7478

75-
virtual Move probe(const Position& pos, size_t width, bool onlyGreen) const = 0;
76-
virtual void show_moves(const Position& pos) const = 0;
77-
};
79+
virtual Move probe(const Position& pos, size_t width, bool onlyGreen) const = 0;
80+
virtual void show_moves(const Position& pos) const = 0;
81+
};
82+
}
7883
}
7984

8085
#endif

src/book/book_manager.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#if defined(POLYFISH)
22

3-
#include "../misc.h"
43
#include "../uci.h"
54
#include "polyglot/polyglot.h"
65
#include "ctg/ctg.h"

0 commit comments

Comments
 (0)