📂 golxzn::os::filesystem 📂 1.6.5
golxzn filesystem submodule
Loading...
Searching...
No Matches
golxzn::os::filesystem Class Referencefinal

Golxzn Resource Manager. More...

#include <filesystem.hpp>

Classes

struct  error
 Struct returned by some methods to tell if there's an error. More...
 

Public Types

using associations_type = std::unordered_map< std::wstring, std::wstring >
 Map of the protocol extensions and their prefixes.
 

Static Public Member Functions

static error initialize (const std::wstring_view application_name, const std::wstring_view assets_path=default_assets_directory_name)
 Initialize the Resource Manager.
 
static void set_application_name (const std::wstring_view application_name) noexcept
 Sets the application name object.
 
static void associate (std::wstring_view protocol, std::wstring &&prefix) noexcept
 Add the association between the protocol and the prefix. (ex. L"res://" and L"user://")
 
static std::vector< byte > read_binary (const std::wstring_view path)
 Read whole binary file.
 
static std::string read_text (const std::wstring_view path)
 Read whole text file.
 
template<class Custom >
static auto read_binary (const std::wstring_view path) -> std::enable_if_t< std::is_constructible_v< Custom, std::vector< byte > >, Custom >
 Construct Custom class by binary data from file.
 
template<class Custom >
static auto read_text (const std::wstring_view path) -> std::enable_if_t< std::is_constructible_v< Custom, std::string >, Custom >
 Construct Custom class by text data from file.
 
template<class Custom >
static auto read_shared_binary (const std::wstring_view path) -> std::enable_if_t< std::is_constructible_v< Custom, std::vector< byte > >, std::shared_ptr< Custom > >
 Construct std::shared_ptr<Custom> by binary data from file.
 
template<class Custom >
static auto read_shared_text (const std::wstring_view path) -> std::enable_if_t< std::is_constructible_v< Custom, std::string >, std::shared_ptr< Custom > >
 Construct std::shared_ptr<Custom> by binary data from file.
 
template<class Custom >
static auto read_unique_binary (const std::wstring_view path) -> std::enable_if_t< std::is_constructible_v< Custom, std::vector< byte > >, std::unique_ptr< Custom > >
 Construct std::shared_ptr<Custom> by binary data from file.
 
template<class Custom >
static auto read_unique_text (const std::wstring_view path) -> std::enable_if_t< std::is_constructible_v< Custom, std::string >, std::unique_ptr< Custom > >
 Construct std::shared_ptr<Custom> by binary data from file.
 
static error write_binary (const std::wstring_view path, const details::data_view< byte > &data)
 Write binary data to a file.
 
static error write_binary (const std::wstring_view path, const std::initializer_list< byte > data)
 Write binary data to a file.
 
static error append_binary (const std::wstring_view path, const details::data_view< byte > &data)
 Append binary data to a file.
 
static error append_binary (const std::wstring_view path, const std::initializer_list< byte > data)
 Append binary data to a file.
 
static error write_text (const std::wstring_view path, const std::string_view text)
 Write text data to a file.
 
static error append_text (const std::wstring_view path, const std::string_view text)
 Append text data to a file.
 
static error write_text (const std::wstring_view path, const std::wstring_view text)
 Write text data to a file.
 
static error append_text (const std::wstring_view path, const std::wstring_view text)
 Append text data to a file.
 
static std::wstring_view get_association (const std::wstring_view protocol) noexcept
 Get the association object.
 
static std::wstring_view application_name () noexcept
 Get the application name.
 
static std::wstring_view user_data_directory () noexcept
 Get the user data directory object.
 
static std::wstring_view assets_directory () noexcept
 Get the assets directories.
 
static const associations_typeassociations () noexcept
 Get the associations.
 
static void join (std::wstring &left, std::wstring_view right) noexcept
 Join two paths with a slash.
 
static std::wstring join (std::wstring_view left, std::wstring_view right) noexcept
 Join two paths with a slash.
 
static void parent_directory (std::wstring &path) noexcept
 Remove the last path component.
 
static std::wstring parent_directory (std::wstring_view path) noexcept
 Remove the last path component.
 
static std::wstring normalize (std::wstring_view path)
 Fix the path separators to the '/' and remove the trailing slash.
 
static bool exists (const std::wstring_view path) noexcept
 Check if an entry exists.
 
static bool is_file (const std::wstring_view path)
 Check if an entry is a file.
 
static bool is_directory (const std::wstring_view path)
 Check if an entry is a directory.
 
static error make_directory (const std::wstring_view path)
 Create a directory (recursively).
 
static error remove_directory (const std::wstring_view path)
 Remove a directory (recursively).
 
static error remove_file (const std::wstring_view path)
 Remove a file.
 
static error remove (const std::wstring_view path)
 List an entry (file or directory).
 
static std::wstring current_directory ()
 Get the absolute path of this application.
 
static std::vector< std::wstring > entries (const std::wstring_view path)
 Get all entries in a directory.
 
static std::wstring to_wide (const std::string_view str) noexcept
 Convert a string to wide string.
 
static std::string to_narrow (const std::wstring_view wstr) noexcept
 Convert a wide string to string.
 
static error initialize (const std::string_view application_name, const std::string_view assets_path=default_assets_directory_name_narrow)
 Narrow string alias for golxzn::os::filesystem::initialize(const std::wstring_view, const std::wstring_view)
 
static void set_application_name (const std::string_view application_name) noexcept
 Narrow string alias for golxzn::os::filesystem::set_application_name(const std::wstring_view)
 
static void associate (const std::string_view protocol, const std::string_view prefix) noexcept
 Narrow string alias for golxzn::os::filesystem::associate(const std::wstring_view, const std::wstring_view)
 
static std::vector< byte > read_binary (const std::string_view path)
 Narrow string alias for golxzn::os::filesystem::read_binary(const std::wstring_view path)
 
static std::string read_text (const std::string_view path)
 Narrow string alias for golxzn::os::filesystem::read_text(const std::wstring_view path)
 
template<class Custom >
static auto read_binary (const std::string_view path) -> std::enable_if_t< std::is_constructible_v< Custom, std::vector< byte > >, Custom >
 Narrow string alias for golxzn::os::filesystem::read_binary(const std::wstring_view path)
 
template<class Custom >
static auto read_text (const std::string_view path) -> std::enable_if_t< std::is_constructible_v< Custom, std::string >, Custom >
 Narrow string alias for golxzn::os::filesystem::read_text(const std::wstring_view path)
 
template<class Custom >
static auto read_shared_binary (const std::string_view path) -> std::enable_if_t< std::is_constructible_v< Custom, std::vector< byte > >, std::shared_ptr< Custom > >
 Narrow string alias for golxzn::os::filesystem::read_shared_binary(const std::wstring_view path)
 
template<class Custom >
static auto read_shared_text (const std::string_view path) -> std::enable_if_t< std::is_constructible_v< Custom, std::string >, std::shared_ptr< Custom > >
 Narrow string alias for golxzn::os::filesystem::read_shared_text(const std::wstring_view path)
 
template<class Custom >
static auto read_unique_binary (const std::string_view path) -> std::enable_if_t< std::is_constructible_v< Custom, std::vector< byte > >, std::unique_ptr< Custom > >
 Narrow string alias for golxzn::os::filesystem::read_unique_binary(const std::wstring_view path)
 
template<class Custom >
static auto read_unique_text (const std::string_view path) -> std::enable_if_t< std::is_constructible_v< Custom, std::string >, std::unique_ptr< Custom > >
 Narrow string alias for golxzn::os::filesystem::read_unique_text(const std::wstring_view path)
 
static error write_binary (const std::string_view path, const details::data_view< byte > &data)
 Narrow string alias for golxzn::os::filesystem::write_binary(const std::wstring_view path, const details::data_view<byte> &data)
 
static error write_binary (const std::string_view path, const std::initializer_list< byte > data)
 Narrow string alias for golxzn::os::filesystem::write_binary(const std::wstring_view path, const std::initializer_list<byte> data)
 
static error append_binary (const std::string_view path, const details::data_view< byte > &data)
 Narrow string alias for golxzn::os::filesystem::append_binary(const std::wstring_view path, const details::data_view<byte> &data)
 
static error append_binary (const std::string_view path, const std::initializer_list< byte > data)
 Narrow string alias for golxzn::os::filesystem::append_binary(const std::wstring_view path, const std::initializer_list<byte> data)
 
static error write_text (const std::string_view path, const std::string_view text)
 Narrow string alias for golxzn::os::filesystem::write_text(const std::wstring_view path, const std::string_view text)
 
static error append_text (const std::string_view path, const std::string_view text)
 Narrow string alias for golxzn::os::filesystem::append_text(const std::wstring_view path, const std::string_view text)
 
static error write_text (const std::string_view path, const std::wstring_view text)
 Narrow string alias for golxzn::os::filesystem::write_text(const std::wstring_view path, const std::wstring_view text)
 
static error append_text (const std::string_view path, const std::wstring_view text)
 Narrow string alias for golxzn::os::filesystem::append_text(const std::wstring_view path, const std::wstring_view text)
 
static std::wstring_view get_association (const std::string_view protocol) noexcept
 Narrow string alias for golxzn::os::filesystem::get_association(const std::wstring_view protocol)
 
static void join (std::string &left, std::string_view right) noexcept
 Narrow string alias for golxzn::os::filesystem::join(std::wstring &left, std::wstring_view right)
 
static std::string join (std::string_view left, std::string_view right) noexcept
 Narrow string alias for golxzn::os::filesystem::join(std::wstring_view left, std::wstring_view right)
 
static void parent_directory (std::string &path) noexcept
 Narrow string alias for golxzn::os::filesystem::parent_directory(std::wstring &path)
 
static std::string parent_directory (std::string_view path) noexcept
 Narrow string alias for golxzn::os::filesystem::parent_directory(std::wstring_view path)
 
static std::wstring normalize (const std::string_view path)
 Narrow string alias for golxzn::os::filesystem::normalize(const std::wstring_view path)
 
static bool exists (const std::string_view path) noexcept
 Narrow string alias for golxzn::os::filesystem::exists(const std::wstring_view path)
 
static bool is_file (const std::string_view path)
 Narrow string alias for golxzn::os::filesystem::is_file(const std::wstring_view path)
 
static bool is_directory (const std::string_view path)
 Narrow string alias for golxzn::os::filesystem::is_directory(const std::wstring_view path)
 
static error make_directory (const std::string_view path)
 Narrow string alias for golxzn::os::filesystem::make_directory(const std::wstring_view path)
 
static error remove_directory (const std::string_view path)
 Narrow string alias for golxzn::os::filesystem::remove_directory(const std::wstring_view path)
 
static error remove_file (const std::string_view path)
 Narrow string alias for golxzn::os::filesystem::remove_file(const std::wstring_view path)
 
static error remove (const std::string_view path)
 Narrow string alias for golxzn::os::filesystem::remove(const std::wstring_view path)
 
static std::vector< std::string > entries (const std::string_view path)
 Narrow stirng alias for golxzn::os::filesystem::entries(const std::wstring_view path)
 

Static Public Attributes

static constexpr std::wstring_view none { L"" }
 Empty wide string.
 
static constexpr std::wstring::value_type separator { L'/' }
 Path separator.
 
static constexpr std::wstring_view default_application_name { L"unknown_application" }
 Default application name.
 
static constexpr std::wstring_view default_assets_directory_name { L"assets" }
 Default assets directory name.
 
static constexpr std::wstring_view protocol_separator { L"://" }
 Protocol separator.
 
static constexpr std::string_view none_narrow { "" }
 Narrow version of golxzn::os::filesystem::none.
 
static constexpr std::string::value_type separator_narrow { '/' }
 Narrow version of golxzn::os::filesystem::separator.
 
static constexpr std::string_view default_application_name_narrow { "unknown_application" }
 Narrow version of golxzn::os::filesystem::default_application_name.
 
static constexpr std::string_view default_assets_directory_name_narrow { "assets" }
 Narrow version of golxzn::os::filesystem::default_assets_directory_name.
 
static constexpr std::string_view protocol_separator_narrow { "://" }
 Narrow version of golxzn::os::filesystem::protocol_separator.
 
static const error OK { std::wstring{ none } }
 OK struct.
 

Detailed Description

Golxzn Resource Manager.

Use this class to load resources from the program's directory.

Warning
Every methods with string arguments instead of wstring cause a memory allocation.

Member Function Documentation

◆ application_name()

static std::wstring_view golxzn::os::filesystem::application_name ( )
staticnoexcept

Get the application name.

Returns
std::string_view - application name

◆ assets_directory()

static std::wstring_view golxzn::os::filesystem::assets_directory ( )
staticnoexcept

Get the assets directories.

Same as golxzn::os::filesystem::get_association(L"res://")

Returns
assets directory or golxzn::os::filesystem::none if it's not set

◆ associations()

static const associations_type & golxzn::os::filesystem::associations ( )
staticnoexcept

Get the associations.

Returns
const associations_type& associations - Map of the protocol extensions and their prefixes

◆ current_directory()

static std::wstring golxzn::os::filesystem::current_directory ( )
static

Get the absolute path of this application.

Returns
std::wstring Absolute path of the application or, in the failure case, a "./".

◆ entries()

static std::vector< std::wstring > golxzn::os::filesystem::entries ( const std::wstring_view  path)
static

Get all entries in a directory.

Parameters
pathpath to the directory
Returns
std::vector<std::wstring> - vector of entries

◆ get_association()

static std::wstring_view golxzn::os::filesystem::get_association ( const std::wstring_view  protocol)
staticnoexcept

Get the association object.

Parameters
protocolThe protocol. Has to end with "://". If the prefix is not set, it returns an golxzn::os::filesystem::none
Returns
std::wstring_view - Prefix or golxzn::os::filesystem::none

◆ join() [1/2]

static void golxzn::os::filesystem::join ( std::wstring &  left,
std::wstring_view  right 
)
staticnoexcept

Join two paths with a slash.

Parameters
leftPath that will be changed
rightPath to append

◆ join() [2/2]

static std::wstring golxzn::os::filesystem::join ( std::wstring_view  left,
std::wstring_view  right 
)
staticnoexcept

Join two paths with a slash.

Parameters
leftleft path
rightright path
Returns
std::wstring - Joined path

◆ normalize()

static std::wstring golxzn::os::filesystem::normalize ( std::wstring_view  path)
static

Fix the path separators to the '/' and remove the trailing slash.

Parameters
pathstd::wstring_view path
Returns
std::wstring - Canonical path

◆ parent_directory() [1/2]

static void golxzn::os::filesystem::parent_directory ( std::wstring &  path)
staticnoexcept

Remove the last path component.

Parameters
pathpath

◆ parent_directory() [2/2]

static std::wstring golxzn::os::filesystem::parent_directory ( std::wstring_view  path)
staticnoexcept

Remove the last path component.

Parameters
pathpath
Returns
std::wstring - Parent directory

◆ to_narrow()

static std::string golxzn::os::filesystem::to_narrow ( const std::wstring_view  wstr)
staticnoexcept

Convert a wide string to string.

Parameters
wstrwide string to convert
Returns
std::string - converted string

◆ to_wide()

static std::wstring golxzn::os::filesystem::to_wide ( const std::string_view  str)
staticnoexcept

Convert a string to wide string.

Parameters
strstring to convert
Returns
std::wstring - converted wide string

◆ user_data_directory()

static std::wstring_view golxzn::os::filesystem::user_data_directory ( )
staticnoexcept

Get the user data directory object.

Same as golxzn::os::filesystem::get_association(L"user://") Gets the full path of the user data directory:

  • Windows: USERPROFILE%/AppData/Roaming/<application name>
  • MacOS: $HOME/Library/Application Support/<application name>
  • Linux: $XDG_CONFIG_HOME/<application name> or $HOME/.config/<application name>
Returns
User directory or golxzn::os::filesystem::none if it's not set

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