libsheepy
libsheepyCUndefined.h
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2023 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 
37 typedef void (*finishUndefinedFt) (undefinedt **self);
38 
45 typedef struct {
53 
57 struct undefined {
58  const char *type;
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);
69 void finalizeRecycleUndefined(void *arg UNUSED);
70 void finalizeUndefined(void);
71 
73 
74 // terminate undefinedt val when it is out of scope
76 
77 // free undefinedt local val when it is out of scope
79 
80 // free undefinedt val when it is out of scope
82 
83 // finish undefinedt val when it is out of scope
85 
86 // smash undefinedt val when it is out of scope
88 
92 #define cleanUndefinedP(name) undefinedt *name CLEANUP(cleanUpUndefinedTerminateG)
93 
97 #define cleanAllocateUndefined(obj) ;cleanUndefinedP(obj); initiateAllocateUndefined(&obj)
98 
102 #define cleanUndefined(name) undefinedt name CLEANUP(cleanUpUndefinedFreeLocalG); initiateUndefined(&name)
103 
107 #define cleanFreeUndefined(name) undefinedt *name CLEANUP(cleanUpUndefinedFreeG)
108 
112 #define cleanFinishUndefinedP(name) undefinedt *name CLEANUP(cleanUpUndefinedFinishG)
113 
117 #define cleanSmashUndefinedP(name) undefinedt *name CLEANUP(cleanUpUndefinedSmashG)
118 
119 
121 
122 void freeUndefinedG (undefinedt *self);
123 
124 // end class undefined
terminateUndefinedFt smash
void initiateUndefined(undefinedt *self)
terminateUndefinedFt terminate
void finalizeRecycleUndefined(void *arg UNUSED)
const char * type
finishUndefinedFt finish
undefinedt *(* duplicateUndefinedFt)(undefinedt *self)
void(* finishUndefinedFt)(undefinedt **self)
free container
void cleanUpUndefinedTerminateG(undefinedt **val)
undefinedFunctionst * f
void cleanUpUndefinedFinishG(undefinedt **val)
duplicateUndefinedFt duplicate
undefinedt * allocUndefined(void)
void cleanUpUndefinedFreeG(undefinedt **val)
void cleanUpUndefinedFreeLocalG(undefinedt *val)
class functions allocated once for all objects
toStringUndefinedFt toString
void finalizeUndefined(void)
undefinedt * duplicateUndefinedG(undefinedt *self)
void freeUndefinedG(undefinedt *self)
char *(* toStringUndefinedFt)(undefinedt *self)
void(* terminateUndefinedFt)(undefinedt **self)
void(* freeUndefinedFt)(undefinedt *self)
#define UNUSED
Definition: libsheepy.h:8195
void cleanUpUndefinedSmashG(undefinedt **val)
void initiateAllocateUndefined(undefinedt **self)