IceShard 1
A personal game engine project, with development focused on 2D/2.5D games.
Loading...
Searching...
No Matches
native_file.hxx
Go to the documentation of this file.
1
3
4#pragma once
5#include <ice/os.hxx>
6#include <ice/path_utils.hxx>
7#include <ice/native_aio.hxx>
8#include <ice/expected.hxx>
9
11{
12
13 static constexpr ErrorCode E_FileHandleInvalid{ "E.8800:FileSystem:File handle is invalid." };
14 static constexpr ErrorCode E_FilePathProvidedIsInvalid{ "E.8801:FileSystem:File path provided is invalid." };
15 static constexpr ErrorCode E_FileFailedToBindToAIOPort{ "E.8802:FileSystem:File handle failed to bind to provided AIO port." };
16 static constexpr ErrorCode E_FileFailedToReadRequestedSize{ "E.8803:FileSystem:Failed to read requested number of bytes from file." };
17
18#if ISP_WINDOWS
19 using File = ice::win32::FileHandle;
20 using FilePath = ice::BasicPath<ice::wchar>;
21 using HeapFilePath = ice::BasicHeapPath<ice::wchar>;
22# define ISP_PATH_LITERAL(val) L##val
23#elif ISP_UNIX
24 using File = ice::unix_::FileHandle;
25 using FilePath = ice::BasicPath<char>;
26 using HeapFilePath = ice::BasicHeapPath<char>;
27# define ISP_PATH_LITERAL(val) val
28#endif
29
30 enum class PathFlags : ice::u8
31 {
32 None = 0x00,
33 Normalized = 0x01,
34 };
35
37 {
39 None = 0b0000'0000,
40
42 Read = 0b0000'0000,
43
45 Write = 0b0000'0001,
46
48 Exclusive = 0b0001'0000,
49
51 Asynchronous = 0b0010'0000,
52 };
53
60
62 ice::native_file::FilePath path
63 ) noexcept;
64
66 ice::native_file::FilePath path,
68 ) noexcept -> ice::native_file::File;
69
72 ice::native_file::FilePath path,
75
77 auto sizeof_file(ice::native_file::FilePath path) noexcept -> ice::usize;
78
81 ice::usize requested_read_size,
82 ice::Memory memory
83 ) noexcept -> ice::usize;
84
87 ice::usize requested_read_offset,
88 ice::usize requested_read_size,
89 ice::Memory memory
90 ) noexcept -> ice::usize;
91
95 ice::usize requested_read_offset,
96 ice::usize requested_read_size,
97 ice::Memory memory
99
102 ice::usize write_offset,
104 ) noexcept -> ice::usize;
105
109 ice::usize write_offset,
112
116 ) noexcept -> ice::usize;
117
119 enum class EntityType : ice::u8 { File, Directory };
120
121 using TraversePathCallback = auto(*)(
122 ice::native_file::FilePath,
123 ice::native_file::FilePath,
125 void* userdata
127
129 ice::native_file::FilePath starting_dir,
131 void* userdata
132 ) noexcept;
133
135 ice::native_file::FilePath path
136 ) noexcept;
137
139 ice::native_file::FilePath path
140 ) noexcept;
141
143 ice::native_file::HeapFilePath& out_filepath,
144 ice::String path_string
145 ) noexcept;
146
148 ice::native_file::FilePath path,
149 ice::HeapString<>& out_string
150 ) noexcept;
151
153 ice::native_file::HeapFilePath& path,
154 ice::String string
155 ) noexcept;
156
157 template<PathFlags Flags = PathFlags::None, typename... Strings>
158 requires (std::convertible_to<Strings, ice::String> && ...)
159 inline auto path_from_strings(
161 Strings&&... strings
162 ) noexcept -> ice::native_file::HeapFilePath
163 {
164 ice::native_file::HeapFilePath result{ alloc };
165 (ice::native_file::path_join_string(result, ice::forward<Strings>(strings)), ...);
166 if constexpr (ice::has_all(Flags, PathFlags::Normalized))
167 {
168 result.normalize();
169 }
170 return result;
171 }
172
173} // namespace ice::native_file
Definition expected.hxx:16
Definition span.hxx:129
struct AIOPortInternal * AIOPort
Definition native_aio.hxx:10
Definition native_file.hxx:11
auto read_file_request(ice::native_aio::AIORequest &request, ice::native_file::File const &native_file, ice::usize requested_read_offset, ice::usize requested_read_size, ice::Memory memory) noexcept -> ice::native_file::FileRequestStatus
static constexpr ErrorCode E_FilePathProvidedIsInvalid
Definition native_file.hxx:14
bool create_directory(ice::native_file::FilePath path) noexcept
static constexpr ErrorCode E_FileHandleInvalid
Definition native_file.hxx:13
auto(*)( ice::native_file::FilePath, ice::native_file::FilePath, ice::native_file::EntityType, void *userdata) noexcept -> ice::native_file::TraverseAction TraversePathCallback
Definition native_file.hxx:121
auto sizeof_file(ice::native_file::File const &native_file) noexcept -> ice::usize
bool exists_file(ice::native_file::FilePath path) noexcept
auto open_file(ice::native_file::FilePath path, ice::native_file::FileOpenFlags flags=FileOpenFlags::Read) noexcept -> ice::native_file::File
PathFlags
Definition native_file.hxx:31
@ Normalized
Definition native_file.hxx:33
@ None
Definition native_file.hxx:32
auto path_from_strings(ice::Allocator &alloc, Strings &&... strings) noexcept -> ice::native_file::HeapFilePath
Definition native_file.hxx:159
static constexpr ErrorCode E_FileFailedToReadRequestedSize
Definition native_file.hxx:16
static constexpr ErrorCode E_FileFailedToBindToAIOPort
Definition native_file.hxx:15
FileRequestStatus
Definition native_file.hxx:55
@ Completed
Definition native_file.hxx:58
@ Pending
Definition native_file.hxx:57
@ Error
Definition native_file.hxx:56
auto write_file(ice::native_file::File const &native_file, ice::usize write_offset, ice::Data data) noexcept -> ice::usize
EntityType
Definition native_file.hxx:119
@ File
Definition native_file.hxx:119
@ Directory
Definition native_file.hxx:119
void path_from_string(ice::native_file::HeapFilePath &out_filepath, ice::String path_string) noexcept
FileOpenFlags
Definition native_file.hxx:37
@ Write
Opens the file for write operations.
Definition native_file.hxx:45
@ Asynchronous
Opens the file for asynchronous read-only operations.
Definition native_file.hxx:51
@ Exclusive
Opens the file in exclusive mode.
Definition native_file.hxx:48
@ Read
Opens the file for read operations.
Definition native_file.hxx:42
void path_join_string(ice::native_file::HeapFilePath &path, ice::String string) noexcept
auto read_file(ice::native_file::File const &native_file, ice::usize requested_read_size, ice::Memory memory) noexcept -> ice::usize
bool traverse_directories(ice::native_file::FilePath starting_dir, ice::native_file::TraversePathCallback callback, void *userdata) noexcept
TraverseAction
Definition native_file.hxx:118
@ Continue
Definition native_file.hxx:118
@ Break
Definition native_file.hxx:118
@ SkipSubDir
Definition native_file.hxx:118
void path_to_string(ice::native_file::FilePath path, ice::HeapString<> &out_string) noexcept
auto write_file_request(ice::native_aio::AIORequest &request, ice::native_file::File const &native_file, ice::usize write_offset, ice::Data data) noexcept -> ice::native_file::FileRequestStatus
auto append_file(ice::native_file::File const &native_file, ice::Data data) noexcept -> ice::usize
bool is_directory(ice::native_file::FilePath path) noexcept
Definition path_utils.hxx:10
ice::BasicString< char > String
Definition string.hxx:82
auto alloc(ice::usize size) noexcept -> ice::AllocResult
ice::AllocatorBase< ice::build::is_debug||ice::build::is_develop > Allocator
Definition mem_types.hxx:25
constexpr bool has_all(T value, T expected_flags) noexcept
Definition enum_flags.hxx:77
std::uint8_t u8
Definition types.hxx:24
Definition path_utils.hxx:161
Definition path_utils.hxx:149
Definition mem_data.hxx:17
Definition error.hxx:19
Definition heap_string.hxx:15
Definition mem_memory.hxx:13
Definition native_aio.hxx:36
Represents a unsigned size value on the given platform.
Definition mem_size_types.hxx:26