libsheepy

C lib for handling text files, strings and json like data structure with an object oriented system
git clone https://spartatek.se/git/libsheepy.git
Log | Files | Refs | README | LICENSE

libsheepyCSmallInt.c (29837B)


      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 "libsheepyCSmallInt.h"
     25 #include "libsheepyCSmallIntInternal.h"
     26 #include <inttypes.h>
     27 
     28 #define internal static
     29 
     30 #include <stdbool.h>
     31 #include <stdlib.h>
     32 #include <stdint.h>
     33 #include <stdio.h>
     34 
     35 void initiateSmallInt(smallIntt *self);
     36 void registerMethodsSmallInt(smallIntFunctionst *f);
     37 void initiateAllocateSmallInt(smallIntt **self);
     38 void finalizeRecycleSmallInt(void *arg UNUSED);
     39 void finalizeSmallInt(void);
     40 smallIntt* allocSmallInt(int64_t value);
     41 void cleanUpSmallIntTerminateG(smallIntt **val);
     42 void cleanUpSmallIntFreeLocalG(smallIntt *val);
     43 void cleanUpSmallIntFreeG(smallIntt **val);
     44 void cleanUpSmallIntFinishG(smallIntt **val);
     45 internal void freeSmallInt(smallIntt *self);
     46 internal void terminateSmallInt(smallIntt **self);
     47 internal char* toStringSmallInt(smallIntt *self);
     48 internal smallIntt* duplicateSmallInt(smallIntt *self);
     49 internal void  smashSmallInt(smallIntt **self);
     50 #if (NFreeStackCheck)
     51 internal void finishSmallInt(smallIntt **self);
     52 #else
     53 internal void finishSmallInt(smallIntt **self);
     54 #endif
     55 internal const char* helpSmallInt(smallIntt UNUSED *self);
     56 internal int64_t  getSmallInt(smallIntt *self);
     57 internal smallIntt*  setSmallInt(smallIntt *self, int64_t value);
     58 internal smallIntt* setBoolSmallInt(smallIntt* self, bool p2);
     59 internal smallIntt* setDoubleSmallInt(smallIntt* self, double p2);
     60 internal smallIntt* setInt32SmallInt(smallIntt* self, int32_t p2);
     61 internal smallIntt* setUint32SmallInt(smallIntt* self, uint32_t p2);
     62 internal smallIntt* setUint64SmallInt(smallIntt* self, uint64_t p2);
     63 internal smallIntt* setSSmallInt(smallIntt* self, const char* p2);
     64 internal smallIntt* setSmallBoolSmallInt(smallIntt* self, smallBoolt* p2);
     65 internal smallIntt* setSmallDoubleSmallInt(smallIntt* self, smallDoublet* p2);
     66 internal smallIntt* setSmallIntSmallInt(smallIntt* self, smallIntt* p2);
     67 internal smallIntt* setSmallJsonSmallInt(smallIntt* self, smallJsont* p2);
     68 internal smallIntt* setSmallStringSmallInt(smallIntt* self, smallStringt* p2);
     69 internal int64_t* getPSmallInt(smallIntt *self);
     70 internal bool equalSmallIntCha(smallIntt* self, char p2);
     71 internal bool equalSmallIntChar(smallIntt* self, const char * p2);
     72 internal bool equalSmallIntBase(smallIntt* self, baset* p2);
     73 internal bool equalSmallIntBool(smallIntt* self, bool p2);
     74 internal bool equalSmallIntDouble(smallIntt* self, double p2);
     75 internal bool equalSmallIntInt64(smallIntt* self, int64_t p2);
     76 internal bool equalSmallIntInt32(smallIntt* self, int32_t p2);
     77 internal bool equalSmallIntUint32(smallIntt* self, uint32_t p2);
     78 internal bool equalSmallIntUint64(smallIntt* self, uint64_t p2);
     79 internal bool equalSmallIntSmallBool(smallIntt* self, smallBoolt* p2);
     80 internal bool equalSmallIntSmallBytes(smallIntt* self, smallBytest* p2);
     81 internal bool equalSmallIntSmallDouble(smallIntt* self, smallDoublet* p2);
     82 internal bool equalSmallInt(smallIntt* self, smallIntt* p2);
     83 internal bool equalSmallIntSmallJson(smallIntt* self, smallJsont* p2);
     84 internal bool equalSmallIntSmallString(smallIntt* self, smallStringt* p2);
     85 internal smallIntt* readFileSmallInt(smallIntt *self, const char *filePath);
     86 internal smallIntt* readFileSmallJsonSmallInt(smallIntt *self, smallJsont *filePath);
     87 internal smallIntt* readFileSmallStringSmallInt(smallIntt *self, smallStringt *filePath);
     88 internal smallIntt* readStreamSmallInt(smallIntt *self, FILE *fp);
     89 internal int writeFileSmallInt(smallIntt *self, const char *filePath);
     90 internal int writeFileSmallJsonSmallInt(smallIntt *self, smallJsont *filePath);
     91 internal int writeFileSmallStringSmallInt(smallIntt *self, smallStringt *filePath);
     92 internal int writeStreamSmallInt(smallIntt *self, FILE *fp);
     93 internal int appendFileSmallInt(smallIntt *self, const char *filePath);
     94 internal int appendFileSmallStringSmallInt(smallIntt *self, smallStringt *filePath);
     95 smallIntt*          duplicateSmallIntG       (smallIntt *self);
     96 int64_t             getIntSmallIntG          (smallIntt *self, int64_t retType UNUSED, int64_t index UNUSED);
     97 int64_t*            getIntPSmallIntG         (smallIntt *self, int64_t* retType UNUSED, int64_t index UNUSED);
     98 int32_t             getInt32SmallIntG        (smallIntt *self, int32_t retType UNUSED, int64_t index UNUSED);
     99 int32_t*            getInt32PSmallIntG       (smallIntt *self, int32_t* retType UNUSED, int64_t index UNUSED);
    100 uint64_t            getUintSmallIntG          (smallIntt *self, uint64_t retType UNUSED, int64_t index UNUSED);
    101 uint64_t*           getUintPSmallIntG         (smallIntt *self, uint64_t* retType UNUSED, int64_t index UNUSED);
    102 uint32_t            getUint32SmallIntG        (smallIntt *self, uint32_t retType UNUSED, int64_t index UNUSED);
    103 uint32_t*           getUint32PSmallIntG       (smallIntt *self, uint32_t* retType UNUSED, int64_t index UNUSED);
    104 smallIntt* setBoolSmallIntG(smallIntt* self, bool p2);
    105 smallIntt* setDoubleSmallIntG(smallIntt* self, double p2);
    106 smallIntt* setInt32SmallIntG(smallIntt* self, int32_t p2);
    107 smallIntt* setUint32SmallIntG(smallIntt* self, uint32_t p2);
    108 smallIntt* setUint64SmallIntG(smallIntt* self, uint64_t p2);
    109 smallIntt* setSSmallIntG(smallIntt* self, const char* p2);
    110 smallIntt* setSmallBoolSmallIntG(smallIntt* self, smallBoolt* p2);
    111 smallIntt* setSmallDoubleSmallIntG(smallIntt* self, smallDoublet* p2);
    112 smallIntt* setSmallIntSmallIntG(smallIntt* self, smallIntt* p2);
    113 smallIntt* setSmallJsonSmallIntG(smallIntt* self, smallJsont* p2);
    114 smallIntt* setSmallStringSmallIntG(smallIntt* self, smallStringt* p2);
    115 bool equalSmallIntChaG(smallIntt* self, char p2);
    116 bool equalSmallIntCharG(smallIntt* self, const char * p2);
    117 bool equalSmallIntBaseG(smallIntt* self, baset* p2);
    118 bool equalSmallIntBoolG(smallIntt* self, bool p2);
    119 bool equalSmallIntDoubleG(smallIntt* self, double p2);
    120 bool equalSmallIntInt64G(smallIntt* self, int64_t p2);
    121 bool equalSmallIntInt32G(smallIntt* self, int32_t p2);
    122 bool equalSmallIntUint32G(smallIntt* self, uint32_t p2);
    123 bool equalSmallIntUint64G(smallIntt* self, uint64_t p2);
    124 bool equalSmallIntSmallBoolG(smallIntt* self, smallBoolt* p2);
    125 bool equalSmallIntSmallBytesG(smallIntt* self, smallBytest* p2);
    126 bool equalSmallIntSmallDoubleG(smallIntt* self, smallDoublet* p2);
    127 bool equalSmallIntFG(smallIntt* self, smallIntt* p2);
    128 bool equalSmallIntSmallJsonG(smallIntt* self, smallJsont* p2);
    129 bool equalSmallIntSmallStringG(smallIntt* self, smallStringt* p2);
    130 smallIntt*  readFileSmallIntG     (smallIntt *self, const char *filePath);
    131 smallIntt* readFileSmallJsonSmallIntG  (smallIntt *self, smallJsont *filePath);
    132 smallIntt* readFileSmallStringSmallIntG(smallIntt *self, smallStringt *filePath);
    133 smallIntt* readStreamSmallIntG         (smallIntt *self, FILE *fp);
    134 int  writeFileSmallIntG    (smallIntt *self, const char *filePath);
    135 int writeFileSmallJsonSmallIntG  (smallIntt *self, smallJsont *filePath);
    136 int writeFileSmallStringSmallIntG(smallIntt *self, smallStringt *filePath);
    137 int writeStreamSmallIntG         (smallIntt *self, FILE *fp);
    138 int appendFileSmallIntFG           (smallIntt *self, const char *filePath);
    139 int appendFileSmallStringSmallIntG(smallIntt *self, smallStringt *filePath);
    140 
    141 void initiateSmallInt(smallIntt *self) {
    142 
    143   self->type = "smallInt";
    144   if (!smallIntF) {
    145     isError(smallIntF, malloc(sizeof(smallIntFunctionst))) {
    146       self->f = NULL;
    147       return;
    148     }
    149     registerMethodsSmallInt(smallIntF);
    150   }
    151   self->f = smallIntF;
    152 
    153   self->value = NULL;
    154 }
    155 
    156 void registerMethodsSmallInt(smallIntFunctionst *f) {
    157 
    158   f->free                  = freeSmallInt;
    159   f->terminate             = terminateSmallInt;
    160   f->toString              = toStringSmallInt;
    161   f->duplicate             = duplicateSmallInt;
    162   f->smash                 = smashSmallInt;
    163   f->finish                = finishSmallInt;
    164   f->help                  = helpSmallInt;
    165   f->get                   = getSmallInt;
    166   f->set                   = setSmallInt;
    167   f->setBool               = setBoolSmallInt;
    168   f->setDouble             = setDoubleSmallInt;
    169   f->setInt32              = setInt32SmallInt;
    170   f->setUint32             = setUint32SmallInt;
    171   f->setUint64             = setUint64SmallInt;
    172   f->setS                  = setSSmallInt;
    173   f->setSmallBool          = setSmallBoolSmallInt;
    174   f->setSmallDouble        = setSmallDoubleSmallInt;
    175   f->setSmallInt           = setSmallIntSmallInt;
    176   f->setSmallJson          = setSmallJsonSmallInt;
    177   f->setSmallString        = setSmallStringSmallInt;
    178   f->getP                  = getPSmallInt;
    179   f->equalCha              = equalSmallIntCha;
    180   f->equalChar             = equalSmallIntChar;
    181   f->equalBase             = equalSmallIntBase;
    182   f->equalBool             = equalSmallIntBool;
    183   f->equalDouble           = equalSmallIntDouble;
    184   f->equalInt64            = equalSmallIntInt64;
    185   f->equalInt32            = equalSmallIntInt32;
    186   f->equalUint32           = equalSmallIntUint32;
    187   f->equalUint64           = equalSmallIntUint64;
    188   f->equalSmallBool        = equalSmallIntSmallBool;
    189   f->equalSmallBytes       = equalSmallIntSmallBytes;
    190   f->equalSmallDouble      = equalSmallIntSmallDouble;
    191   f->equal                 = equalSmallInt;
    192   f->equalSmallJson        = equalSmallIntSmallJson;
    193   f->equalSmallString      = equalSmallIntSmallString;
    194   f->readFile              = readFileSmallInt;
    195   f->readFileSmallJson     = readFileSmallJsonSmallInt;
    196   f->readFileSmallString   = readFileSmallStringSmallInt;
    197   f->readStream            = readStreamSmallInt;
    198   f->writeFile             = writeFileSmallInt;
    199   f->writeFileSmallJson    = writeFileSmallJsonSmallInt;
    200   f->writeFileSmallString  = writeFileSmallStringSmallInt;
    201   f->writeStream           = writeStreamSmallInt;
    202   f->appendFile            = appendFileSmallInt;
    203   f->appendFileSmallString = appendFileSmallStringSmallInt;
    204 }
    205 
    206 void initiateAllocateSmallInt(smallIntt **self) {
    207 
    208   if (self) {
    209     #if (recycleContainers)
    210     initAllocateRecycle(smallIntt);
    211     #else
    212     isError(*self, malloc(sizeof(smallIntt)))
    213       return;
    214     #endif
    215     if (*self) {
    216       initiateSmallInt(*self);
    217       if (!(*self)->f) {
    218         finishSmallInt(self);
    219 }
    220   }
    221     }
    222       }
    223 
    224 void finalizeRecycleSmallInt(void *arg UNUSED) {
    225 
    226   #if (recycleContainers)
    227   finalizeRecycle
    228   #endif
    229   // recycleContainers
    230 }
    231 
    232 void finalizeSmallInt(void) {
    233 
    234   if (smallIntF) {
    235     free(smallIntF);
    236     smallIntF = NULL;
    237   }
    238   finalizeRecycleSmallInt(NULL);
    239 }
    240 
    241 smallIntt* allocSmallInt(int64_t value) {
    242   smallIntt *r = NULL;
    243 
    244   initiateAllocateSmallInt(&r);
    245   if (!r) {
    246     return(NULL);
    247   }
    248   isError(r->value, allocSInt(value)) {
    249     terminateO(r);
    250     return(NULL);
    251   }
    252   return(r);
    253 }
    254 
    255 void cleanUpSmallIntTerminateG(smallIntt **val) {
    256 
    257   terminateO(*val);
    258 }
    259 
    260 void cleanUpSmallIntFreeLocalG(smallIntt *val) {
    261 
    262   freeO(val);
    263 }
    264 
    265 void cleanUpSmallIntFreeG(smallIntt **val) {
    266 
    267   freeO(*val);
    268 }
    269 
    270 void cleanUpSmallIntFinishG(smallIntt **val) {
    271 
    272   finishO(*val);
    273 }
    274 
    275 internal void freeSmallInt(smallIntt *self) {
    276 
    277   if (self->value) {
    278     free(self->value);
    279     self->value = NULL;
    280   }
    281   return;
    282 }
    283 
    284 internal void terminateSmallInt(smallIntt **self) {
    285 
    286   freeSmallInt(*self);
    287   finishSmallInt(self);
    288 }
    289 
    290 
    291 internal char* toStringSmallInt(smallIntt *self) {
    292   char *s = NULL;
    293 
    294   if (!self->value) {
    295     return(NULL);
    296   }
    297   s = malloc(256*sizeof(char));
    298   if (!s) {
    299     return(NULL);
    300   }
    301   snprintf(s,256, "%" PRIi64, self->value->value);
    302 
    303   return(s);
    304 }
    305 
    306 internal smallIntt* duplicateSmallInt(smallIntt *self) {
    307 
    308   createAllocateSmallInt(dup);
    309   if (!dup) {
    310     return(NULL);
    311   }
    312   if (self->value) {
    313     isError(dup->value, allocSInt(self->value->value)) {
    314       terminateO(dup);
    315       return(NULL);
    316     }
    317   }
    318   return(dup);
    319 }
    320 
    321 internal void  smashSmallInt(smallIntt **self) {
    322 
    323   finishSmallInt(self);
    324 }
    325 
    326 #if (NFreeStackCheck)
    327 internal void finishSmallInt(smallIntt **self) {
    328 
    329   register u64 rsp asm("rsp");
    330   if ((u64)*self > rsp) {
    331     logW("Probably trying to free a smallInt on stack: "BLD PRIx64 RST" sp: "BLD PRIx64 RST, *self, rsp);
    332     logBtrace;
    333   }
    334   else {
    335     #if (recycleContainers)
    336     finishRecycle
    337     #else
    338     free(*self);
    339     #endif
    340     // recycleContainers
    341     *self = NULL;
    342 }
    343   }
    344 
    345 #else
    346 // #if NFreeStackCheck
    347 internal void finishSmallInt(smallIntt **self) {
    348 
    349   #if (recycleContainers)
    350   finishRecycle
    351   #else
    352   free(*self);
    353   #endif
    354   // recycleContainers
    355   *self = NULL;
    356 }
    357 
    358 #endif
    359 // #if NFreeStackCheck
    360 
    361 internal const char* helpSmallInt(smallIntt UNUSED *self) {
    362 
    363   return(helpTextSmallInt);
    364 }
    365 
    366 internal int64_t  getSmallInt(smallIntt *self) {
    367 
    368   if (!self->value) {
    369     return(0);
    370   }
    371   return(self->value->value);
    372 }
    373 
    374 internal smallIntt*  setSmallInt(smallIntt *self, int64_t value) {
    375 
    376   if (!self->value) {
    377     isError(self->value, allocSInt(value)) return(NULL);
    378   }
    379   else {
    380     self->value->value = value;
    381   }
    382   return(self);
    383 }
    384 
    385 internal smallIntt* setBoolSmallInt(smallIntt* self, bool p2) {
    386 
    387   if (!self->value) {
    388     isError(self->value, allocSInt((int64_t)p2)) return(NULL);
    389   }
    390   else {
    391     self->value->value = (int64_t)p2;
    392   }
    393   return(self);
    394 }
    395 
    396 internal smallIntt* setDoubleSmallInt(smallIntt* self, double p2) {
    397 
    398   if (!self->value) {
    399     isError(self->value, allocSInt((int64_t)p2)) return(NULL);
    400   }
    401   else {
    402     self->value->value = (int64_t)p2;
    403   }
    404   return(self);
    405 }
    406 
    407 internal smallIntt* setInt32SmallInt(smallIntt* self, int32_t p2) {
    408 
    409   if (!self->value) {
    410     isError(self->value, allocSInt((int64_t)p2)) return(NULL);
    411   }
    412   else {
    413     self->value->value = (int64_t)p2;
    414   }
    415   return(self);
    416 }
    417 
    418 internal smallIntt* setUint32SmallInt(smallIntt* self, uint32_t p2) {
    419 
    420   if (!self->value) {
    421     isError(self->value, allocSInt((int64_t)p2)) return(NULL);
    422   }
    423   else {
    424     self->value->value = (int64_t)p2;
    425   }
    426   return(self);
    427 }
    428 
    429 internal smallIntt* setUint64SmallInt(smallIntt* self, uint64_t p2) {
    430 
    431   if (!self->value) {
    432     isError(self->value, allocSInt((int64_t)p2)) return(NULL);
    433   }
    434   else {
    435     self->value->value = (int64_t)p2;
    436   }
    437   return(self);
    438 }
    439 
    440 internal smallIntt* setSSmallInt(smallIntt* self, const char* p2) {
    441 
    442   if (!p2 || !isNumber(p2)) {
    443     return(NULL);
    444   }
    445   if (!self->value) {
    446     isError(self->value, allocSInt(parseInt(p2))) return(NULL);
    447   }
    448   else {
    449     self->value->value = parseInt(p2);
    450   }
    451   return(self);
    452 }
    453 
    454 internal smallIntt* setSmallBoolSmallInt(smallIntt* self, smallBoolt* p2) {
    455   bool value;
    456 
    457   if (!p2) {
    458     return(NULL);
    459   }
    460 
    461   value = p2->f->get(p2);
    462 
    463   if (!self->value) {
    464     isError(self->value, allocSInt((int64_t)value)) return(NULL);
    465   }
    466   else {
    467     self->value->value = (int64_t)value;
    468   }
    469   return(self);
    470 }
    471 
    472 internal smallIntt* setSmallDoubleSmallInt(smallIntt* self, smallDoublet* p2) {
    473 
    474   if (!p2) {
    475     return(NULL);
    476   }
    477 
    478   if (!self->value) {
    479     isError(self->value, allocSInt((int64_t)p2->f->get(p2))) return(NULL);
    480   }
    481   else {
    482     self->value->value = (int64_t)p2->f->get(p2);
    483   }
    484   return(self);
    485 }
    486 
    487 internal smallIntt* setSmallIntSmallInt(smallIntt* self, smallIntt* p2) {
    488 
    489   if (!p2) {
    490     return(NULL);
    491   }
    492 
    493   if (!self->value) {
    494     isError(self->value, allocSInt(p2->f->get(p2))) return(NULL);
    495   }
    496   else {
    497     self->value->value = p2->f->get(p2);
    498   }
    499   return(self);
    500 }
    501 
    502 internal smallIntt* setSmallJsonSmallInt(smallIntt* self, smallJsont* p2) {
    503 
    504   if (!p2) {
    505     return(NULL);
    506   }
    507 
    508   const char *type = getTopTypeO(p2);
    509 
    510   if (!type || eqS(type, "undefined") || eqS(type, "dict") || eqS(type, "array")) {
    511     return(NULL);
    512   }
    513 
    514   if (eqS(type, "bool")) {
    515     return(setBoolSmallInt(self, getTopBoolO(p2)));
    516   }
    517   else if (eqS(type, "double")) {
    518     return(setDoubleSmallInt(self, getTopDoubleO(p2)));
    519   }
    520   else if (eqS(type, "int")) {
    521     return(setSmallInt(self, getTopIntO(p2)));
    522   }
    523   else if (eqS(type, "string")) {
    524     return(setSSmallInt(self, getTopSO(p2)));
    525   }
    526 
    527   return(NULL);
    528 }
    529 
    530 internal smallIntt* setSmallStringSmallInt(smallIntt* self, smallStringt* p2) {
    531 
    532   if (!p2 || !isNumberO(p2)) {
    533     return(NULL);
    534   }
    535   if (!self->value) {
    536     isError(self->value, allocSInt(parseIntO(p2))) return(NULL);
    537   }
    538   else {
    539     self->value->value = parseIntO(p2);
    540   }
    541   return(self);
    542 }
    543 
    544 internal int64_t* getPSmallInt(smallIntt *self) {
    545 
    546   if (!self->value) {
    547     return(NULL);
    548   }
    549   return(&(self->value->value));
    550 }
    551 
    552 internal bool equalSmallIntCha(smallIntt* self, char p2) {
    553 
    554   if (!self->value) {
    555     return(false);
    556   }
    557 
    558   charToS(s, p2);
    559 
    560   if (!isInt(s)) {
    561     return(false);
    562   }
    563 
    564   int64_t value = parseInt(s);
    565 
    566   return(self->value->value == value);;
    567 }
    568 
    569 internal bool equalSmallIntChar(smallIntt* self, const char * p2) {
    570 
    571   if (!self->value || !p2) {
    572     return(false);
    573   }
    574 
    575   if (!isInt(p2)) {
    576     return(false);
    577   }
    578 
    579   int64_t value = parseInt(p2);
    580 
    581   return(self->value->value == value);;
    582 }
    583 
    584 internal bool equalSmallIntBase(smallIntt* self, baset* p2) {
    585 
    586   if (!self->value || !p2) {
    587     return(false);
    588   }
    589 
    590   char *s = toStringO(p2);
    591 
    592   if (!isInt(s)) {
    593     free(s);
    594     return(false);
    595   }
    596 
    597   int64_t value = parseInt(s);
    598 
    599   bool r;
    600   if (self->value->value == value) {
    601     r = true;
    602   }
    603   else {
    604     r = false;
    605   }
    606   free(s);
    607   return(r);
    608 }
    609 
    610 internal bool equalSmallIntBool(smallIntt* self, bool p2) {
    611 
    612   if (!self->value) {
    613     return(false);
    614   }
    615 
    616   return(self->value->value == p2);;
    617 }
    618 
    619 internal bool equalSmallIntDouble(smallIntt* self, double p2) {
    620 
    621   if (!self->value) {
    622     return(false);
    623   }
    624 
    625   return(self->value->value == p2);;
    626 }
    627 
    628 internal bool equalSmallIntInt64(smallIntt* self, int64_t p2) {
    629 
    630   if (!self->value) {
    631     return(false);
    632   }
    633 
    634   return(self->value->value == p2);;
    635 }
    636 
    637 internal bool equalSmallIntInt32(smallIntt* self, int32_t p2) {
    638 
    639   if (!self->value) {
    640     return(false);
    641   }
    642 
    643   return(self->value->value == p2);;
    644 }
    645 
    646 internal bool equalSmallIntUint32(smallIntt* self, uint32_t p2) {
    647 
    648   if (!self->value) {
    649     return(false);
    650   }
    651 
    652   return(self->value->value == p2);;
    653 }
    654 
    655 internal bool equalSmallIntUint64(smallIntt* self, uint64_t p2) {
    656 
    657   if (!self->value) {
    658     return(false);
    659   }
    660 
    661   return((uint64_t)self->value->value == p2);;
    662 }
    663 
    664 internal bool equalSmallIntSmallBool(smallIntt* self, smallBoolt* p2) {
    665 
    666   if (!self->value || !p2 || !p2->value) {
    667     return(false);
    668   }
    669 
    670   return(self->value->value == p2->value->value);;
    671 }
    672 
    673 internal bool equalSmallIntSmallBytes(smallIntt* self, smallBytest* p2) {
    674 
    675   if (!self->value || !p2 || !p2->B) {
    676     return(false);
    677   }
    678 
    679   char *s = sBytesGet(p2->B);
    680 
    681   bool has0 = false;
    682   rangeDown(i, p2->B->count) {
    683     if (s[i] == 0) {
    684       has0 = true;
    685       break;
    686     }
    687   }
    688 
    689   if (!has0) {
    690     return(false);
    691   }
    692 
    693   if (!isInt(s)) {
    694     return(false);
    695   }
    696 
    697   int64_t p2Value = parseInt(s);
    698 
    699   return(p2Value == self->value->value);;
    700 }
    701 
    702 internal bool equalSmallIntSmallDouble(smallIntt* self, smallDoublet* p2) {
    703 
    704   if (!self->value || !p2 || !p2->value) {
    705     return(false);
    706   }
    707 
    708   return(self->value->value == p2->value->value);;
    709 }
    710 
    711 internal bool equalSmallInt(smallIntt* self, smallIntt* p2) {
    712 
    713   if (!self->value || !p2 || !p2->value) {
    714     return(false);
    715   }
    716 
    717   return(self->value->value == p2->value->value);;
    718 }
    719 
    720 internal bool equalSmallIntSmallJson(smallIntt* self, smallJsont* p2) {
    721 
    722   // sanity checks
    723   if (!p2) {
    724     return(false);
    725   }
    726 
    727   if (checkObjectTypes && !isOSmallJson(p2)) {
    728     return(false);
    729   }
    730 
    731   return(p2->f->equalSmallInt(p2, self));
    732 }
    733 
    734 internal bool equalSmallIntSmallString(smallIntt* self, smallStringt* p2) {
    735 
    736   if (!self->value || !p2 || !p2->data) {
    737     return(false);
    738   }
    739 
    740   if (!isIntO(p2)) {
    741     return(false);
    742   }
    743 
    744   int64_t value = parseIntO(p2);
    745 
    746   return(self->value->value == value);;
    747 }
    748 
    749 internal smallIntt* readFileSmallInt(smallIntt *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, allocSInt(0)) 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(int64_t) , f);
    769   fclose(f);
    770 
    771   if (readStatus != sizeof(int64_t)) {
    772     pFuncError
    773     shEPrintfS("The path was: \"%s\"\n", filePath);
    774     return(NULL);
    775   }
    776 
    777   return(self);
    778 }
    779 
    780 internal smallIntt* readFileSmallJsonSmallInt(smallIntt *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(readFileSmallInt(self, getTopSO(filePath)));
    797 }
    798 
    799 internal smallIntt* readFileSmallStringSmallInt(smallIntt *self, smallStringt *filePath) {
    800 
    801   if (!filePath) {
    802     return(NULL);
    803   }
    804 
    805   if (checkObjectTypes && !isOSmallString(filePath)) {
    806     return(NULL);
    807   }
    808 
    809   return(readFileSmallInt(self, ssGet(filePath)));
    810 }
    811 
    812 internal smallIntt* readStreamSmallInt(smallIntt *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, allocSInt(0)) return(NULL);
    822   }
    823 
    824   readStatus = fread(&self->value->value, 1, sizeof(int64_t) , fp);
    825 
    826   if (readStatus != sizeof(int64_t)) {
    827     pFuncError
    828     return(NULL);
    829   }
    830 
    831   return(self);
    832 }
    833 
    834 internal int writeFileSmallInt(smallIntt *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(int64_t) , f);
    850   fclose(f);
    851 
    852   if (writeStatus != sizeof(int64_t)) {
    853     pFuncError
    854     shEPrintfS("The path was: \"%s\"\n", filePath);
    855     return(0);
    856   }
    857 
    858   return(1);
    859 }
    860 
    861 internal int writeFileSmallJsonSmallInt(smallIntt *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(writeFileSmallInt(self, getTopSO(filePath)));
    878 }
    879 
    880 internal int writeFileSmallStringSmallInt(smallIntt *self, smallStringt *filePath) {
    881 
    882   if (!filePath) {
    883     return(0);
    884   }
    885 
    886   if (checkObjectTypes && !isOSmallString(filePath)) {
    887     return(0);
    888   }
    889 
    890   return(writeFileSmallInt(self, ssGet(filePath)));
    891 }
    892 
    893 internal int writeStreamSmallInt(smallIntt *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(int64_t) , fp);
    902 
    903   if (writeStatus != sizeof(int64_t)) {
    904     pFuncError
    905     return(0);
    906   }
    907 
    908   return(1);
    909 }
    910 
    911 internal int appendFileSmallInt(smallIntt *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(int64_t) , f);
    927   fclose(f);
    928 
    929   if (writeStatus != sizeof(int64_t)) {
    930     pFuncError
    931     shEPrintfS("The path was: \"%s\"\n", filePath);
    932     return(0);
    933   }
    934 
    935   return(1);
    936 }
    937 
    938 internal int appendFileSmallStringSmallInt(smallIntt *self, smallStringt *filePath) {
    939 
    940   if (!filePath) {
    941     return(0);
    942   }
    943   return(appendFileSmallInt(self, ssGet(filePath)));
    944 }
    945 
    946 smallIntt*          duplicateSmallIntG       (smallIntt *self) {
    947 
    948   return(self->f->duplicate(self));
    949 }
    950 
    951 void                freeSmallIntG            (smallIntt *self) {self->f->free(self);}
    952 
    953 int64_t             getIntSmallIntG          (smallIntt *self, int64_t retType UNUSED, int64_t index UNUSED) {
    954 
    955   return(self->f->get(self));
    956 }
    957 
    958 int64_t*            getIntPSmallIntG         (smallIntt *self, int64_t* retType UNUSED, int64_t index UNUSED) {
    959 
    960   return(self->f->getP(self));
    961 }
    962 
    963 int32_t             getInt32SmallIntG        (smallIntt *self, int32_t retType UNUSED, int64_t index UNUSED) {
    964 
    965   return((int32_t)self->f->get(self));
    966 }
    967 
    968 int32_t*            getInt32PSmallIntG       (smallIntt *self, int32_t* retType UNUSED, int64_t index UNUSED) {
    969 
    970   return((int32_t*)self->f->getP(self));
    971 }
    972 
    973 uint64_t            getUintSmallIntG          (smallIntt *self, uint64_t retType UNUSED, int64_t index UNUSED) {
    974 
    975   return((uint64_t)self->f->get(self));
    976 }
    977 
    978 uint64_t*           getUintPSmallIntG         (smallIntt *self, uint64_t* retType UNUSED, int64_t index UNUSED) {
    979 
    980   return((uint64_t*)self->f->getP(self));
    981 }
    982 
    983 uint32_t            getUint32SmallIntG        (smallIntt *self, uint32_t retType UNUSED, int64_t index UNUSED) {
    984 
    985   return((uint32_t)self->f->get(self));
    986 }
    987 
    988 uint32_t*           getUint32PSmallIntG       (smallIntt *self, uint32_t* retType UNUSED, int64_t index UNUSED) {
    989 
    990   return((uint32_t*)self->f->getP(self));
    991 }
    992 
    993 smallIntt* setBoolSmallIntG(smallIntt* self, bool p2) {
    994 
    995   return(self->f->setBool(self, p2));
    996 }
    997 
    998 smallIntt* setDoubleSmallIntG(smallIntt* self, double p2) {
    999 
   1000   return(self->f->setDouble(self, p2));
   1001 }
   1002 
   1003 smallIntt* setInt32SmallIntG(smallIntt* self, int32_t p2) {
   1004 
   1005   return(self->f->setInt32(self, p2));
   1006 }
   1007 
   1008 smallIntt* setUint32SmallIntG(smallIntt* self, uint32_t p2) {
   1009 
   1010   return(self->f->setUint32(self, p2));
   1011 }
   1012 
   1013 smallIntt* setUint64SmallIntG(smallIntt* self, uint64_t p2) {
   1014 
   1015   return(self->f->setUint64(self, p2));
   1016 }
   1017 
   1018 smallIntt* setSSmallIntG(smallIntt* self, const char* p2) {
   1019 
   1020   return(self->f->setS(self, p2));
   1021 }
   1022 
   1023 smallIntt* setSmallBoolSmallIntG(smallIntt* self, smallBoolt* p2) {
   1024 
   1025   return(self->f->setSmallBool(self, p2));
   1026 }
   1027 
   1028 smallIntt* setSmallDoubleSmallIntG(smallIntt* self, smallDoublet* p2) {
   1029 
   1030   return(self->f->setSmallDouble(self, p2));
   1031 }
   1032 
   1033 smallIntt* setSmallIntSmallIntG(smallIntt* self, smallIntt* p2) {
   1034 
   1035   return(self->f->setSmallInt(self, p2));
   1036 }
   1037 
   1038 smallIntt* setSmallJsonSmallIntG(smallIntt* self, smallJsont* p2) {
   1039 
   1040   return(self->f->setSmallJson(self, p2));
   1041 }
   1042 
   1043 smallIntt* setSmallStringSmallIntG(smallIntt* self, smallStringt* p2) {
   1044 
   1045   return(self->f->setSmallString(self, p2));
   1046 }
   1047 
   1048 
   1049 bool equalSmallIntChaG(smallIntt* self, char p2) {
   1050 
   1051   return(self->f->equalCha(self, p2));
   1052 }
   1053 
   1054 bool equalSmallIntCharG(smallIntt* self, const char * p2) {
   1055 
   1056   return(self->f->equalChar(self, p2));
   1057 }
   1058 
   1059 bool equalSmallIntBaseG(smallIntt* self, baset* p2) {
   1060 
   1061   return(self->f->equalBase(self, p2));
   1062 }
   1063 
   1064 bool equalSmallIntBoolG(smallIntt* self, bool p2) {
   1065 
   1066   return(self->f->equalBool(self, p2));
   1067 }
   1068 
   1069 bool equalSmallIntDoubleG(smallIntt* self, double p2) {
   1070 
   1071   return(self->f->equalDouble(self, p2));
   1072 }
   1073 
   1074 bool equalSmallIntInt64G(smallIntt* self, int64_t p2) {
   1075 
   1076   return(self->f->equalInt64(self, p2));
   1077 }
   1078 
   1079 bool equalSmallIntInt32G(smallIntt* self, int32_t p2) {
   1080 
   1081   return(self->f->equalInt32(self, p2));
   1082 }
   1083 
   1084 bool equalSmallIntUint32G(smallIntt* self, uint32_t p2) {
   1085 
   1086   return(self->f->equalUint32(self, p2));
   1087 }
   1088 
   1089 bool equalSmallIntUint64G(smallIntt* self, uint64_t p2) {
   1090 
   1091   return(self->f->equalUint64(self, p2));
   1092 }
   1093 
   1094 bool equalSmallIntSmallBoolG(smallIntt* self, smallBoolt* p2) {
   1095 
   1096   return(self->f->equalSmallBool(self, p2));
   1097 }
   1098 
   1099 bool equalSmallIntSmallBytesG(smallIntt* self, smallBytest* p2) {
   1100 
   1101   return(self->f->equalSmallBytes(self, p2));
   1102 }
   1103 
   1104 bool equalSmallIntSmallDoubleG(smallIntt* self, smallDoublet* p2) {
   1105 
   1106   return(self->f->equalSmallDouble(self, p2));
   1107 }
   1108 
   1109 bool equalSmallIntFG(smallIntt* self, smallIntt* p2) {
   1110 
   1111   return(self->f->equal(self, p2));
   1112 }
   1113 
   1114 bool equalSmallIntSmallJsonG(smallIntt* self, smallJsont* p2) {
   1115 
   1116   return(self->f->equalSmallJson(self, p2));
   1117 }
   1118 
   1119 bool equalSmallIntSmallStringG(smallIntt* self, smallStringt* p2) {
   1120 
   1121   return(self->f->equalSmallString(self, p2));
   1122 }
   1123 
   1124 smallIntt*  readFileSmallIntG     (smallIntt *self, const char *filePath) {
   1125 
   1126   return(self->f->readFile(self, filePath));
   1127 }
   1128 
   1129 smallIntt* readFileSmallJsonSmallIntG  (smallIntt *self, smallJsont *filePath) {
   1130 
   1131   return(self->f->readFileSmallJson(self,filePath));
   1132 }
   1133 
   1134 smallIntt* readFileSmallStringSmallIntG(smallIntt *self, smallStringt *filePath) {
   1135 
   1136   return(self->f->readFileSmallString(self,filePath));
   1137 }
   1138 
   1139 smallIntt* readStreamSmallIntG         (smallIntt *self, FILE *fp) {
   1140 
   1141   return(self->f->readStream(self, fp));
   1142 }
   1143 
   1144 int  writeFileSmallIntG    (smallIntt *self, const char *filePath) {
   1145 
   1146   return(self->f->writeFile(self, filePath));
   1147 }
   1148 
   1149 int writeFileSmallJsonSmallIntG  (smallIntt *self, smallJsont *filePath) {
   1150 
   1151   return(self->f->writeFileSmallJson(self,filePath));
   1152 }
   1153 
   1154 int writeFileSmallStringSmallIntG(smallIntt *self, smallStringt *filePath) {
   1155 
   1156   return(self->f->writeFileSmallString(self,filePath));
   1157 }
   1158 
   1159 int writeStreamSmallIntG         (smallIntt *self, FILE *fp) {
   1160 
   1161   return(self->f->writeStream(self, fp));
   1162 }
   1163 
   1164 int appendFileSmallIntFG           (smallIntt *self, const char *filePath) {
   1165 
   1166   return(self->f->appendFile(self, filePath));
   1167 }
   1168 
   1169 int appendFileSmallStringSmallIntG(smallIntt *self, smallStringt *filePath) {
   1170 
   1171   return(self->f->appendFileSmallString(self,filePath));
   1172 }
   1173