CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
fileobj.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/fs.h>
13
14CX_C_BEGIN
15
16typedef struct File File;
17typedef struct File_WeakRef File_WeakRef;
19saDeclarePtr(File_WeakRef);
20#define _sti_File _sti_object
21#define SType_File File*
22#define STStorageType_File File*
23#define STypeArg_File(type, val) stgeneric(object, (ObjInst*)objInstCheckClass(File, val))
24#define STypeArgPtr_File(type, val) (stgeneric*)objInstCheckClassPtr(File, val)
25#define STypeCheckedArg_File(type, val) stType(type), stArg(type, val)
26#define STypeCheckedPtrArg_File(type, val) stType(type), stArgPtr(type, val)
27
28
29
30typedef struct File_ClassIf {
31 ObjIface* _implements;
32 ObjIface* _parent;
33 size_t _size;
34
35 // Flushes pending writes and closes the underlying handle without releasing the File.
36 // Implemented by each kind of File; callers use fileClose() instead. Further reads and
37 // writes fail, and closing an already closed file must be harmless. Returns true if
38 // successful, false if flushing or closing failed or if self was NULL.
39 bool (*closeHandle)(_In_ void* self);
40 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);
41 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);
42 int64 (*tell)(_In_ void* self);
43 int64 (*seek)(_In_ void* self, int64 off, FSSeekType seektype);
44 bool (*flush)(_In_ void* self);
45} File_ClassIf;
46extern File_ClassIf File_ClassIf_tmpl;
47
59typedef struct File {
60 union {
61 File_ClassIf* _;
62 void* _is_File;
63 void* _is_ObjInst;
64 };
65 ObjClassInfo* _clsinfo;
66 atomic(uintptr) _ref;
67 atomic(ptr) _weakref;
68
69} File;
70extern ObjClassInfo File_clsinfo;
71#define File(inst) objInstCheckClass(File, inst)
72#define FileNone ((File*)NULL)
73
74typedef struct File_WeakRef {
75 union {
76 ObjInst* _inst;
77 void* _is_File_WeakRef;
78 void* _is_ObjInst_WeakRef;
79 };
80 atomic(uintptr) _ref;
81 RWLock _lock;
82} File_WeakRef;
83#define File_WeakRef(inst) objWeakRefCheckClass(File, inst)
84
85bool File_writeString(_In_ File* self, _In_opt_ strref str, _Out_opt_ size_t* byteswritten);
95#define fileWriteString(self, str, byteswritten) File_writeString(File(self), str, byteswritten)
96
97// bool fileCloseHandle(File* self);
98//
99// Flushes pending writes and closes the underlying handle without releasing the File.
100// Implemented by each kind of File; callers use fileClose() instead. Further reads and
101// writes fail, and closing an already closed file must be harmless. Returns true if
102// successful, false if flushing or closing failed or if self was NULL.
103#define fileCloseHandle(self) ((self) ? ((self)->_->closeHandle(File(self))) : false)
116#define fileRead(self, buf, sz, bytesread) ((self) ? ((self)->_->read(File(self), buf, sz, bytesread)) : false)
129#define fileWrite(self, buf, sz, byteswritten) ((self) ? ((self)->_->write(File(self), buf, sz, byteswritten)) : false)
135#define fileTell(self) ((self) ? ((self)->_->tell(File(self))) : -1)
143#define fileSeek(self, off, seektype) ((self) ? ((self)->_->seek(File(self), off, seektype)) : -1)
152#define fileFlush(self) ((self) ? ((self)->_->flush(File(self))) : false)
153
154CX_C_END
Platform-specific filesystem operations.
#define saDeclarePtr(name)
Definition sarray.h:100
enum FSSeekTypeEnum FSSeekType
CX Struct System - Introspectable, serializable POD structures in C.
CX Object System - Object-oriented programming in C.
Definition fileobj.h:59