libsheepyCSmallDouble.h (14542B)
1 // MIT License 2 // 3 // Copyright (c) 2026 Remy Noulin 4 // 5 // Permission is hereby granted, free of charge, to any person obtaining a copy 6 // of this software and associated documentation files (the "Software"), to deal 7 // in the Software without restriction, including without limitation the rights 8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 // copies of the Software, and to permit persons to whom the Software is 10 // furnished to do so, subject to the following conditions: 11 // 12 // The above copyright notice and this permission notice shall be included in all 13 // copies or substantial portions of the Software. 14 // 15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 // SOFTWARE. 22 #pragma once 23 24 // Class smallDouble 25 typedef struct smallDouble smallDoublet; 26 27 /** 28 * help text for this class 29 * It is public declaration so that child classes can add their help text easily: 30 * ret "Child help text \n\n" helpTextSmallDouble; 31 */ 32 #define helpTextSmallDouble "TODO smallDouble help brief, class description /*, definitions,*/ methods, examples" 33 34 // for object inheriting smallDouble, cast to smallDouble to be able to use this class functions and generics 35 #define cDo(self) ( (smallDoublet*) self ) 36 37 typedef void (*freeSmallDoubleFt) (smallDoublet *self); 38 typedef void (*terminateSmallDoubleFt) (smallDoublet **self); 39 typedef char* (*toStringSmallDoubleFt) (smallDoublet *self); 40 typedef smallDoublet* (*duplicateSmallDoubleFt) (smallDoublet *self); 41 42 // smallDouble functions 43 /** 44 * free self but not the smallDouble buffer 45 * 46 * Useful when smallDouble buffer is shared or 47 * when the buffer holds a static smallDouble 48 */ 49 typedef void (*smashSmallDoubleFt) (smallDoublet **self); 50 51 /** 52 * free container 53 */ 54 typedef void (*finishSmallDoubleFt) (smallDoublet **self); 55 56 typedef const char* (*helpSmallDoubleFt) (smallDoublet *self); 57 58 /** 59 * get double 60 * 61 * \return 62 * double 63 */ 64 typedef double (*getSmallDoubleFt) (smallDoublet *self); 65 66 /** 67 * set double 68 * 69 * \param 70 * double to store in object 71 */ 72 typedef smallDoublet* (*setSmallDoubleFt) (smallDoublet *self, double value); 73 74 typedef smallDoublet* (*setBoolSmallDoubleFt)(smallDoublet* self, bool p2); 75 typedef smallDoublet* (*setSmallDoubleFt)(smallDoublet* self, double p2); 76 typedef smallDoublet* (*setInt64SmallDoubleFt)(smallDoublet* self, int64_t p2); 77 typedef smallDoublet* (*setInt32SmallDoubleFt)(smallDoublet* self, int32_t p2); 78 typedef smallDoublet* (*setUint32SmallDoubleFt)(smallDoublet* self, uint32_t p2); 79 typedef smallDoublet* (*setUint64SmallDoubleFt)(smallDoublet* self, uint64_t p2); 80 typedef smallDoublet* (*setSSmallDoubleFt)(smallDoublet* self, const char* p2); 81 typedef smallDoublet* (*setSmallBoolSmallDoubleFt)(smallDoublet* self, smallBoolt* p2); 82 typedef smallDoublet* (*setSmallDoubleSmallDoubleFt)(smallDoublet* self, smallDoublet* p2); 83 typedef smallDoublet* (*setSmallIntSmallDoubleFt)(smallDoublet* self, smallIntt* p2); 84 typedef smallDoublet* (*setSmallJsonSmallDoubleFt)(smallDoublet* self, smallJsont* p2); 85 typedef smallDoublet* (*setSmallStringSmallDoubleFt)(smallDoublet* self, smallStringt* p2); 86 87 /** 88 * get a pointer to double 89 * 90 * \return 91 * double* 92 */ 93 typedef double* (*getPSmallDoubleFt) (smallDoublet *self); 94 95 typedef bool (*equalSmallDoubleChaFt)(smallDoublet* self, char p2); 96 typedef bool (*equalSmallDoubleCharFt)(smallDoublet* self, const char * p2); 97 typedef bool (*equalSmallDoubleBaseFt)(smallDoublet* self, baset* p2); 98 typedef bool (*equalSmallDoubleBoolFt)(smallDoublet* self, bool p2); 99 typedef bool (*equalSmallDoubleDoubleFt)(smallDoublet* self, double p2); 100 typedef bool (*equalSmallDoubleInt64Ft)(smallDoublet* self, int64_t p2); 101 typedef bool (*equalSmallDoubleInt32Ft)(smallDoublet* self, int32_t p2); 102 typedef bool (*equalSmallDoubleUint32Ft)(smallDoublet* self, uint32_t p2); 103 typedef bool (*equalSmallDoubleUint64Ft)(smallDoublet* self, uint64_t p2); 104 typedef bool (*equalSmallDoubleSmallBoolFt)(smallDoublet* self, smallBoolt* p2); 105 typedef bool (*equalSmallDoubleSmallBytesFt)(smallDoublet* self, smallBytest* p2); 106 typedef bool (*equalSmallDoubleFt)(smallDoublet* self, smallDoublet* p2); 107 typedef bool (*equalSmallDoubleSmallIntFt)(smallDoublet* self, smallIntt* p2); 108 typedef bool (*equalSmallDoubleSmallJsonFt)(smallDoublet* self, smallJsont* p2); 109 typedef bool (*equalSmallDoubleSmallStringFt)(smallDoublet* self, smallStringt* p2); 110 111 /** 112 * read file to double 113 * 114 * \param 115 * filePath: path to file 116 * \return 117 * 0 data in file 118 * -1 an error occured 119 */ 120 typedef smallDoublet* (*readFileSmallDoubleFt)(smallDoublet *self, const char *filePath); 121 typedef smallDoublet* (*readFileSmallJsonSmallDoubleFt)(smallDoublet *self, smallJsont *filePath); 122 typedef smallDoublet* (*readFileSmallStringSmallDoubleFt)(smallDoublet *self, smallStringt *filePath); 123 typedef smallDoublet* (*readStreamSmallDoubleFt)(smallDoublet *self, FILE *fp); 124 125 /** 126 * write double to file 127 * 128 * \param 129 * filePath path to file 130 * \return 131 * 1 success 132 * 0 error 133 */ 134 typedef int (*writeFileSmallDoubleFt) (smallDoublet *self, const char *filePath); 135 typedef int (*writeFileSmallJsonSmallDoubleFt) (smallDoublet *self, smallJsont *filePath); 136 typedef int (*writeFileSmallStringSmallDoubleFt)(smallDoublet *self, smallStringt *filePath); 137 typedef int (*writeStreamSmallDoubleFt) (smallDoublet *self, FILE *fp); 138 139 /** 140 * append double to filePath 141 * 142 * \param 143 * filePath 144 * \return 145 * true success 146 * false failed, filePath 147 */ 148 typedef int (*appendFileSmallDoubleFt)(smallDoublet *self, const char *filePath); 149 typedef int (*appendFileSmallStringSmallDoubleFt)(smallDoublet *self, smallStringt *filePath); 150 151 /** 152 * class functions 153 * allocated once for all objects 154 * 155 * freed with finalizeSmallDouble or finalizeLibsheepy 156 */ 157 158 /** 159 * use this define in child classes and add the new function after this class functions 160 * 161 * in this define, add the methods after <finishClassTemplateFt finish;> 162 * 163 * Example: 164 * #define RINGFUNCTIONST \ 165 * CLASSTEMPLATEFUNCTIONST; \ 166 * setSizeRingFt setSize 167 */ 168 #define SMALLDOUBLEFUNCTIONST \ 169 helpSmallDoubleFt help;\ 170 getSmallDoubleFt get;\ 171 setSmallDoubleFt set;\ 172 setBoolSmallDoubleFt setBool;\ 173 setInt64SmallDoubleFt setInt64;\ 174 setInt32SmallDoubleFt setInt32;\ 175 setUint32SmallDoubleFt setUint32;\ 176 setUint64SmallDoubleFt setUint64;\ 177 setSSmallDoubleFt setS;\ 178 setSmallBoolSmallDoubleFt setSmallBool;\ 179 setSmallDoubleSmallDoubleFt setSmallDouble;\ 180 setSmallIntSmallDoubleFt setSmallInt;\ 181 setSmallJsonSmallDoubleFt setSmallJson;\ 182 setSmallStringSmallDoubleFt setSmallString;\ 183 getPSmallDoubleFt getP;\ 184 equalSmallDoubleChaFt equalCha;\ 185 equalSmallDoubleCharFt equalChar;\ 186 equalSmallDoubleBaseFt equalBase;\ 187 equalSmallDoubleBoolFt equalBool;\ 188 equalSmallDoubleDoubleFt equalDouble;\ 189 equalSmallDoubleInt64Ft equalInt64;\ 190 equalSmallDoubleInt32Ft equalInt32;\ 191 equalSmallDoubleUint32Ft equalUint32;\ 192 equalSmallDoubleUint64Ft equalUint64;\ 193 equalSmallDoubleSmallBoolFt equalSmallBool;\ 194 equalSmallDoubleSmallBytesFt equalSmallBytes;\ 195 equalSmallDoubleFt equal;\ 196 equalSmallDoubleSmallIntFt equalSmallInt;\ 197 equalSmallDoubleSmallJsonFt equalSmallJson;\ 198 equalSmallDoubleSmallStringFt equalSmallString;\ 199 readFileSmallDoubleFt readFile;\ 200 readFileSmallJsonSmallDoubleFt readFileSmallJson;\ 201 readFileSmallStringSmallDoubleFt readFileSmallString;\ 202 readStreamSmallDoubleFt readStream;\ 203 writeFileSmallDoubleFt writeFile;\ 204 writeFileSmallJsonSmallDoubleFt writeFileSmallJson;\ 205 writeFileSmallStringSmallDoubleFt writeFileSmallString;\ 206 writeStreamSmallDoubleFt writeStream;\ 207 appendFileSmallDoubleFt appendFile;\ 208 appendFileSmallStringSmallDoubleFt appendFileSmallString 209 210 typedef struct { 211 freeSmallDoubleFt free; 212 terminateSmallDoubleFt terminate; 213 toStringSmallDoubleFt toString; 214 duplicateSmallDoubleFt duplicate; 215 smashSmallDoubleFt smash; 216 finishSmallDoubleFt finish; 217 SMALLDOUBLEFUNCTIONST; 218 } smallDoubleFunctionst; 219 220 /** 221 * class 222 */ 223 struct smallDouble { 224 const char *type; 225 smallDoubleFunctionst *f; 226 227 sDoublet *value; 228 }; 229 230 // smallDouble 231 232 #define createSmallDouble(obj) ;smallDoublet obj; initiateSmallDouble(&obj) 233 #define createAllocateSmallDouble(obj) ;smallDoublet *obj; initiateAllocateSmallDouble(&obj) 234 235 void initiateSmallDouble(smallDoublet *self); 236 void initiateAllocateSmallDouble(smallDoublet **self); 237 void finalizeRecycleSmallDouble(void *arg UNUSED); 238 void finalizeSmallDouble(void); 239 240 // initialize class methods, call registerMethodsSmallDouble from classes inheriting this class 241 void registerMethodsSmallDouble(smallDoubleFunctionst *f); 242 243 smallDoublet* allocSmallDouble(double value); 244 245 // terminate smallDoublet val when it is out of scope 246 void cleanUpSmallDoubleTerminateG(smallDoublet **val); 247 248 // free smallDoublet local val when it is out of scope 249 void cleanUpSmallDoubleFreeLocalG(smallDoublet *val); 250 251 // free smallDoublet val when it is out of scope 252 void cleanUpSmallDoubleFreeG(smallDoublet **val); 253 254 // finish smallDoublet val when it is out of scope 255 void cleanUpSmallDoubleFinishG(smallDoublet **val); 256 257 /** 258 * declare pointer name with type smallDoublet and terminate name when it is out of scope 259 */ 260 #define cleanSmallDoubleP(name) smallDoublet *name CLEANUP(cleanUpSmallDoubleTerminateG) 261 262 /** 263 * allocate smallDouble (pointer) and clean up when it is out of scope 264 */ 265 #define cleanAllocateSmallDouble(obj) ;cleanSmallDoubleP(obj); initiateAllocateSmallDouble(&obj) 266 267 /** 268 * declare local object name with type smallDoublet and free name when it is out of scope 269 */ 270 #define cleanSmallDouble(name) smallDoublet name CLEANUP(cleanUpSmallDoubleFreeLocalG); initiateSmallDouble(&name) 271 272 /** 273 * declare pointer name with type smallDoublet and free name when it is out of scope 274 */ 275 #define cleanFreeSmallDouble(name) smallDoublet *name CLEANUP(cleanUpSmallDoubleFreeG) 276 277 /** 278 * declare pointer name with Type smallDoublet and finish name when it is out of scope 279 */ 280 #define cleanFinishSmallDoubleP(name) smallDoublet *name CLEANUP(cleanUpSmallDoubleFinishG) 281 282 smallDoublet* duplicateSmallDoubleG (smallDoublet *self); 283 284 void freeSmallDoubleG (smallDoublet *self); 285 286 double getDoubleSmallDoubleG (smallDoublet *self, double retType UNUSED, int64_t index UNUSED); 287 288 smallDoublet* setBoolSmallDoubleG (smallDoublet* self, bool p2); 289 smallDoublet* setSmallDoubleG (smallDoublet* self, double p2); 290 smallDoublet* setInt64SmallDoubleG (smallDoublet* self, int64_t p2); 291 smallDoublet* setInt32SmallDoubleG (smallDoublet* self, int32_t p2); 292 smallDoublet* setUint32SmallDoubleG (smallDoublet* self, uint32_t p2); 293 smallDoublet* setUint64SmallDoubleG (smallDoublet* self, uint64_t p2); 294 smallDoublet* setSSmallDoubleG (smallDoublet* self, const char* p2); 295 smallDoublet* setSmallBoolSmallDoubleG (smallDoublet* self, smallBoolt* p2); 296 smallDoublet* setSmallDoubleSmallDoubleG (smallDoublet* self, smallDoublet* p2); 297 smallDoublet* setSmallIntSmallDoubleG (smallDoublet* self, smallIntt* p2); 298 smallDoublet* setSmallJsonSmallDoubleG (smallDoublet* self, smallJsont* p2); 299 smallDoublet* setSmallStringSmallDoubleG (smallDoublet* self, smallStringt* p2); 300 301 double* getDoublePSmallDoubleG (smallDoublet *self, double* retType UNUSED, int64_t index UNUSED); 302 303 bool equalSmallDoubleChaG (smallDoublet* self, char p2); 304 bool equalSmallDoubleCharG (smallDoublet* self, const char * p2); 305 bool equalSmallDoubleBaseG (smallDoublet* self, baset* p2); 306 bool equalSmallDoubleBoolG (smallDoublet* self, bool p2); 307 bool equalSmallDoubleDoubleG (smallDoublet* self, double p2); 308 bool equalSmallDoubleInt64G (smallDoublet* self, int64_t p2); 309 bool equalSmallDoubleInt32G (smallDoublet* self, int32_t p2); 310 bool equalSmallDoubleUint32G (smallDoublet* self, uint32_t p2); 311 bool equalSmallDoubleUint64G (smallDoublet* self, uint64_t p2); 312 bool equalSmallDoubleSmallBoolG (smallDoublet* self, smallBoolt* p2); 313 bool equalSmallDoubleSmallBytesG (smallDoublet* self, smallBytest* p2); 314 bool equalSmallDoubleFG (smallDoublet* self, smallDoublet* p2); 315 bool equalSmallDoubleSmallIntG (smallDoublet* self, smallIntt* p2); 316 bool equalSmallDoubleSmallJsonG (smallDoublet* self, smallJsont* p2); 317 bool equalSmallDoubleSmallStringG (smallDoublet* self, smallStringt* p2); 318 319 smallDoublet* readFileSmallDoubleG (smallDoublet *self, const char *filePath); 320 smallDoublet* readFileSmallJsonSmallDoubleG (smallDoublet *self, smallJsont *filePath); 321 smallDoublet* readFileSmallStringSmallDoubleG(smallDoublet *self, smallStringt *filePath); 322 smallDoublet* readStreamSmallDoubleG (smallDoublet *self, FILE *fp); 323 int writeFileSmallDoubleG (smallDoublet *self, const char *filePath); 324 int writeFileSmallJsonSmallDoubleG (smallDoublet *self, smallJsont *filePath); 325 int writeFileSmallStringSmallDoubleG(smallDoublet *self, smallStringt *filePath); 326 int writeStreamSmallDoubleG (smallDoublet *self, FILE *fp); 327 int appendFileSmallDoubleFG (smallDoublet *self, const char *filePath); //TODO remove F - oGMacros generates a macro making the compilation fail 328 int appendFileSmallStringSmallDoubleG(smallDoublet *self, smallStringt *filePath); 329 // end class smallDouble