MGL(Win32)
読み取り中…
検索中…
一致する文字列を見つけられません
mgl_file_delegate_posix.h
[詳解]
1// SPDX-License-Identifier: Zlib
2/* ------------------------------------------------------------------------- */
9/* ------------------------------------------------------------------------- */
10
11#ifndef INCGUARD_MGL_FILE_DELEGATE_POSIX_H_1611110145
12#define INCGUARD_MGL_FILE_DELEGATE_POSIX_H_1611110145
13
14#include <mgl/mgl_environment.h>
15#if defined(MGL_FILE_DELEGATE_ENABLE_POSIX)
16
17#include <cstdio>
18
20
21namespace MGL::File
22{
24class POSIXDelegate : public Delegate
25{
26public:
28 static constexpr DelegateKey kDelegateKey = MakeDelegateKey("MGL-POSIX");
29
30 /* ------------------------------------------------------------------------- */
36 /* ------------------------------------------------------------------------- */
37 [[nodiscard]] bool IsManagedSystemNativeFile() const noexcept override
38 {
39 return true; // 扱う
40 }
41
42 /* ------------------------------------------------------------------------- */
48 /* ------------------------------------------------------------------------- */
49 [[nodiscard]] bool IsWritable() const noexcept override
50 {
51 return true; // 対応している
52 }
53
54 /* ------------------------------------------------------------------------- */
62 /* ------------------------------------------------------------------------- */
63 Result Mount([[maybe_unused]] SharedMountWork &mountWork, [[maybe_unused]] const PathView &path, [[maybe_unused]] MountAccessType accessType) noexcept override
64 {
65 return Result::Succeeded(); // このデリゲートはマウントワークを使用しないので何もせずに成功を返す
66 }
67
68 /* ------------------------------------------------------------------------- */
73 /* ------------------------------------------------------------------------- */
74 void Unmount([[maybe_unused]] SharedMountWork &mountWork) noexcept override
75 {
76 }
77
78 AccessWorkPtr Open(Result &result, SharedMountWork &mountWork, const PathView &path, OpenMode mode) noexcept override;
79 Result Close(AccessWork *work) noexcept override;
80 size_t Read(AccessWork *work, Result &result, void *buffer, size_t size) noexcept override;
81 size_t Write(AccessWork *work, Result &result, const void *buffer, size_t size) noexcept override;
82 size_t Seek(AccessWork *work, Result &result, SeekType seekType, int32_t offset) noexcept override;
83 size_t GetOffset(AccessWork *work, Result &result) const noexcept override;
84 bool IsEOF(AccessWork *work, Result &result) const noexcept override;
85 size_t GetSize(AccessWork *work, Result &result) const noexcept override;
86 size_t GetSize(MountWork *mountWork, Result &result, const PathView &path) const noexcept override;
87 Result MakeDirectory(MountWork *mountWork, const PathView &path) noexcept override;
88 Result Move(MountWork *mountWork, const PathView &sourcePath, const PathView &destPath) noexcept override;
89 Result Remove(MountWork *mountWork, const PathView &path) noexcept override;
90 bool Exists(MountWork *mountWork, Result &result, const PathView &path) noexcept override;
91
93 struct POSIXWork : public AccessWork
94 {
95 FILE *fp{nullptr};
96 size_t size{0};
97
99 POSIXWork(OpenMode mode) noexcept
100 : AccessWork(mode, kDelegateKey)
101 {
102 }
103 };
104
105protected:
106 static POSIXWork *GetWork(AccessWork *work, OpenMode mode = OpenMode::None) noexcept;
107 [[nodiscard]] static const char *GetModeString(OpenMode mode) noexcept;
108 [[nodiscard]] static Error GetError(int errorNumber) noexcept;
109};
110} // namespace MGL::File
111
112#endif // MGL_FILE_DELEGATE_ENABLE_POSIX
113#endif // INCGUARD_MGL_FILE_DELEGATE_POSIX_H_1611110145
114
115// vim: et ts=4 sw=4 sts=4
MGL 環境定義
STL::unique_ptr< AccessWork > AccessWorkPtr
ファイルアクセスのためのワークのポインタ型
Definition mgl_file_access_work.h:130
Result Close(AccessWorkPtr &work) noexcept
ファイルをクローズ
Definition mgl_file_accessor.cc:138
size_t GetOffset(AccessWorkPtr &work, Result &result) noexcept
ストリーム位置を取得
Definition mgl_file_accessor.cc:300
Result MakeDirectory(const PathView &path) noexcept
ディレクトリを作成する
Definition mgl_file_accessor.cc:439
AccessWorkPtr Open(Result &result, const PathView &path, OpenMode mode) noexcept
ファイルをオープン
Definition mgl_file_accessor.cc:94
Result Remove(const PathView &path) noexcept
ファイルの削除
Definition mgl_file_accessor.cc:510
size_t Seek(AccessWorkPtr &work, Result &result, SeekType seekType, int32_t offset) noexcept
ストリーム位置を設定
Definition mgl_file_accessor.cc:257
size_t Read(AccessWorkPtr &work, Result &result, void *buffer, size_t size) noexcept
ファイルを読み込み
Definition mgl_file_accessor.cc:181
Result Unmount(const PathView &mountName) noexcept
マウント解除
Definition mgl_file_accessor.cc:678
size_t GetSize(AccessWorkPtr &work, Result &result) noexcept
オープンしているファイルのサイズを取得
Definition mgl_file_accessor.cc:374
Result Mount(const PathView &mountName, const PathView &path, MountAccessType accessType, DelegateKey delegateKey=Mounter::kDefaultDelegateKey) noexcept
マウント
Definition mgl_file_accessor.cc:658
bool IsEOF(AccessWorkPtr &work, Result &result) noexcept
ファイルストリームが終端に達しているかを取得
Definition mgl_file_accessor.cc:338
size_t Write(AccessWorkPtr &work, Result &result, const void *buffer, size_t size) noexcept
ファイルに書き込み
Definition mgl_file_accessor.cc:219
Result Move(const PathView &sourcePath, const PathView &destPath) noexcept
ファイルの移動・リネーム
Definition mgl_file_accessor.cc:463
bool Exists(Result &result, const PathView &path) noexcept
ファイルの存在をチェック
Definition mgl_file_accessor.cc:598
DelegateKey
デリゲートキーの型
Definition mgl_file_defs.h:23
Error
エラー定義
Definition mgl_file_defs.h:71
MGL::ResultWrapper< Error, Error::None, Error::NoOperation > Result
ファイル関連の処理結果
Definition mgl_file_defs.h:106
constexpr DelegateKey MakeDelegateKey(const char *keyString, uint32_t seed=kDefaultDelegateKeySeed) noexcept
デリゲートキーの生成
Definition mgl_file_defs.h:36
MGL ファイルデリゲート