CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
vfsfile.h
Go to the documentation of this file.
1
5
6#pragma once
7// This header file is auto-generated!
8// Do not make changes to this file or they will be overwritten.
9// clang-format off
10#include <cx/obj.h>
11#include <cx/struct.h>
12#include <cx/fs/fileobj.h>
13#include <cx/fs/vfsobj.h>
14
15CX_C_BEGIN
16
17typedef struct VFSDir VFSDir;
18typedef struct VFSFile VFSFile;
19typedef struct VFSFile_WeakRef VFSFile_WeakRef;
21saDeclarePtr(VFSFile_WeakRef);
22#define _sti_VFSFile _sti_object
23#define SType_VFSFile VFSFile*
24#define STStorageType_VFSFile VFSFile*
25#define STypeArg_VFSFile(type, val) stgeneric(object, (ObjInst*)objInstCheckClass(VFSFile, val))
26#define STypeArgPtr_VFSFile(type, val) (stgeneric*)objInstCheckClassPtr(VFSFile, val)
27#define STypeCheckedArg_VFSFile(type, val) stType(type), stArg(type, val)
28#define STypeCheckedPtrArg_VFSFile(type, val) stType(type), stArgPtr(type, val)
29
30
31
32typedef struct VFSFile_ClassIf {
33 ObjIface* _implements;
34 ObjIface* _parent;
35 size_t _size;
36
37 // Flushes pending writes and closes the underlying handle without releasing the File.
38 // Implemented by each kind of File; callers use fileClose() instead. Further reads and
39 // writes fail, and closing an already closed file must be harmless. Returns true if
40 // successful, false if flushing or closing failed or if self was NULL.
41 bool (*closeHandle)(_In_ void* self);
42 bool (*read)(_In_ void* self, _Out_writes_bytes_to_(sz, *bytesread) void* buf, size_t sz, _Out_ _Deref_out_range_(0, sz) size_t* bytesread);
43 bool (*write)(_In_ void* self, _In_reads_bytes_(sz) const void* buf, size_t sz, _Out_opt_ _Deref_out_range_(0, sz) size_t* byteswritten);
44 int64 (*tell)(_In_ void* self);
45 int64 (*seek)(_In_ void* self, int64 off, FSSeekType seektype);
46 bool (*flush)(_In_ void* self);
47} VFSFile_ClassIf;
48extern VFSFile_ClassIf VFSFile_ClassIf_tmpl;
49
55typedef struct VFSFile {
56 union {
57 VFSFile_ClassIf* _;
58 void* _is_VFSFile;
59 void* _is_File;
60 void* _is_ObjInst;
61 };
62 ObjClassInfo* _clsinfo;
63 atomic(uintptr) _ref;
64 atomic(ptr) _weakref;
65
66 VFS* vfs;
67 File* inner; // the provider's file, which every operation ends up at
68 // for copy-on-write files
69 // VFSProvider
70 ObjInst* cowprov;
71 string cowpath; // absolute path to COW file (for cache invalidation)
72 string cowrpath; // relative path for COW file for provider
73} VFSFile;
74extern ObjClassInfo VFSFile_clsinfo;
75#define VFSFile(inst) objInstCheckClass(VFSFile, inst)
76#define VFSFileNone ((VFSFile*)NULL)
77
78typedef struct VFSFile_WeakRef {
79 union {
80 ObjInst* _inst;
81 void* _is_VFSFile_WeakRef;
82 void* _is_File_WeakRef;
83 void* _is_ObjInst_WeakRef;
84 };
85 atomic(uintptr) _ref;
86 RWLock _lock;
87} VFSFile_WeakRef;
88#define VFSFile_WeakRef(inst) objWeakRefCheckClass(VFSFile, inst)
89
90_objfactory_guaranteed VFSFile* VFSFile_create(VFS* vfs, File* inner);
91// VFSFile* vfsfileCreate(VFS* vfs, File* inner);
92#define vfsfileCreate(vfs, inner) VFSFile_create(VFS(vfs), File(inner))
93
103#define vfsfileWriteString(self, str, byteswritten) File_writeString(File(self), str, byteswritten)
104
105// bool vfsfileCloseHandle(VFSFile* self);
106//
107// Flushes pending writes and closes the underlying handle without releasing the File.
108// Implemented by each kind of File; callers use fileClose() instead. Further reads and
109// writes fail, and closing an already closed file must be harmless. Returns true if
110// successful, false if flushing or closing failed or if self was NULL.
111#define vfsfileCloseHandle(self) ((self) ? ((self)->_->closeHandle(VFSFile(self))) : false)
112// bool vfsfileRead(VFSFile* self, void* buf, size_t sz, size_t* bytesread);
113#define vfsfileRead(self, buf, sz, bytesread) ((self) ? ((self)->_->read(VFSFile(self), buf, sz, bytesread)) : false)
114// bool vfsfileWrite(VFSFile* self, const void* buf, size_t sz, size_t* byteswritten);
115#define vfsfileWrite(self, buf, sz, byteswritten) ((self) ? ((self)->_->write(VFSFile(self), buf, sz, byteswritten)) : false)
116// int64 vfsfileTell(VFSFile* self);
117#define vfsfileTell(self) ((self) ? ((self)->_->tell(VFSFile(self))) : -1)
118// int64 vfsfileSeek(VFSFile* self, int64 off, FSSeekType seektype);
119#define vfsfileSeek(self, off, seektype) ((self) ? ((self)->_->seek(VFSFile(self), off, seektype)) : -1)
120// bool vfsfileFlush(VFSFile* self);
121#define vfsfileFlush(self) ((self) ? ((self)->_->flush(VFSFile(self))) : false)
122
123CX_C_END
#define saDeclarePtr(name)
Definition sarray.h:100
enum FSSeekTypeEnum FSSeekType
#define _objfactory_guaranteed
Definition objimpl.h:106
CX Struct System - Introspectable, serializable POD structures in C.
CX Object System - Object-oriented programming in C.
Definition fileobj.h:59
VFS Object.
Definition vfsobj.h:51
VFS object definitions.