mirror of
https://github.com/libretro/devilutionX.git
synced 2026-11-09 17:22:49 -10:00
Also added an iterator based API, though it's not useful for this use-case. Might be nice in the future? The field/record iterators is single-pass input iterators with shared state. To avoid rescanning fields unnecessarily parseInt currently can only be called once, it would be possible to make these iterators bidirectional with a bit of extra state (holding onto the start pointer) Co-authored-by: Gleb Mazovetskiy <[email protected]>
22 lines
693 B
C++
22 lines
693 B
C++
#include "file.hpp"
|
|
|
|
#include "engine/assets.hpp"
|
|
|
|
namespace devilution {
|
|
tl::expected<DataFile, DataFile::Error> DataFile::load(std::string_view path)
|
|
{
|
|
AssetRef ref = FindAsset(path);
|
|
if (!ref.ok())
|
|
return tl::unexpected { Error::NotFound };
|
|
const size_t size = ref.size();
|
|
// TODO: It should be possible to stream the data file contents instead of copying the whole thing into memory
|
|
std::unique_ptr<char[]> data { new char[size] };
|
|
{
|
|
AssetHandle handle = OpenAsset(std::move(ref));
|
|
if (!handle.ok() || !handle.read(data.get(), size))
|
|
return tl::unexpected { Error::ReadError };
|
|
}
|
|
return DataFile { std::move(data), size };
|
|
}
|
|
} // namespace devilution
|