le2d v0.4.3
2D game engine framework
 
Loading...
Searching...
No Matches
le::FileDataLoader Class Reference

Concrete IDataLoader that uses the filesystem. More...

#include <le2d/file_data_loader.hpp>

Inheritance diagram for le::FileDataLoader:
le::IDataLoader

Public Member Functions

 FileDataLoader (std::string_view root_dir=".")
 
auto try_load_bytes (std::vector< std::byte > &out, std::string_view uri) const -> bool final
 
auto try_load_spirv (std::vector< std::uint32_t > &out, std::string_view uri) const -> bool final
 
auto try_load_string (std::string &out, std::string_view uri) const -> bool final
 
auto save_bytes (std::span< std::byte const > bytes, std::string_view uri) const -> bool
 
auto save_string (std::string_view text, std::string_view uri) const -> bool
 
auto get_root_dir () const -> std::string_view
 
auto set_root_dir (std::string_view root_dir) -> bool
 
auto get_path (std::string_view uri) const -> std::string
 
auto get_uri (std::string_view path) const -> std::string
 
- Public Member Functions inherited from le::IDataLoader
auto load_bytes (std::string_view uri) const -> std::vector< std::byte >
 
auto load_spir_v (std::string_view uri) const -> std::vector< std::uint32_t >
 
auto load_string (std::string_view uri) const -> std::string
 
auto try_load_json (dj::Json &out, std::string_view uri) const -> bool
 
auto load_json (std::string_view uri) const -> dj::Json
 
auto get_json_type_name (std::string_view uri) const -> std::string
 

Static Public Member Functions

static auto upfind (std::string_view suffix, std::string_view leaf_dir=".") -> std::string
 Locate a directory by cycling upwards every iteration.
 

Detailed Description

Concrete IDataLoader that uses the filesystem.

Constructor & Destructor Documentation

◆ FileDataLoader()

le::FileDataLoader::FileDataLoader ( std::string_view  root_dir = ".")
explicit
Parameters
root_dirMount point. Will be prefixed to URIs for loads.

Member Function Documentation

◆ get_path()

auto le::FileDataLoader::get_path ( std::string_view  uri) const -> std::string
Parameters
uriURI to get full path for.
Returns
Full path (whether it exists or not).

◆ get_root_dir()

auto le::FileDataLoader::get_root_dir ( ) const -> std::string_view
inline
Returns
Current root dir.

◆ get_uri()

auto le::FileDataLoader::get_uri ( std::string_view  path) const -> std::string
Parameters
pathpath to get URI for.
Returns
URI corresponding to path, if within root dir.

◆ save_bytes()

auto le::FileDataLoader::save_bytes ( std::span< std::byte const >  bytes,
std::string_view  uri 
) const -> bool
Parameters
bytesBytes to save to file.
uriURI to save file at.

◆ save_string()

auto le::FileDataLoader::save_string ( std::string_view  text,
std::string_view  uri 
) const -> bool
Parameters
textText to save to file.
uriURI to save file at.

◆ set_root_dir()

auto le::FileDataLoader::set_root_dir ( std::string_view  root_dir) -> bool
Parameters
root_dirMount point. Will be prefixed to URIs for loads.
Returns
true if successfully mounted.

◆ try_load_bytes()

auto le::FileDataLoader::try_load_bytes ( std::vector< std::byte > &  out,
std::string_view  uri 
) const -> bool
finalvirtual
Parameters
outDestination buffer.
uriURI to load from.
Returns
true if successfully loaded.

Implements le::IDataLoader.

◆ try_load_spirv()

auto le::FileDataLoader::try_load_spirv ( std::vector< std::uint32_t > &  out,
std::string_view  uri 
) const -> bool
finalvirtual
Parameters
outDestination buffer.
uriURI to load from.
Returns
true if successfully loaded.

Implements le::IDataLoader.

◆ try_load_string()

auto le::FileDataLoader::try_load_string ( std::string &  out,
std::string_view  uri 
) const -> bool
finalvirtual
Parameters
outDestination buffer.
uriURI to load from.
Returns
true if successfully loaded.

Implements le::IDataLoader.

◆ upfind()

static auto le::FileDataLoader::upfind ( std::string_view  suffix,
std::string_view  leaf_dir = "." 
) -> std::string
static

Locate a directory by cycling upwards every iteration.

Parameters
suffixPattern to search for (eg "assets" or "resources/data").
leaf_dirStarting directory (usually working dir or exe dir).

The documentation for this class was generated from the following file: