libsheepyCClassTemplate.h (2245B)
1 #pragma once 2 // Class classTemplate 3 typedef struct classTemplate classTemplatet; 4 5 // for object inheriting classTemplate, cast to classTemplate to be able to use this class functions and generics 6 #define cClassTemplate(self) ( (classTemplatet*) self ) 7 8 typedef void (*freeClassTemplateFt) (classTemplatet *self); 9 typedef void (*terminateClassTemplateFt) (classTemplatet **self); 10 typedef char* (*toStringClassTemplateFt) (classTemplatet *self); 11 typedef classTemplatet* (*duplicateClassTemplateFt) (classTemplatet *self); 12 typedef void (*smashClassTemplateFt) (classTemplatet **self); 13 14 /** 15 * free classTemplate 16 */ 17 typedef void (*finishClassTemplateFt) (classTemplatet **self); 18 19 /** 20 * class functions 21 * allocated once for all objects 22 * 23 * freed with finalizeClassTemplate or finalizeLibsheepy 24 */ 25 26 /** 27 * use this define in child classes and add the new function after this class functions 28 * 29 * in this define, add the methods after <finishClassTemplateFt finish;> 30 * 31 * Example: 32 * #define RINGFUNCTIONST \ 33 * CLASSTEMPLATEFUNCTIONST; \ 34 * setSizeRingFt setSize 35 */ 36 #define CLASSTEMPLATEFUNCTIONST \ 37 /* TODO ADD METHODS AFTER <finishClassTemplateFt finish;> HERE */ 38 39 typedef struct { 40 freeClassTemplateFt free; 41 terminateClassTemplateFt terminate; 42 toStringClassTemplateFt toString; 43 duplicateClassTemplateFt duplicate; 44 smashClassTemplateFt smash; 45 finishClassTemplateFt finish; 46 CLASSTEMPLATEFUNCTIONST; 47 } classTemplateFunctionst; 48 49 /** 50 * class 51 */ 52 struct classTemplate { 53 const char *type; 54 classTemplateFunctionst *f; 55 }; 56 57 // classTemplate 58 59 #define createClassTemplate(obj) ;classTemplatet obj; initiateClassTemplate(&obj) 60 #define createAllocateClassTemplate(obj) ;classTemplatet *obj; initiateAllocateClassTemplate(&obj) 61 62 void initiateClassTemplate(classTemplatet *self); 63 void initiateAllocateClassTemplate(classTemplatet **self); 64 void finalizeClassTemplate(void); 65 66 // initialize class methods, call registerMethodsClassTemplate from classes inheriting this class 67 void registerMethodsClassTemplate(classTemplateFunctionst *f); 68 69 classTemplatet* allocClassTemplate(/*TODO INIT DATA */); 70 71 // end class classTemplate