Unravel Engine C++ Reference
Loading...
Searching...
No Matches
filesystem.h
Go to the documentation of this file.
1#pragma once
2
3#include <hpp/filesystem.hpp>
4
5#include <istream>
6#include <unordered_map>
7#include <vector>
8#include <fstream>
9
10namespace fs
11{
12
13using protocols_t = std::unordered_map<std::string, std::string>;
14using byte_array_t = std::vector<std::uint8_t>;
15
16template<typename Container = std::string, typename CharT = char, typename Traits = std::char_traits<char>>
18{
19 static_assert(
20 std::is_same<Container, std::basic_string<CharT, Traits, typename Container::allocator_type>>::value ||
21 std::is_same<Container, std::vector<CharT, typename Container::allocator_type>>::value ||
22 std::is_same<Container,
23 std::vector<std::make_unsigned_t<CharT>, typename Container::allocator_type>>::value ||
24 std::is_same<Container, std::vector<std::make_signed_t<CharT>, typename Container::allocator_type>>::value,
25 "only strings and vectors of ((un)signed) CharT allowed");
26
27 class membuf : public std::streambuf
28 {
29 public:
30 membuf(const typename Container::value_type* begin, size_t size)
31 {
32 auto cbegin = reinterpret_cast<char*>(const_cast<typename Container::value_type*>(begin));
33 this->setg(cbegin, cbegin, cbegin + size);
34 }
35 };
36 auto get_stream_buf() const -> membuf
37 {
38 membuf result(data.data(), data.size());
39 return result;
40 }
41
42 Container data;
43};
44
45//-----------------------------------------------------------------------------
46// Name : add_path_protocol ()
53//-----------------------------------------------------------------------------
54auto add_path_protocol(const std::string& protocol, const path& directory) -> bool;
55
56//-----------------------------------------------------------------------------
57// Name : get_path_protocols ()
61//-----------------------------------------------------------------------------
63
64//-----------------------------------------------------------------------------
65// Name : resolve_protocol()
72//-----------------------------------------------------------------------------
73auto extract_protocol(const path& _path) -> path;
74
75//-----------------------------------------------------------------------------
76// Name : resolve_protocol()
83//-----------------------------------------------------------------------------
84auto resolve_protocol(const path& _path) -> path;
85
86//-----------------------------------------------------------------------------
87// Name : convert_to_protocol()
92//-----------------------------------------------------------------------------
93auto convert_to_protocol(const path& _path) -> path;
94
95//-----------------------------------------------------------------------------
96// Name : has_known_protocol()
100//-----------------------------------------------------------------------------
101auto has_known_protocol(const path& _path) -> bool;
102
103//-----------------------------------------------------------------------------
104// Name : read_stream ()
109//-----------------------------------------------------------------------------
110auto read_stream(std::istream& stream) -> byte_array_t;
111auto read_stream_str(std::istream& stream) -> std::string;
112
113auto read_stream_buffer(std::istream& stream) -> stream_buffer<byte_array_t>;
114auto read_stream_buffer_str(std::istream& stream) -> stream_buffer<std::string>;
115
116//-------------------------------------------------------------------------
117// Name : replace ()
122//-------------------------------------------------------------------------
123auto replace(const path& _path, const path& _sequence, const path& _new_sequence) -> path;
124
125//-------------------------------------------------------------------------
126// Name : split_until ()
130//-------------------------------------------------------------------------
131auto split_until(const path& _path, const path& _predicate) -> std::vector<path>;
132
133//-------------------------------------------------------------------------
134// Name : reduce_trailing_extensions ()
138//-------------------------------------------------------------------------
139auto reduce_trailing_extensions(const path& _path) -> path;
140
141auto is_any_parent_path(const path& parent, const path& child) -> bool;
142
143} // namespace fs
membuf(const typename Container::value_type *begin, size_t size)
Definition filesystem.h:30
Definition cache.hpp:11
bool add_path_protocol(const std::string &protocol, const path &dir)
Allows us to map a protocol to a specific directory. A path protocol gives the caller the ability to ...
path extract_protocol(const path &_path)
Given the specified path/filename, resolve the final full filename. This will be based on either the ...
stream_buffer< std::string > read_stream_buffer_str(std::istream &stream)
std::unordered_map< std::string, std::string > protocols_t
Definition filesystem.h:13
path reduce_trailing_extensions(const path &_path)
another.
byte_array_t read_stream(std::istream &stream)
Load a byte_array_t with the contents of the specified file, be that file in a package or in the main...
path resolve_protocol(const path &_path)
Given the specified path/filename, resolve the final full filename. This will be based on either the ...
bool has_known_protocol(const path &_path)
Checks whether the path has a known protocol.
path replace(const path &_path, const path &_sequence, const path &_new_sequence)
Replacing any occurences of the specified path sequence with another.
std::string read_stream_str(std::istream &stream)
bool is_any_parent_path(const path &parent, const path &child)
std::vector< std::uint8_t > byte_array_t
Definition filesystem.h:14
protocols_t & get_path_protocols()
Returns the registered path protocols.
std::vector< path > split_until(const path &_path, const path &_predicate)
another.
stream_buffer< byte_array_t > read_stream_buffer(std::istream &stream)
path convert_to_protocol(const path &_path)
Oposite of the resolve_protocol this function tries to convert to protocol path from an absolute one.
auto get_stream_buf() const -> membuf
Definition filesystem.h:36