MGL(Win32)
読み取り中…
検索中…
一致する文字列を見つけられません
mgl_file_delegate_nsfile.h
[詳解]
1/* ------------------------------------------------------------------------- */
8/* ------------------------------------------------------------------------- */
9
10#ifndef INCGUARD_MGL_FILE_DELEGATE_NSFILE_H_1691390916
11#define INCGUARD_MGL_FILE_DELEGATE_NSFILE_H_1691390916
12
13#include <mgl/mgl_environment.h>
14#if defined(MGL_FILE_DELEGATE_ENABLE_NSFILE)
15
16#include <stdio.h>
17
19
20#if defined(__OBJC__)
21#import <Foundation/NSError.h>
22#endif
23
24namespace MGL::File
25{
26// C++からはNSErrorを参照できないので前方宣言で誤魔化す
27#if !defined(__OBJC__)
28class NSError;
29#endif
30
32class NSFileDelegate : public Delegate
33{
34public:
36 inline static constexpr DelegateKey kDelegateKey = MakeDelegateKey("MGL-NSFile");
37
38 /* ------------------------------------------------------------------------- */
44 /* ------------------------------------------------------------------------- */
45 virtual bool IsManagedSystemNativeFile() const noexcept override
46 {
47 return true; // 扱う
48 }
49
50 /* ------------------------------------------------------------------------- */
56 /* ------------------------------------------------------------------------- */
57 virtual bool IsWritable() const noexcept override
58 {
59 return true; // 対応している
60 }
61
62 /* ------------------------------------------------------------------------- */
70 /* ------------------------------------------------------------------------- */
71 virtual Result Mount([[maybe_unused]] SharedMountWork &mountWork, [[maybe_unused]] const PathView &path, [[maybe_unused]] MountAccessType accessType) noexcept override
72 {
73 return Result::Succeeded(); // このデリゲートはマウントワークを使用しないので何もせずに成功を返す
74 }
75
76 /* ------------------------------------------------------------------------- */
81 /* ------------------------------------------------------------------------- */
82 virtual void Unmount([[maybe_unused]] SharedMountWork &mountWork) noexcept override
83 {
84 return;
85 }
86
87 virtual AccessWorkPtr Open(Result &result, SharedMountWork &mountWork, const PathView &path, OpenMode mode) noexcept override;
88 virtual Result Close(AccessWork *work) noexcept override;
89 virtual size_t Read(AccessWork *work, Result &result, void *buffer, size_t size) noexcept override;
90 virtual size_t Write(AccessWork *work, Result &result, const void *buffer, size_t size) noexcept override;
91 virtual size_t Seek(AccessWork *work, Result &result, SeekType seekType, int32_t offset) noexcept override;
92 virtual size_t GetOffset(AccessWork *work, Result &result) const noexcept override;
93 virtual bool IsEOF(AccessWork *work, Result &result) const noexcept override;
94 virtual size_t GetSize(AccessWork *work, Result &result) const noexcept override;
95 virtual size_t GetSize(MountWork *mountWork, Result &result, const PathView &path) const noexcept override;
96 virtual Result MakeDirectory(MountWork *mountWork, const PathView &path) noexcept override;
97 virtual Result Move(MountWork *mountWork, const PathView &sourcePath, const PathView &destPath) noexcept override;
98 virtual Result Remove(MountWork *mountWork, const PathView &path) noexcept override;
99 virtual bool Exists(MountWork *mountWork, Result &result, const PathView &path) noexcept override;
100
102 struct NSFileWork : public AccessWork
103 {
104 FILE *fp;
105 size_t size;
106
108 NSFileWork(OpenMode mode) noexcept
109 : AccessWork(mode, kDelegateKey)
110 , fp(nullptr)
111 , size(0)
112 {}
113 };
114
115protected:
116 NSFileWork *GetWork(AccessWork *work, OpenMode mode = OpenMode::None) const noexcept;
117 const char *GetModeString(OpenMode mode) const noexcept;
118 Error GetError(int errorNumber) const noexcept;
119 Error GetError(const NSError *nsError) const noexcept;
120};
121} // namespace MGL::File
122
123#endif // MGL_FILE_DELEGATE_ENABLE_NSFILE
124#endif // INCGUARD_MGL_FILE_DELEGATE_NSFILE_H_1691390916
125
126// 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 ファイルデリゲート