mirror of
https://github.com/AlexAltea/orbital.git
synced 2024-05-13 09:59:48 -04:00
all: Fix formatting of *.cpp files
This commit is contained in:
parent
dcec16c9d6
commit
c3bba3cdb4
|
@ -3,7 +3,7 @@
|
|||
|
||||
root = true
|
||||
|
||||
[**.{c,h}]
|
||||
[**.{c,cpp,h}]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
trim_trailing_whitespace = true
|
||||
|
|
|
@ -16,73 +16,73 @@ constexpr U32 BLS_MAGIC = '2BLS';
|
|||
constexpr U64 BLS_BLOCK = 0x200;
|
||||
|
||||
U64 BlsStream::read(U64 size, void* buffer) {
|
||||
std::unique_lock<std::mutex> lock(bls->mtx);
|
||||
Stream& s = bls->s;
|
||||
s.seek(base + offset, StreamSeek::Set);
|
||||
size = std::min<U32>(size, size - offset);
|
||||
return s.read(size, buffer);
|
||||
std::unique_lock<std::mutex> lock(bls->mtx);
|
||||
Stream& s = bls->s;
|
||||
s.seek(base + offset, StreamSeek::Set);
|
||||
size = std::min<U32>(size, size - offset);
|
||||
return s.read(size, buffer);
|
||||
}
|
||||
|
||||
U64 BlsStream::write(U64 size, const void* buffer) {
|
||||
throw std::runtime_error("Unsupported method");
|
||||
throw std::runtime_error("Unsupported method");
|
||||
}
|
||||
|
||||
void BlsStream::seek(U64 offset, StreamSeek mode) {
|
||||
switch (mode) {
|
||||
case StreamSeek::Set:
|
||||
this->offset = offset;
|
||||
break;
|
||||
case StreamSeek::Cur:
|
||||
this->offset += offset;
|
||||
break;
|
||||
case StreamSeek::End:
|
||||
this->offset = size - offset;
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("Unsupported mode");
|
||||
}
|
||||
switch (mode) {
|
||||
case StreamSeek::Set:
|
||||
this->offset = offset;
|
||||
break;
|
||||
case StreamSeek::Cur:
|
||||
this->offset += offset;
|
||||
break;
|
||||
case StreamSeek::End:
|
||||
this->offset = size - offset;
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("Unsupported mode");
|
||||
}
|
||||
}
|
||||
|
||||
U64 BlsStream::tell() const {
|
||||
return offset;
|
||||
return offset;
|
||||
}
|
||||
|
||||
BlsParser::BlsParser(Stream& s) : s(s) {
|
||||
// Read and verify BLS header
|
||||
s.seek(0, StreamSeek::Set);
|
||||
header = s.read_t<BlsHeader>();
|
||||
assert(header.magic == BLS_MAGIC);
|
||||
assert(header.version == 1);
|
||||
// Read and verify BLS header
|
||||
s.seek(0, StreamSeek::Set);
|
||||
header = s.read_t<BlsHeader>();
|
||||
assert(header.magic == BLS_MAGIC);
|
||||
assert(header.version == 1);
|
||||
}
|
||||
|
||||
BlsParser::~BlsParser() {
|
||||
}
|
||||
|
||||
std::vector<std::string> BlsParser::files() {
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
std::vector<std::string> names(header.num_files);
|
||||
s.seek(sizeof(BlsHeader), StreamSeek::Set);
|
||||
for (auto& name : names) {
|
||||
auto entry = s.read_t<BlsEntry>();
|
||||
name = (char*)&entry.file_name[0];
|
||||
}
|
||||
return names;
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
std::vector<std::string> names(header.num_files);
|
||||
s.seek(sizeof(BlsHeader), StreamSeek::Set);
|
||||
for (auto& name : names) {
|
||||
auto entry = s.read_t<BlsEntry>();
|
||||
name = (char*)&entry.file_name[0];
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
BlsStream BlsParser::get(std::string_view name) {
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
s.seek(sizeof(BlsHeader), StreamSeek::Set);
|
||||
for (U32 i = 0; i < header.num_files; i++) {
|
||||
auto entry = s.read_t<BlsEntry>();
|
||||
if (name == (char*)&entry.file_name[0])
|
||||
return BlsStream(this, entry.block_offset * BLS_BLOCK, entry.file_size);
|
||||
}
|
||||
throw std::runtime_error("Could not find file within BLS");
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
s.seek(sizeof(BlsHeader), StreamSeek::Set);
|
||||
for (U32 i = 0; i < header.num_files; i++) {
|
||||
auto entry = s.read_t<BlsEntry>();
|
||||
if (name == (char*)&entry.file_name[0])
|
||||
return BlsStream(this, entry.block_offset * BLS_BLOCK, entry.file_size);
|
||||
}
|
||||
throw std::runtime_error("Could not find file within BLS");
|
||||
}
|
||||
|
||||
BlsStream BlsParser::get(U32 index) {
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
s.seek(sizeof(BlsHeader) + sizeof(BlsEntry) * index, StreamSeek::Set);
|
||||
auto entry = s.read_t<BlsEntry>();
|
||||
return BlsStream(this, entry.block_offset * BLS_BLOCK, entry.file_size);
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
s.seek(sizeof(BlsHeader) + sizeof(BlsEntry) * index, StreamSeek::Set);
|
||||
auto entry = s.read_t<BlsEntry>();
|
||||
return BlsStream(this, entry.block_offset * BLS_BLOCK, entry.file_size);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue