libsheepyCSmallBool.h (13233B)
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 #include <stdbool.h> 25 26 // Class smallBool 27 typedef struct smallBool smallBoolt; 28 29 /** 30 * help text for this class 31 * It is public declaration so that child classes can add their help text easily: 32 * ret "Child help text \n\n" helpTextSmallBool; 33 */ 34 #define helpTextSmallBool "TODO smallBool help brief, class description /*, definitions,*/ methods, examples" 35 36 // for object inheriting smallBool, cast to smallBool to be able to use this class functions and generics 37 #define cBo(self) ( (smallBoolt*) self ) 38 39 typedef void (*freeSmallBoolFt) (smallBoolt *self); 40 typedef void (*terminateSmallBoolFt) (smallBoolt **self); 41 typedef char* (*toStringSmallBoolFt) (smallBoolt *self); 42 typedef smallBoolt* (*duplicateSmallBoolFt) (smallBoolt *self); 43 44 // smallBool functions 45 /** 46 * free self but not the smallBool buffer 47 * 48 * Useful when smallBool buffer is shared or 49 * when the buffer holds a static smallBool 50 */ 51 typedef void (*smashSmallBoolFt) (smallBoolt **self); 52 53 /** 54 * free container 55 */ 56 typedef void (*finishSmallBoolFt) (smallBoolt **self); 57 58 typedef const char* (*helpSmallBoolFt) (smallBoolt *self); 59 60 /** 61 * get a copy of smallBool 62 * 63 * The returned smallBool needs to be freed 64 * 65 * \return 66 * char* 67 */ 68 typedef bool (*getSmallBoolFt) (smallBoolt *self); 69 70 /** 71 * set smallBool 72 * 73 * \param 74 * string buffer to store in object (the buffer is duplicated) 75 */ 76 typedef smallBoolt* (*setSmallBoolFt) (smallBoolt *self, bool value); 77 78 typedef smallBoolt* (*setDoubleSmallBoolFt) (smallBoolt* self, double p2); 79 typedef smallBoolt* (*setInt64SmallBoolFt) (smallBoolt* self, int64_t p2); 80 typedef smallBoolt* (*setInt32SmallBoolFt) (smallBoolt* self, int32_t p2); 81 typedef smallBoolt* (*setUint32SmallBoolFt) (smallBoolt* self, uint32_t p2); 82 typedef smallBoolt* (*setUint64SmallBoolFt) (smallBoolt* self, uint64_t p2); 83 typedef smallBoolt* (*setSSmallBoolFt) (smallBoolt* self, const char* p2); 84 typedef smallBoolt* (*setSmallBoolSmallBoolFt) (smallBoolt* self, smallBoolt* p2); 85 typedef smallBoolt* (*setSmallDoubleSmallBoolFt)(smallBoolt* self, smallDoublet* p2); 86 typedef smallBoolt* (*setSmallIntSmallBoolFt) (smallBoolt* self, smallIntt* p2); 87 typedef smallBoolt* (*setSmallJsonSmallBoolFt) (smallBoolt* self, smallJsont* p2); 88 typedef smallBoolt* (*setSmallStringSmallBoolFt)(smallBoolt* self, smallStringt* p2); 89 90 /** 91 * get a pointer to smallBool 92 * 93 * \return 94 * char* 95 */ 96 typedef bool* (*getPSmallBoolFt) (smallBoolt *self); 97 98 typedef bool (*equalSmallBoolCharFt)(smallBoolt* self, const char * p2); 99 typedef bool (*equalSmallBoolBaseFt)(smallBoolt* self, baset* p2); 100 typedef bool (*equalSmallBoolBoolFt)(smallBoolt* self, bool p2); 101 typedef bool (*equalSmallBoolDoubleFt)(smallBoolt* self, double p2); 102 typedef bool (*equalSmallBoolInt64Ft)(smallBoolt* self, int64_t p2); 103 typedef bool (*equalSmallBoolInt32Ft)(smallBoolt* self, int32_t p2); 104 typedef bool (*equalSmallBoolUint32Ft)(smallBoolt* self, uint32_t p2); 105 typedef bool (*equalSmallBoolUint64Ft)(smallBoolt* self, uint64_t p2); 106 typedef bool (*equalSmallBoolFt)(smallBoolt* self, smallBoolt* p2); 107 typedef bool (*equalSmallBoolSmallDoubleFt)(smallBoolt* self, smallDoublet* p2); 108 typedef bool (*equalSmallBoolSmallIntFt)(smallBoolt* self, smallIntt* p2); 109 typedef bool (*equalSmallBoolSmallJsonFt)(smallBoolt* self, smallJsont* p2); 110 typedef bool (*equalSmallBoolSmallStringFt)(smallBoolt* self, smallStringt* p2); 111 typedef bool (*equalSmallBoolSmallBytesFt)(smallBoolt* self, smallBytest* p2); 112 113 /** 114 * read file to bool 115 * 116 * \param 117 * filePath: path to file 118 * \return 119 * 0 data in file 120 * -1 an error occured 121 */ 122 typedef smallBoolt* (*readFileSmallBoolFt)(smallBoolt *self, const char *filePath); 123 typedef smallBoolt* (*readFileSmallJsonSmallBoolFt)(smallBoolt *self, smallJsont *filePath); 124 typedef smallBoolt* (*readFileSmallStringSmallBoolFt)(smallBoolt *self, smallStringt *filePath); 125 typedef smallBoolt* (*readStreamSmallBoolFt)(smallBoolt *self, FILE *fp); 126 127 /** 128 * write bool to file 129 * 130 * \param 131 * filePath path to file 132 * \return 133 * 1 success 134 * 0 error 135 */ 136 typedef int (*writeFileSmallBoolFt) (smallBoolt *self, const char *filePath); 137 typedef int (*writeFileSmallJsonSmallBoolFt) (smallBoolt *self, smallJsont *filePath); 138 typedef int (*writeFileSmallStringSmallBoolFt)(smallBoolt *self, smallStringt *filePath); 139 typedef int (*writeStreamSmallBoolFt) (smallBoolt *self, FILE *fp); 140 141 /** 142 * append bool to filePath 143 * 144 * \param 145 * filePath 146 * \return 147 * true success 148 * false failed, filePath 149 */ 150 typedef int (*appendFileSmallBoolFt)(smallBoolt *self, const char *filePath); 151 typedef int (*appendFileSmallStringSmallBoolFt)(smallBoolt *self, smallStringt *filePath); 152 153 /** 154 * class functions 155 * allocated once for all objects 156 * 157 * freed with finalizeSmallBool or finalizeLibsheepy 158 */ 159 160 /** 161 * use this define in child classes and add the new function after this class functions 162 * 163 * in this define, add the methods after <finishClassTemplateFt finish;> 164 * 165 * Example: 166 * #define RINGFUNCTIONST \ 167 * CLASSTEMPLATEFUNCTIONST; \ 168 * setSizeRingFt setSize 169 */ 170 #define SMALLBOOLFUNCTIONST \ 171 helpSmallBoolFt help;\ 172 getSmallBoolFt get;\ 173 setSmallBoolFt set;\ 174 setDoubleSmallBoolFt setDouble;\ 175 setInt64SmallBoolFt setInt64;\ 176 setInt32SmallBoolFt setInt32;\ 177 setUint32SmallBoolFt setUint32;\ 178 setUint64SmallBoolFt setUint64;\ 179 setSSmallBoolFt setS;\ 180 setSmallBoolSmallBoolFt setSmallBool;\ 181 setSmallDoubleSmallBoolFt setSmallDouble;\ 182 setSmallIntSmallBoolFt setSmallInt;\ 183 setSmallJsonSmallBoolFt setSmallJson;\ 184 setSmallStringSmallBoolFt setSmallString;\ 185 getPSmallBoolFt getP;\ 186 equalSmallBoolCharFt equalChar;\ 187 equalSmallBoolBaseFt equalBase;\ 188 equalSmallBoolBoolFt equalBool;\ 189 equalSmallBoolDoubleFt equalDouble;\ 190 equalSmallBoolInt64Ft equalInt64;\ 191 equalSmallBoolInt32Ft equalInt32;\ 192 equalSmallBoolUint32Ft equalUint32;\ 193 equalSmallBoolUint64Ft equalUint64;\ 194 equalSmallBoolFt equal;\ 195 equalSmallBoolSmallBytesFt equalSmallBytes;\ 196 equalSmallBoolSmallDoubleFt equalSmallDouble;\ 197 equalSmallBoolSmallIntFt equalSmallInt;\ 198 equalSmallBoolSmallJsonFt equalSmallJson;\ 199 equalSmallBoolSmallStringFt equalSmallString;\ 200 readFileSmallBoolFt readFile;\ 201 readFileSmallJsonSmallBoolFt readFileSmallJson;\ 202 readFileSmallStringSmallBoolFt readFileSmallString;\ 203 readStreamSmallBoolFt readStream;\ 204 writeFileSmallBoolFt writeFile;\ 205 writeFileSmallJsonSmallBoolFt writeFileSmallJson;\ 206 writeFileSmallStringSmallBoolFt writeFileSmallString;\ 207 writeStreamSmallBoolFt writeStream;\ 208 appendFileSmallBoolFt appendFile;\ 209 appendFileSmallStringSmallBoolFt appendFileSmallString 210 211 typedef struct { 212 freeSmallBoolFt free; 213 terminateSmallBoolFt terminate; 214 toStringSmallBoolFt toString; 215 duplicateSmallBoolFt duplicate; 216 smashSmallBoolFt smash; 217 finishSmallBoolFt finish; 218 SMALLBOOLFUNCTIONST; 219 } smallBoolFunctionst; 220 221 /** 222 * class 223 */ 224 struct smallBool { 225 const char *type; 226 smallBoolFunctionst *f; 227 228 /** bool value */ 229 sBoolt *value; 230 }; 231 232 // smallBool 233 234 #define createSmallBool(obj) ;smallBoolt obj; initiateSmallBool(&obj) 235 #define createAllocateSmallBool(obj) ;smallBoolt *obj; initiateAllocateSmallBool(&obj) 236 237 void initiateSmallBool(smallBoolt *self); 238 void initiateAllocateSmallBool(smallBoolt **self); 239 void finalizeRecycleSmallBool(void *arg UNUSED); 240 void finalizeSmallBool(void); 241 242 // initialize class methods, call registerMethodsSmallBool from classes inheriting this class 243 void registerMethodsSmallBool(smallBoolFunctionst *f); 244 245 smallBoolt* allocSmallBool(bool value); 246 247 // terminate smallBoolt val when it is out of scope 248 void cleanUpSmallBoolTerminateG(smallBoolt **val); 249 250 // free smallBoolt local val when it is out of scope 251 void cleanUpSmallBoolFreeLocalG(smallBoolt *val); 252 253 // free smallBoolt val when it is out of scope 254 void cleanUpSmallBoolFreeG(smallBoolt **val); 255 256 // finish smallBoolt val when it is out of scope 257 void cleanUpSmallBoolFinishG(smallBoolt **val); 258 259 /** 260 * declare pointer name with type smallBoolt and terminate name when it is out of scope 261 */ 262 #define cleanSmallBoolP(name) smallBoolt *name CLEANUP(cleanUpSmallBoolTerminateG) 263 264 /** 265 * allocate smallBool (pointer) and clean up when it is out of scope 266 */ 267 #define cleanAllocateSmallBool(obj) ;cleanSmallBoolP(obj); initiateAllocateSmallBool(&obj) 268 269 /** 270 * declare local object name with type smallBoolt and free name when it is out of scope 271 */ 272 #define cleanSmallBool(name) smallBoolt name CLEANUP(cleanUpSmallBoolFreeLocalG); initiateSmallBool(&name) 273 274 /** 275 * declare pointer name with type smallBoolt and free name when it is out of scope 276 */ 277 #define cleanFreeSmallBool(name) smallBoolt *name CLEANUP(cleanUpSmallBoolFreeG) 278 279 /** 280 * declare pointer name with Type smallBoolt and finish name when it is out of scope 281 */ 282 #define cleanFinishSmallBoolP(name) smallBoolt *name CLEANUP(cleanUpSmallBoolFinishG) 283 284 smallBoolt* duplicateSmallBoolG (smallBoolt *self); 285 286 void freeSmallBoolG (smallBoolt *self); 287 288 bool getBoolSmallBoolG (smallBoolt *self, bool retType UNUSED, int64_t index UNUSED); 289 bool* getBoolPSmallBoolG (smallBoolt *self, bool* retType UNUSED, int64_t index UNUSED); 290 291 smallBoolt* setSmallBoolG(smallBoolt* self, bool p2); 292 smallBoolt* setDoubleSmallBoolG(smallBoolt* self, double p2); 293 smallBoolt* setInt64SmallBoolG(smallBoolt* self, int64_t p2); 294 smallBoolt* setInt32SmallBoolG(smallBoolt* self, int32_t p2); 295 smallBoolt* setUint32SmallBoolG(smallBoolt* self, uint32_t p2); 296 smallBoolt* setUint64SmallBoolG(smallBoolt* self, uint64_t p2); 297 smallBoolt* setSSmallBoolG(smallBoolt* self, const char* p2); 298 smallBoolt* setSmallBoolSmallBoolG(smallBoolt* self, smallBoolt* p2); 299 smallBoolt* setSmallDoubleSmallBoolG(smallBoolt* self, smallDoublet* p2); 300 smallBoolt* setSmallIntSmallBoolG(smallBoolt* self, smallIntt* p2); 301 smallBoolt* setSmallJsonSmallBoolG(smallBoolt* self, smallJsont* p2); 302 smallBoolt* setSmallStringSmallBoolG(smallBoolt* self, smallStringt* p2); 303 304 bool equalSmallBoolCharG(smallBoolt* self, const char * p2); 305 bool equalSmallBoolBaseG(smallBoolt* self, baset* p2); 306 bool equalSmallBoolBoolG(smallBoolt* self, bool p2); 307 bool equalSmallBoolDoubleG(smallBoolt* self, double p2); 308 bool equalSmallBoolInt64G(smallBoolt* self, int64_t p2); 309 bool equalSmallBoolInt32G(smallBoolt* self, int32_t p2); 310 bool equalSmallBoolUint32G(smallBoolt* self, uint32_t p2); 311 bool equalSmallBoolUint64G(smallBoolt* self, uint64_t p2); 312 bool equalSmallBoolFG(smallBoolt* self, smallBoolt* p2); 313 bool equalSmallBoolSmallDoubleG(smallBoolt* self, smallDoublet* p2); 314 bool equalSmallBoolSmallIntG(smallBoolt* self, smallIntt* p2); 315 bool equalSmallBoolSmallJsonG(smallBoolt* self, smallJsont* p2); 316 bool equalSmallBoolSmallStringG(smallBoolt* self, smallStringt* p2); 317 bool equalSmallBoolSmallBytesG(smallBoolt* self, smallBytest* p2); 318 319 smallBoolt* readFileSmallBoolG (smallBoolt *self, const char *filePath); 320 smallBoolt* readFileSmallJsonSmallBoolG (smallBoolt *self, smallJsont *filePath); 321 smallBoolt* readFileSmallStringSmallBoolG(smallBoolt *self, smallStringt *filePath); 322 smallBoolt* readStreamSmallBoolG (smallBoolt *self, FILE *fp); 323 int writeFileSmallBoolG (smallBoolt *self, const char *filePath); 324 int writeFileSmallJsonSmallBoolG (smallBoolt *self, smallJsont *filePath); 325 int writeFileSmallStringSmallBoolG(smallBoolt *self, smallStringt *filePath); 326 int writeStreamSmallBoolG (smallBoolt *self, FILE *fp); 327 int appendFileSmallBoolFG (smallBoolt *self, const char *filePath); //TODO remove F - oGMacros generates a macro making the compilation fail 328 int appendFileSmallStringSmallBoolG(smallBoolt *self, smallStringt *filePath); 329 // end class smallBool