libsheepyCSmallBool.c (28817B)
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 23 #include "../libsheepyObject.h" 24 #include "libsheepyCSmallBool.h" 25 #include "libsheepyCSmallBoolInternal.h" 26 27 #define internal static 28 29 #include <stdint.h> 30 #include <stdlib.h> 31 #include <stdbool.h> 32 #include <string.h> 33 #include <stdio.h> 34 35 void initiateSmallBool(smallBoolt *self); 36 void registerMethodsSmallBool(smallBoolFunctionst *f); 37 void initiateAllocateSmallBool(smallBoolt **self); 38 void finalizeRecycleSmallBool(void *arg UNUSED); 39 void finalizeSmallBool(void); 40 smallBoolt* allocSmallBool(bool value); 41 void cleanUpSmallBoolTerminateG(smallBoolt **val); 42 void cleanUpSmallBoolFreeLocalG(smallBoolt *val); 43 void cleanUpSmallBoolFreeG(smallBoolt **val); 44 void cleanUpSmallBoolFinishG(smallBoolt **val); 45 internal void freeSmallBool(smallBoolt *self); 46 internal void terminateSmallBool(smallBoolt **self); 47 internal char* toStringSmallBool(smallBoolt *self); 48 internal smallBoolt* duplicateSmallBool(smallBoolt *self); 49 internal void smashSmallBool(smallBoolt **self); 50 #if (NFreeStackCheck) 51 internal void finishSmallBool(smallBoolt **self); 52 #else 53 internal void finishSmallBool(smallBoolt **self); 54 #endif 55 internal const char* helpSmallBool(smallBoolt UNUSED *self); 56 internal bool getSmallBool(smallBoolt *self); 57 internal smallBoolt* setSmallBool(smallBoolt *self, bool value); 58 internal smallBoolt* setDoubleSmallBool(smallBoolt* self, double p2); 59 internal smallBoolt* setInt64SmallBool(smallBoolt* self, int64_t p2); 60 internal smallBoolt* setInt32SmallBool(smallBoolt* self, int32_t p2); 61 internal smallBoolt* setUint32SmallBool(smallBoolt* self, uint32_t p2); 62 internal smallBoolt* setUint64SmallBool(smallBoolt* self, uint64_t p2); 63 internal smallBoolt* setSSmallBool(smallBoolt* self, const char* p2); 64 internal smallBoolt* setSmallBoolSmallBool(smallBoolt* self, smallBoolt* p2); 65 internal smallBoolt* setSmallDoubleSmallBool(smallBoolt* self, smallDoublet* p2); 66 internal smallBoolt* setSmallIntSmallBool(smallBoolt* self, smallIntt* p2); 67 internal smallBoolt* setSmallJsonSmallBool(smallBoolt* self, smallJsont* p2); 68 internal smallBoolt* setSmallStringSmallBool(smallBoolt* self, smallStringt* p2); 69 internal bool* getPSmallBool(smallBoolt *self); 70 internal bool equalSmallBoolChar(smallBoolt* self, const char * p2); 71 internal bool equalSmallBoolBase(smallBoolt* self, baset* p2); 72 internal bool equalSmallBoolBool(smallBoolt* self, bool p2); 73 internal bool equalSmallBoolDouble(smallBoolt* self, double p2); 74 internal bool equalSmallBoolInt64(smallBoolt* self, int64_t p2); 75 internal bool equalSmallBoolInt32(smallBoolt* self, int32_t p2); 76 internal bool equalSmallBoolUint32(smallBoolt* self, uint32_t p2); 77 internal bool equalSmallBoolUint64(smallBoolt* self, uint64_t p2); 78 internal bool equalSmallBool(smallBoolt* self, smallBoolt* p2); 79 internal bool equalSmallBoolSmallBytes(smallBoolt* self, smallBytest* p2); 80 internal bool equalSmallBoolSmallDouble(smallBoolt* self, smallDoublet* p2); 81 internal bool equalSmallBoolSmallInt(smallBoolt* self, smallIntt* p2); 82 internal bool equalSmallBoolSmallJson(smallBoolt* self, smallJsont* p2); 83 internal bool equalSmallBoolSmallString(smallBoolt* self, smallStringt* p2); 84 internal smallBoolt* readFileSmallBool(smallBoolt *self, const char *filePath); 85 internal smallBoolt* readFileSmallJsonSmallBool(smallBoolt *self, smallJsont *filePath); 86 internal smallBoolt* readFileSmallStringSmallBool(smallBoolt *self, smallStringt *filePath); 87 internal smallBoolt* readStreamSmallBool(smallBoolt *self, FILE *fp); 88 internal int writeFileSmallBool(smallBoolt *self, const char *filePath); 89 internal int writeFileSmallJsonSmallBool(smallBoolt *self, smallJsont *filePath); 90 internal int writeFileSmallStringSmallBool(smallBoolt *self, smallStringt *filePath); 91 internal int writeStreamSmallBool(smallBoolt *self, FILE *fp); 92 internal int appendFileSmallBool(smallBoolt *self, const char *filePath); 93 internal int appendFileSmallStringSmallBool(smallBoolt *self, smallStringt *filePath); 94 smallBoolt* duplicateSmallBoolG (smallBoolt *self); 95 bool getBoolSmallBoolG (smallBoolt *self, bool retType UNUSED, int64_t index UNUSED); 96 bool* getBoolPSmallBoolG (smallBoolt *self, bool* retType UNUSED, int64_t index UNUSED); 97 smallBoolt* setSmallBoolG(smallBoolt* self, bool p2); 98 smallBoolt* setDoubleSmallBoolG(smallBoolt* self, double p2); 99 smallBoolt* setInt64SmallBoolG(smallBoolt* self, int64_t p2); 100 smallBoolt* setInt32SmallBoolG(smallBoolt* self, int32_t p2); 101 smallBoolt* setUint32SmallBoolG(smallBoolt* self, uint32_t p2); 102 smallBoolt* setUint64SmallBoolG(smallBoolt* self, uint64_t p2); 103 smallBoolt* setSSmallBoolG(smallBoolt* self, const char* p2); 104 smallBoolt* setSmallBoolSmallBoolG(smallBoolt* self, smallBoolt* p2); 105 smallBoolt* setSmallDoubleSmallBoolG(smallBoolt* self, smallDoublet* p2); 106 smallBoolt* setSmallIntSmallBoolG(smallBoolt* self, smallIntt* p2); 107 smallBoolt* setSmallJsonSmallBoolG(smallBoolt* self, smallJsont* p2); 108 smallBoolt* setSmallStringSmallBoolG(smallBoolt* self, smallStringt* p2); 109 bool equalSmallBoolCharG(smallBoolt* self, const char * p2); 110 bool equalSmallBoolBaseG(smallBoolt* self, baset* p2); 111 bool equalSmallBoolBoolG(smallBoolt* self, bool p2); 112 bool equalSmallBoolDoubleG(smallBoolt* self, double p2); 113 bool equalSmallBoolInt64G(smallBoolt* self, int64_t p2); 114 bool equalSmallBoolInt32G(smallBoolt* self, int32_t p2); 115 bool equalSmallBoolUint32G(smallBoolt* self, uint32_t p2); 116 bool equalSmallBoolUint64G(smallBoolt* self, uint64_t p2); 117 bool equalSmallBoolFG(smallBoolt* self, smallBoolt* p2); 118 bool equalSmallBoolSmallBytesG(smallBoolt* self, smallBytest* p2); 119 bool equalSmallBoolSmallDoubleG(smallBoolt* self, smallDoublet* p2); 120 bool equalSmallBoolSmallIntG(smallBoolt* self, smallIntt* p2); 121 bool equalSmallBoolSmallJsonG(smallBoolt* self, smallJsont* p2); 122 bool equalSmallBoolSmallStringG(smallBoolt* self, smallStringt* p2); 123 smallBoolt* readFileSmallBoolG (smallBoolt *self, const char *filePath); 124 smallBoolt* readFileSmallJsonSmallBoolG(smallBoolt *self, smallJsont *filePath); 125 smallBoolt* readFileSmallStringSmallBoolG(smallBoolt *self, smallStringt *filePath); 126 smallBoolt* readStreamSmallBoolG (smallBoolt *self, FILE *fp); 127 int writeFileSmallBoolG (smallBoolt *self, const char *filePath); 128 int writeFileSmallJsonSmallBoolG (smallBoolt *self, smallJsont *filePath); 129 int writeFileSmallStringSmallBoolG(smallBoolt *self, smallStringt *filePath); 130 int writeStreamSmallBoolG (smallBoolt *self, FILE *fp); 131 int appendFileSmallBoolFG (smallBoolt *self, const char *filePath); 132 int appendFileSmallStringSmallBoolG(smallBoolt *self, smallStringt *filePath); 133 134 void initiateSmallBool(smallBoolt *self) { 135 136 self->type = "smallBool"; 137 138 if (!smallBoolF) { 139 isError(smallBoolF, malloc(sizeof(smallBoolFunctionst))) { 140 self->f = NULL; 141 return; 142 } 143 registerMethodsSmallBool(smallBoolF); 144 } 145 self->f = smallBoolF; 146 147 self->value = NULL; 148 } 149 150 void registerMethodsSmallBool(smallBoolFunctionst *f) { 151 152 f->free = freeSmallBool; 153 f->terminate = terminateSmallBool; 154 f->toString = toStringSmallBool; 155 f->duplicate = duplicateSmallBool; 156 f->smash = smashSmallBool; 157 f->finish = finishSmallBool; 158 f->help = helpSmallBool; 159 f->get = getSmallBool; 160 f->set = setSmallBool; 161 f->setDouble = setDoubleSmallBool; 162 f->setInt64 = setInt64SmallBool; 163 f->setInt32 = setInt32SmallBool; 164 f->setUint32 = setUint32SmallBool; 165 f->setUint64 = setUint64SmallBool; 166 f->setS = setSSmallBool; 167 f->setSmallBool = setSmallBoolSmallBool; 168 f->setSmallDouble = setSmallDoubleSmallBool; 169 f->setSmallInt = setSmallIntSmallBool; 170 f->setSmallJson = setSmallJsonSmallBool; 171 f->setSmallString = setSmallStringSmallBool; 172 f->getP = getPSmallBool; 173 f->equalChar = equalSmallBoolChar; 174 f->equalBase = equalSmallBoolBase; 175 f->equalBool = equalSmallBoolBool; 176 f->equalDouble = equalSmallBoolDouble; 177 f->equalInt64 = equalSmallBoolInt64; 178 f->equalInt32 = equalSmallBoolInt32; 179 f->equalUint32 = equalSmallBoolUint32; 180 f->equalUint64 = equalSmallBoolUint64; 181 f->equal = equalSmallBool; 182 f->equalSmallBytes = equalSmallBoolSmallBytes; 183 f->equalSmallDouble = equalSmallBoolSmallDouble; 184 f->equalSmallInt = equalSmallBoolSmallInt; 185 f->equalSmallJson = equalSmallBoolSmallJson; 186 f->equalSmallString = equalSmallBoolSmallString; 187 f->readFile = readFileSmallBool; 188 f->readFileSmallJson = readFileSmallJsonSmallBool; 189 f->readFileSmallString = readFileSmallStringSmallBool; 190 f->readStream = readStreamSmallBool; 191 f->writeFile = writeFileSmallBool; 192 f->writeFileSmallJson = writeFileSmallJsonSmallBool; 193 f->writeFileSmallString = writeFileSmallStringSmallBool; 194 f->writeStream = writeStreamSmallBool; 195 f->appendFile = appendFileSmallBool; 196 f->appendFileSmallString = appendFileSmallStringSmallBool; 197 } 198 199 void initiateAllocateSmallBool(smallBoolt **self) { 200 201 if (self) { 202 #if (recycleContainers) 203 initAllocateRecycle(smallBoolt); 204 #else 205 isError(*self, malloc(sizeof(smallBoolt))) 206 return; 207 #endif 208 // recycleContainers 209 if (*self) { 210 initiateSmallBool(*self); 211 if (!(*self)->f) { 212 finishSmallBool(self); 213 } 214 } 215 } 216 } 217 218 void finalizeRecycleSmallBool(void *arg UNUSED) { 219 220 #if (recycleContainers) 221 finalizeRecycle 222 #endif 223 // recycleContainers 224 } 225 226 void finalizeSmallBool(void) { 227 228 if (smallBoolF) { 229 free(smallBoolF); 230 smallBoolF = NULL; 231 } 232 finalizeRecycleSmallBool(NULL); 233 } 234 235 smallBoolt* allocSmallBool(bool value) { 236 smallBoolt *r = NULL; 237 238 initiateAllocateSmallBool(&r); 239 if (!r) { 240 return(NULL); 241 } 242 243 r->value = allocSBool(value); 244 return(r); 245 } 246 247 void cleanUpSmallBoolTerminateG(smallBoolt **val) { 248 249 terminateO(*val); 250 } 251 252 void cleanUpSmallBoolFreeLocalG(smallBoolt *val) { 253 254 freeO(val); 255 } 256 257 void cleanUpSmallBoolFreeG(smallBoolt **val) { 258 259 freeO(*val); 260 } 261 262 void cleanUpSmallBoolFinishG(smallBoolt **val) { 263 264 finishO(*val); 265 } 266 267 internal void freeSmallBool(smallBoolt *self) { 268 269 if (self->value) { 270 free(self->value); 271 self->value = NULL; 272 } 273 return; 274 } 275 276 internal void terminateSmallBool(smallBoolt **self) { 277 278 freeSmallBool(*self); 279 finishSmallBool(self); 280 } 281 282 283 internal char* toStringSmallBool(smallBoolt *self) { 284 285 if (!self->value) { 286 return(NULL); 287 } 288 if (self->value->value) { 289 return(strdup("true")); 290 } 291 else { 292 return(strdup("false")); 293 } 294 } 295 296 internal smallBoolt* duplicateSmallBool(smallBoolt *self) { 297 298 createAllocateSmallBool(dup); 299 if (!dup) { 300 return(NULL); 301 } 302 if (self->value) { 303 dup->value = allocSBool(self->value->value); 304 } 305 return(dup); 306 } 307 308 internal void smashSmallBool(smallBoolt **self) { 309 310 finishSmallBool(self); 311 } 312 313 #if (NFreeStackCheck) 314 internal void finishSmallBool(smallBoolt **self) { 315 316 register u64 rsp asm("rsp"); 317 if ((u64)*self > rsp) { 318 logW("Probably trying to free a smallBool on stack: "BLD PRIx64 RST" sp: "BLD PRIx64 RST, *self, rsp); 319 logBtrace; 320 } 321 else { 322 #if (recycleContainers) 323 finishRecycle 324 #else 325 free(*self); 326 #endif 327 // recycleContainers 328 *self = NULL; 329 } 330 } 331 332 #else 333 // #if NFreeStackCheck 334 internal void finishSmallBool(smallBoolt **self) { 335 336 #if (recycleContainers) 337 finishRecycle 338 #else 339 free(*self); 340 #endif 341 // recycleContainers 342 *self = NULL; 343 } 344 345 #endif 346 // #if NFreeStackCheck 347 348 internal const char* helpSmallBool(smallBoolt UNUSED *self) { 349 350 return(helpTextSmallBool); 351 } 352 353 internal bool getSmallBool(smallBoolt *self) { 354 355 if (!self->value) { 356 return(false); 357 } 358 return(self->value->value); 359 } 360 361 internal smallBoolt* setSmallBool(smallBoolt *self, bool value) { 362 363 if (!self->value) { 364 isError(self->value, allocSBool(value)) return(NULL); 365 } 366 else { 367 self->value->value = value; 368 } 369 return(self); 370 } 371 372 internal smallBoolt* setDoubleSmallBool(smallBoolt* self, double p2) { 373 bool value = false;; 374 375 if (p2) { 376 value = true; 377 } 378 379 if (!self->value) { 380 isError(self->value, allocSBool(value)) return(NULL); 381 } 382 else { 383 self->value->value = value; 384 } 385 return(self); 386 } 387 388 internal smallBoolt* setInt64SmallBool(smallBoolt* self, int64_t p2) { 389 bool value = false;; 390 391 if (p2) { 392 value = true; 393 } 394 395 if (!self->value) { 396 isError(self->value, allocSBool(value)) return(NULL); 397 } 398 else { 399 self->value->value = value; 400 } 401 return(self); 402 } 403 404 internal smallBoolt* setInt32SmallBool(smallBoolt* self, int32_t p2) { 405 bool value = false;; 406 407 if (p2) { 408 value = true; 409 } 410 411 if (!self->value) { 412 isError(self->value, allocSBool(value)) return(NULL); 413 } 414 else { 415 self->value->value = value; 416 } 417 return(self); 418 } 419 420 internal smallBoolt* setUint32SmallBool(smallBoolt* self, uint32_t p2) { 421 bool value = false;; 422 423 if (p2) { 424 value = true; 425 } 426 427 if (!self->value) { 428 isError(self->value, allocSBool(value)) return(NULL); 429 } 430 else { 431 self->value->value = value; 432 } 433 return(self); 434 } 435 436 internal smallBoolt* setUint64SmallBool(smallBoolt* self, uint64_t p2) { 437 bool value = false;; 438 439 if (p2) { 440 value = true; 441 } 442 443 if (!self->value) { 444 isError(self->value, allocSBool(value)) return(NULL); 445 } 446 else { 447 self->value->value = value; 448 } 449 return(self); 450 } 451 452 internal smallBoolt* setSSmallBool(smallBoolt* self, const char* p2) { 453 bool value = false;; 454 455 if (!p2) { 456 return(NULL); 457 } 458 459 if (strEq(p2, "true") || strEq(p2, "TRUE")) { 460 value = true; 461 } 462 463 if (!self->value) { 464 isError(self->value, allocSBool(value)) return(NULL); 465 } 466 else { 467 self->value->value = value; 468 } 469 return(self); 470 } 471 472 internal smallBoolt* setSmallBoolSmallBool(smallBoolt* self, smallBoolt* p2) { 473 bool value = false;; 474 475 if (!p2) { 476 return(NULL); 477 } 478 479 value = p2->f->get(p2); 480 481 if (!self->value) { 482 isError(self->value, allocSBool(value)) return(NULL); 483 } 484 else { 485 self->value->value = value; 486 } 487 return(self); 488 } 489 490 internal smallBoolt* setSmallDoubleSmallBool(smallBoolt* self, smallDoublet* p2) { 491 bool value = false;; 492 493 if (!p2) { 494 return(NULL); 495 } 496 497 double r = p2->f->get(p2); 498 if (r) { 499 value = true; 500 } 501 502 if (!self->value) { 503 isError(self->value, allocSBool(value)) return(NULL); 504 } 505 else { 506 self->value->value = value; 507 } 508 return(self); 509 } 510 511 internal smallBoolt* setSmallIntSmallBool(smallBoolt* self, smallIntt* p2) { 512 bool value = false;; 513 514 if (!p2) { 515 return(NULL); 516 } 517 518 int64_t r = p2->f->get(p2); 519 if (r) { 520 value = true; 521 } 522 523 if (!self->value) { 524 isError(self->value, allocSBool(value)) return(NULL); 525 } 526 else { 527 self->value->value = value; 528 } 529 return(self); 530 } 531 532 internal smallBoolt* setSmallJsonSmallBool(smallBoolt* self, smallJsont* p2) { 533 534 if (!p2) { 535 return(NULL); 536 } 537 538 const char *type = getTopTypeO(p2); 539 540 if (!type || eqS(type, "undefined") || eqS(type, "dict") || eqS(type, "array")) { 541 return(NULL); 542 } 543 544 if (eqS(type, "bool")) { 545 return(setSmallBool(self, getTopBoolO(p2))); 546 } 547 else if (eqS(type, "double")) { 548 return(setDoubleSmallBool(self, getTopDoubleO(p2))); 549 } 550 else if (eqS(type, "int")) { 551 return(setInt64SmallBool(self, getTopIntO(p2))); 552 } 553 else if (eqS(type, "string")) { 554 return(setSSmallBool(self, getTopSO(p2))); 555 } 556 557 return(self); 558 } 559 560 internal smallBoolt* setSmallStringSmallBool(smallBoolt* self, smallStringt* p2) { 561 bool value = false;; 562 563 if (!p2) { 564 return(NULL); 565 } 566 567 if (equalSO(p2, "true") || equalSO(p2, "TRUE")) { 568 value = true; 569 } 570 571 if (!self->value) { 572 isError(self->value, allocSBool(value)) return(NULL); 573 } 574 else { 575 self->value->value = value; 576 } 577 return(self); 578 } 579 580 internal bool* getPSmallBool(smallBoolt *self) { 581 582 if (!self->value) { 583 return(NULL); 584 } 585 return(&(self->value->value)); 586 } 587 588 internal bool equalSmallBoolChar(smallBoolt* self, const char * p2) { 589 590 if (!self->value || !p2) { 591 return(false); 592 } 593 594 if (strEq(p2, "true") || strEq(p2, "TRUE")) { 595 return(self->value->value); 596 } 597 else if (strEq(p2, "false") || strEq(p2, "FALSE")) { 598 return(!self->value->value); 599 } 600 return(false); 601 } 602 603 internal bool equalSmallBoolBase(smallBoolt* self, baset* p2) { 604 605 if (!self->value || !p2) { 606 return(false); 607 } 608 609 char *s = toStringO(p2); 610 611 if (strEq(s, "true") || strEq(s, "TRUE")) { 612 free(s); 613 return(self->value->value); 614 } 615 else if (strEq(s, "false") || strEq(s, "FALSE")) { 616 free(s); 617 return(!self->value->value); 618 } 619 free(s); 620 return(false); 621 } 622 623 internal bool equalSmallBoolBool(smallBoolt* self, bool p2) { 624 625 if (!self->value) { 626 return(false); 627 } 628 629 return(self->value->value == p2);; 630 } 631 632 internal bool equalSmallBoolDouble(smallBoolt* self, double p2) { 633 634 if (!self->value) { 635 return(false); 636 } 637 638 return(self->value->value == p2);; 639 } 640 641 internal bool equalSmallBoolInt64(smallBoolt* self, int64_t p2) { 642 643 if (!self->value) { 644 return(false); 645 } 646 647 return(self->value->value == p2);; 648 } 649 650 internal bool equalSmallBoolInt32(smallBoolt* self, int32_t p2) { 651 652 if (!self->value) { 653 return(false); 654 } 655 656 return(self->value->value == p2);; 657 } 658 659 internal bool equalSmallBoolUint32(smallBoolt* self, uint32_t p2) { 660 661 if (!self->value) { 662 return(false); 663 } 664 665 return(self->value->value == p2);; 666 } 667 668 internal bool equalSmallBoolUint64(smallBoolt* self, uint64_t p2) { 669 670 if (!self->value) { 671 return(false); 672 } 673 674 return(self->value->value == p2);; 675 } 676 677 internal bool equalSmallBool(smallBoolt* self, smallBoolt* p2) { 678 679 if (!self->value || !p2 || !p2->value) { 680 return(false); 681 } 682 683 return(self->value->value == p2->value->value);; 684 } 685 686 internal bool equalSmallBoolSmallBytes(smallBoolt* self, smallBytest* p2) { 687 688 if (!self->value || !p2 || !p2->B) { 689 return(false); 690 } 691 692 if (equalSO(p2, "true") || equalSO(p2, "TRUE")) { 693 return(self->value->value); 694 } 695 else if (equalSO(p2, "false") || equalSO(p2, "FALSE")) { 696 return(!self->value->value); 697 } 698 return(false); 699 } 700 701 internal bool equalSmallBoolSmallDouble(smallBoolt* self, smallDoublet* p2) { 702 703 if (!self->value || !p2 || !p2->value) { 704 return(false); 705 } 706 707 return(self->value->value == p2->value->value);; 708 } 709 710 internal bool equalSmallBoolSmallInt(smallBoolt* self, smallIntt* p2) { 711 712 if (!self->value || !p2 || !p2->value) { 713 return(false); 714 } 715 716 return(self->value->value == p2->value->value);; 717 } 718 719 internal bool equalSmallBoolSmallJson(smallBoolt* self, smallJsont* p2) { 720 721 if (!p2) { 722 return(false); 723 } 724 725 // sanity checks 726 if (checkObjectTypes && !isOSmallJson(p2)) { 727 return(false); 728 } 729 730 return(p2->f->equalSmallBool(p2, self)); 731 } 732 733 internal bool equalSmallBoolSmallString(smallBoolt* self, smallStringt* p2) { 734 735 if (!self->value || !p2 || !p2->data) { 736 return(false); 737 } 738 739 char *s = sStringGetTiny(p2->data); 740 if (strEq(s, "true") || strEq(s, "TRUE")) { 741 return(self->value->value); 742 } 743 else if (strEq(s, "false") || strEq(s, "FALSE")) { 744 return(!self->value->value); 745 } 746 return(false); 747 } 748 749 internal smallBoolt* readFileSmallBool(smallBoolt *self, const char *filePath) { 750 FILE *f = NULL; 751 size_t readStatus; 752 753 // sanity checks 754 if (!filePath || isBlankS(filePath)) { 755 return(NULL); 756 } 757 758 if (!self->value) { 759 isError(self->value, allocSBool(false)) return(NULL); 760 } 761 762 f = fopen(filePath, "r"); 763 if (!f) { 764 pFuncError 765 shEPrintfS("The path was: \"%s\"\n", filePath); 766 return(NULL); 767 } 768 readStatus = fread(&self->value->value, 1, sizeof(bool) , f); 769 fclose(f); 770 771 if (readStatus != sizeof(bool)) { 772 pFuncError 773 shEPrintfS("The path was: \"%s\"\n", filePath); 774 return(NULL); 775 } 776 777 return(self); 778 } 779 780 internal smallBoolt* readFileSmallJsonSmallBool(smallBoolt *self, smallJsont *filePath) { 781 782 if (!filePath) { 783 return(NULL); 784 } 785 786 if (checkObjectTypes && !isOSmallJson(filePath)) { 787 return(NULL); 788 } 789 790 const char *type = getTopTypeO(filePath); 791 792 if (!eqS(type,"string")) { 793 return(NULL); 794 } 795 796 return(readFileSmallBool(self, getTopSO(filePath))); 797 } 798 799 internal smallBoolt* readFileSmallStringSmallBool(smallBoolt *self, smallStringt *filePath) { 800 801 if (!filePath) { 802 return(NULL); 803 } 804 805 if (checkObjectTypes && !isOSmallString(filePath)) { 806 return(NULL); 807 } 808 809 return(readFileSmallBool(self, ssGet(filePath))); 810 } 811 812 internal smallBoolt* readStreamSmallBool(smallBoolt *self, FILE *fp) { 813 size_t readStatus; 814 815 // sanity checks 816 if (!fp) { 817 return(NULL); 818 } 819 820 if (!self->value) { 821 isError(self->value, allocSBool(false)) return(NULL); 822 } 823 824 readStatus = fread(&self->value->value, 1, sizeof(bool) , fp); 825 826 if (readStatus != sizeof(bool)) { 827 pFuncError 828 return(NULL); 829 } 830 831 return(self); 832 } 833 834 internal int writeFileSmallBool(smallBoolt *self, const char *filePath) { 835 FILE *f = NULL; 836 size_t writeStatus; 837 838 // sanity checks 839 if (!filePath || isBlankS(filePath) || !self->value) { 840 return(0); 841 } 842 843 f = fopen(filePath, "w"); 844 if (!f) { 845 pFuncError 846 shEPrintfS("The path was: \"%s\"\n", filePath); 847 return(0); 848 } 849 writeStatus = fwrite(&self->value->value, 1, sizeof(bool) , f); 850 fclose(f); 851 852 if (writeStatus != sizeof(bool)) { 853 pFuncError 854 shEPrintfS("The path was: \"%s\"\n", filePath); 855 return(0); 856 } 857 858 return(1); 859 } 860 861 internal int writeFileSmallJsonSmallBool(smallBoolt *self, smallJsont *filePath) { 862 863 if (!filePath) { 864 return(0); 865 } 866 867 if (checkObjectTypes && !isOSmallJson(filePath)) { 868 return(0); 869 } 870 871 const char *type = getTopTypeO(filePath); 872 873 if (!eqS(type,"string")) { 874 return(0); 875 } 876 877 return(writeFileSmallBool(self, getTopSO(filePath))); 878 } 879 880 internal int writeFileSmallStringSmallBool(smallBoolt *self, smallStringt *filePath) { 881 882 if (!filePath) { 883 return(0); 884 } 885 886 if (checkObjectTypes && !isOSmallString(filePath)) { 887 return(0); 888 } 889 890 return(writeFileSmallBool(self, ssGet(filePath))); 891 } 892 893 internal int writeStreamSmallBool(smallBoolt *self, FILE *fp) { 894 size_t writeStatus; 895 896 // sanity checks 897 if (!fp || !self->value) { 898 return(0); 899 } 900 901 writeStatus = fwrite(&self->value->value, 1, sizeof(bool) , fp); 902 903 if (writeStatus != sizeof(bool)) { 904 pFuncError 905 return(0); 906 } 907 908 return(1); 909 } 910 911 internal int appendFileSmallBool(smallBoolt *self, const char *filePath) { 912 FILE *f = NULL; 913 size_t writeStatus; 914 915 // sanity checks 916 if (!filePath || isBlankS(filePath) || !self->value) { 917 return(0); 918 } 919 920 f = fopen(filePath, "a"); 921 if (!f) { 922 pFuncError 923 shEPrintfS("The path was: \"%s\"\n", filePath); 924 return(0); 925 } 926 writeStatus = fwrite(&self->value->value, 1, sizeof(bool) , f); 927 fclose(f); 928 929 if (writeStatus != sizeof(bool)) { 930 pFuncError 931 shEPrintfS("The path was: \"%s\"\n", filePath); 932 return(0); 933 } 934 935 return(1); 936 } 937 938 internal int appendFileSmallStringSmallBool(smallBoolt *self, smallStringt *filePath) { 939 940 if (!filePath) { 941 return(0); 942 } 943 // TODO check if filePath is really a smallString 944 return(appendFileSmallBool(self, ssGet(filePath))); 945 } 946 947 948 949 smallBoolt* duplicateSmallBoolG (smallBoolt *self) { 950 951 return(self->f->duplicate(self)); 952 } 953 954 void freeSmallBoolG (smallBoolt *self) {self->f->free(self);} 955 956 bool getBoolSmallBoolG (smallBoolt *self, bool retType UNUSED, int64_t index UNUSED) { 957 958 return(self->f->get(self)); 959 } 960 961 bool* getBoolPSmallBoolG (smallBoolt *self, bool* retType UNUSED, int64_t index UNUSED) { 962 963 return(self->f->getP(self)); 964 } 965 966 smallBoolt* setSmallBoolG(smallBoolt* self, bool p2) { 967 968 return(self->f->set(self, p2)); 969 } 970 971 smallBoolt* setDoubleSmallBoolG(smallBoolt* self, double p2) { 972 973 return(self->f->setDouble(self, p2)); 974 } 975 976 smallBoolt* setInt64SmallBoolG(smallBoolt* self, int64_t p2) { 977 978 return(self->f->setInt64(self, p2)); 979 } 980 981 smallBoolt* setInt32SmallBoolG(smallBoolt* self, int32_t p2) { 982 983 return(self->f->setInt32(self, p2)); 984 } 985 986 smallBoolt* setUint32SmallBoolG(smallBoolt* self, uint32_t p2) { 987 988 return(self->f->setUint32(self, p2)); 989 } 990 991 smallBoolt* setUint64SmallBoolG(smallBoolt* self, uint64_t p2) { 992 993 return(self->f->setUint64(self, p2)); 994 } 995 996 smallBoolt* setSSmallBoolG(smallBoolt* self, const char* p2) { 997 998 return(self->f->setS(self, p2)); 999 } 1000 1001 smallBoolt* setSmallBoolSmallBoolG(smallBoolt* self, smallBoolt* p2) { 1002 1003 return(self->f->setSmallBool(self, p2)); 1004 } 1005 1006 smallBoolt* setSmallDoubleSmallBoolG(smallBoolt* self, smallDoublet* p2) { 1007 1008 return(self->f->setSmallDouble(self, p2)); 1009 } 1010 1011 smallBoolt* setSmallIntSmallBoolG(smallBoolt* self, smallIntt* p2) { 1012 1013 return(self->f->setSmallInt(self, p2)); 1014 } 1015 1016 smallBoolt* setSmallJsonSmallBoolG(smallBoolt* self, smallJsont* p2) { 1017 1018 return(self->f->setSmallJson(self, p2)); 1019 } 1020 1021 smallBoolt* setSmallStringSmallBoolG(smallBoolt* self, smallStringt* p2) { 1022 1023 return(self->f->setSmallString(self, p2)); 1024 } 1025 1026 1027 bool equalSmallBoolCharG(smallBoolt* self, const char * p2) { 1028 1029 return(self->f->equalChar(self, p2)); 1030 } 1031 1032 bool equalSmallBoolBaseG(smallBoolt* self, baset* p2) { 1033 1034 return(self->f->equalBase(self, p2)); 1035 } 1036 1037 bool equalSmallBoolBoolG(smallBoolt* self, bool p2) { 1038 1039 return(self->f->equalBool(self, p2)); 1040 } 1041 1042 bool equalSmallBoolDoubleG(smallBoolt* self, double p2) { 1043 1044 return(self->f->equalDouble(self, p2)); 1045 } 1046 1047 bool equalSmallBoolInt64G(smallBoolt* self, int64_t p2) { 1048 1049 return(self->f->equalInt64(self, p2)); 1050 } 1051 1052 bool equalSmallBoolInt32G(smallBoolt* self, int32_t p2) { 1053 1054 return(self->f->equalInt32(self, p2)); 1055 } 1056 1057 bool equalSmallBoolUint32G(smallBoolt* self, uint32_t p2) { 1058 1059 return(self->f->equalUint32(self, p2)); 1060 } 1061 1062 bool equalSmallBoolUint64G(smallBoolt* self, uint64_t p2) { 1063 1064 return(self->f->equalUint64(self, p2)); 1065 } 1066 1067 bool equalSmallBoolFG(smallBoolt* self, smallBoolt* p2) { 1068 1069 return(self->f->equal(self, p2)); 1070 } 1071 1072 bool equalSmallBoolSmallBytesG(smallBoolt* self, smallBytest* p2) { 1073 1074 return(self->f->equalSmallBytes(self, p2)); 1075 } 1076 1077 bool equalSmallBoolSmallDoubleG(smallBoolt* self, smallDoublet* p2) { 1078 1079 return(self->f->equalSmallDouble(self, p2)); 1080 } 1081 1082 bool equalSmallBoolSmallIntG(smallBoolt* self, smallIntt* p2) { 1083 1084 return(self->f->equalSmallInt(self, p2)); 1085 } 1086 1087 bool equalSmallBoolSmallJsonG(smallBoolt* self, smallJsont* p2) { 1088 1089 return(self->f->equalSmallJson(self, p2)); 1090 } 1091 1092 bool equalSmallBoolSmallStringG(smallBoolt* self, smallStringt* p2) { 1093 1094 return(self->f->equalSmallString(self, p2)); 1095 } 1096 1097 smallBoolt* readFileSmallBoolG (smallBoolt *self, const char *filePath) { 1098 1099 return(self->f->readFile(self, filePath)); 1100 } 1101 1102 smallBoolt* readFileSmallJsonSmallBoolG(smallBoolt *self, smallJsont *filePath) { 1103 1104 return(self->f->readFileSmallJson(self,filePath)); 1105 } 1106 1107 smallBoolt* readFileSmallStringSmallBoolG(smallBoolt *self, smallStringt *filePath) { 1108 1109 return(self->f->readFileSmallString(self,filePath)); 1110 } 1111 1112 smallBoolt* readStreamSmallBoolG (smallBoolt *self, FILE *fp) { 1113 1114 return(self->f->readStream(self, fp)); 1115 } 1116 1117 int writeFileSmallBoolG (smallBoolt *self, const char *filePath) { 1118 1119 return(self->f->writeFile(self, filePath)); 1120 } 1121 1122 int writeFileSmallJsonSmallBoolG (smallBoolt *self, smallJsont *filePath) { 1123 1124 return(self->f->writeFileSmallJson(self,filePath)); 1125 } 1126 1127 int writeFileSmallStringSmallBoolG(smallBoolt *self, smallStringt *filePath) { 1128 1129 return(self->f->writeFileSmallString(self,filePath)); 1130 } 1131 1132 int writeStreamSmallBoolG (smallBoolt *self, FILE *fp) { 1133 1134 return(self->f->writeStream(self, fp)); 1135 } 1136 1137 int appendFileSmallBoolFG (smallBoolt *self, const char *filePath) { 1138 1139 return(self->f->appendFile(self, filePath)); 1140 } 1141 1142 int appendFileSmallStringSmallBoolG(smallBoolt *self, smallStringt *filePath) { 1143 1144 return(self->f->appendFileSmallString(self,filePath)); 1145 } 1146