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

libsheepyCUndefined.h (4088B)


      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 "string.h"
     25 
     26 // Class undefined
     27 typedef struct undefined undefinedt;
     28 
     29 typedef void        (*freeUndefinedFt)      (undefinedt *self);
     30 typedef void        (*terminateUndefinedFt) (undefinedt **self);
     31 typedef char*       (*toStringUndefinedFt)  (undefinedt *self);
     32 typedef undefinedt* (*duplicateUndefinedFt) (undefinedt *self);
     33 
     34 /**
     35  * free container
     36  */
     37 typedef void        (*finishUndefinedFt)    (undefinedt **self);
     38 
     39 /**
     40  * class functions
     41  * allocated once for all objects
     42  *
     43  * freed with finalizeUndefined or finalizeLibsheepy
     44  */
     45 typedef struct {
     46   freeUndefinedFt      free;
     47   terminateUndefinedFt terminate;
     48   toStringUndefinedFt  toString;
     49   duplicateUndefinedFt duplicate;
     50   terminateUndefinedFt smash;
     51   finishUndefinedFt    finish;
     52 } undefinedFunctionst;
     53 
     54 /**
     55  * class
     56  */
     57 struct undefined {
     58   const char *type;
     59   undefinedFunctionst *f;
     60 };
     61 
     62 // base
     63 
     64 #define createUndefined(obj) ;undefinedt obj; initiateUndefined(&obj)
     65 #define createAllocateUndefined(obj) ;undefinedt *obj; initiateAllocateUndefined(&obj)
     66 
     67 void initiateUndefined(undefinedt *self);
     68 void initiateAllocateUndefined(undefinedt **self);
     69 void finalizeRecycleUndefined(void *arg UNUSED);
     70 void finalizeUndefined(void);
     71 
     72 undefinedt* allocUndefined(void);
     73 
     74 // terminate undefinedt val when it is out of scope
     75 void cleanUpUndefinedTerminateG(undefinedt **val);
     76 
     77 // free undefinedt local val when it is out of scope
     78 void cleanUpUndefinedFreeLocalG(undefinedt *val);
     79 
     80 // free undefinedt val when it is out of scope
     81 void cleanUpUndefinedFreeG(undefinedt **val);
     82 
     83 // finish undefinedt val when it is out of scope
     84 void cleanUpUndefinedFinishG(undefinedt **val);
     85 
     86 // smash undefinedt val when it is out of scope
     87 void cleanUpUndefinedSmashG(undefinedt **val);
     88 
     89 /**
     90  * declare pointer name with type undefinedt and terminate name when it is out of scope
     91  */
     92 #define cleanUndefinedP(name) undefinedt *name CLEANUP(cleanUpUndefinedTerminateG)
     93 
     94 /**
     95  * allocate undefined (pointer) and clean up when it is out of scope
     96  */
     97 #define cleanAllocateUndefined(obj) ;cleanUndefinedP(obj); initiateAllocateUndefined(&obj)
     98 
     99 /**
    100  * declare local object name with type undefinedt and free name when it is out of scope
    101  */
    102 #define cleanUndefined(name) undefinedt name CLEANUP(cleanUpUndefinedFreeLocalG); initiateUndefined(&name)
    103 
    104 /**
    105  * declare pointer name with type undefinedt and free name when it is out of scope
    106  */
    107 #define cleanFreeUndefined(name) undefinedt *name CLEANUP(cleanUpUndefinedFreeG)
    108 
    109 /**
    110  * declare pointer name with Type undefinedt and finish name when it is out of scope
    111  */
    112 #define cleanFinishUndefinedP(name) undefinedt *name CLEANUP(cleanUpUndefinedFinishG)
    113 
    114 /**
    115  * declare pointer name with Type undefinedt and smash name when it is out of scope
    116  */
    117 #define cleanSmashUndefinedP(name) undefinedt *name CLEANUP(cleanUpUndefinedSmashG)
    118 
    119 
    120 undefinedt* duplicateUndefinedG (undefinedt *self);
    121 
    122 void        freeUndefinedG      (undefinedt *self);
    123 
    124 // end class undefined