💾 Archived View for gmi.noulin.net › gitRepositories › blockFile › file › blockFile.h.gmi captured on 2024-07-09 at 00:10:03. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-01-29)
-=-=-=-=-=-=-
blockFile.h (4202B)
1 #pragma once 2 3 /* Add class methods and class data where there are the TODOs (TODO)*/ 4 5 #define openBFO(obj, fn) (obj)->f->open(obj, fn) 6 #define closeBFO(obj) (obj)->f->close(obj) 7 #define addBFO(obj, buffer, len) (obj)->f->add(obj, buffer, len) 8 #define getBFO(obj, block) (obj)->f->get(obj, block) 9 #define removeBFO(obj, block) (obj)->f->remove(obj, block) 10 #define loadBFO(obj, closure, callback) (obj)->f->load(obj, closure, callback) 11 12 /* TODO add generics: #define amethodG(obj) (obj)->f->amethod(obj) */ 13 14 /* Class blockFile */ 15 typedef struct blockFile blockFilet; 16 17 /* for object inheriting blockFile, cast to blockFile to be able to use this class functions and generics*/ 18 #define cBlockFile(self) ( (blockFilet*) self ) 19 20 typedef enum {NOT_COMPRESSED, COMPRESSED} flagsBlockFilet; 21 22 typedef struct { 23 void *data; 24 u64 len; 25 } bufBlockFilet; 26 27 typedef void (*freeBlockFileFt) (blockFilet *self); 28 typedef void (*terminateBlockFileFt) (blockFilet **self); 29 typedef char* (*toStringBlockFileFt) (blockFilet *self); 30 typedef blockFilet* (*duplicateBlockFileFt) (blockFilet *self); 31 typedef void (*smashBlockFileFt) (blockFilet **self); 32 33 /** 34 * free blockFile 35 */ 36 typedef void (*finishBlockFileFt) (blockFilet **self); 37 38 /* TODO add function typedef with pattern: functionNameClassTempleFt */ 39 40 typedef bool (*openBlockFileFt) (blockFilet *self, const char *filename); 41 typedef void (*closeBlockFileFt) (blockFilet *self); 42 typedef void (*deleteBlockFileFt) (blockFilet *self); 43 typedef void (*deleteFBlockFileFt) (char *filename); 44 typedef u64 (*addBlockBlockFileFt) (blockFilet *self, void* buf, i64 len, flagsBlockFilet flags); 45 typedef u64 (*addBlockFileFt) (blockFilet *self, void* buf, i64 len); 46 typedef bufBlockFilet (*getBlockFileFt) (blockFilet *self, u64 block); 47 typedef bool (*removeBlockFileFt) (blockFilet *self, u64 block); 48 49 /** 50 * callback parameter for the load function 51 */ 52 typedef bool (*loadFBlockFileFt)(void *closure, u64 block, bufBlockFilet data); 53 54 /** 55 * load 56 */ 57 typedef bool (*loadBlockFileFt) (blockFilet *self, void *closure, loadFBlockFileFt callback); 58 59 /** 60 * class functions 61 * allocated once for all objects 62 * 63 * freed with finalizeBlockFile 64 */ 65 66 /** 67 * use this define in child classes and add the new function after this class functions 68 * 69 * in this define, add the methods after <finishBlockFileFt finish;> 70 * 71 * Example: 72 * #define RINGFUNCTIONST \n * BLOCKFILEFUNCTIONST; \n * setSizeRingFt setSize 73 */ 74 #define BLOCKFILEFUNCTIONST \ 75 openBlockFileFt open;\ 76 closeBlockFileFt close;\ 77 deleteBlockFileFt delete;\ 78 deleteFBlockFileFt deleteF;\ 79 addBlockBlockFileFt addBlock;\ 80 addBlockFileFt add;\ 81 getBlockFileFt get;\ 82 removeBlockFileFt remove;\ 83 loadBlockFileFt load; 84 /* TODO ADD METHODS AFTER <finishBlockFileFt finish;> HERE */ 85 86 typedef struct { 87 freeBlockFileFt free; 88 terminateBlockFileFt terminate; 89 toStringBlockFileFt toString; 90 duplicateBlockFileFt duplicate; 91 smashBlockFileFt smash; 92 finishBlockFileFt finish; 93 BLOCKFILEFUNCTIONST; 94 } blockFileFunctionst; 95 96 /** 97 * class 98 */ 99 100 typedef struct privateBlockFile privateBlockFilet; 101 102 struct blockFile { 103 const char *type; 104 blockFileFunctionst *f; 105 106 privateBlockFilet *file; 107 /* TODO add class data */ 108 }; 109 110 /* blockFile */ 111 112 #define createBlockFile(obj) blockFilet obj; initiateBlockFile(&obj) 113 #define createAllocateBlockFile(obj) blockFilet *obj; initiateAllocateBlockFile(&obj) 114 115 void initiateBlockFile(blockFilet *self); 116 void initiateAllocateBlockFile(blockFilet **self); 117 void finalizeBlockFile(void); 118 119 /* initialize class methods, call registerMethodsBlockFile from classes inheriting this class */ 120 void registerMethodsBlockFile(blockFileFunctionst *f); 121 122 blockFilet* allocBlockFile(char* filename); 123 124 /* end class blockFile*/ 125 126 #define isBlockFileCompiledWithCurrentLisheepyVersion checkLibsheepyVersionBlockFile(LIBSHEEPY_VERSION) 127 bool checkLibsheepyVersionBlockFile(const char *currentLibsheepyVersion);