libsheepy
libsheepyCSmallInt.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 <stdint.h>
25 
26 // Class smallInt
27 typedef struct smallInt smallIntt;
28 
34 #define helpTextSmallInt "TODO smallInt help brief, class description /*, definitions,*/ methods, examples"
35 
36 // for object inheriting smallInt, cast to smallInt to be able to use this class functions and generics
37 #define cIn(self) ( (smallIntt*) self )
38 
39 typedef void (*freeSmallIntFt) (smallIntt *self);
40 typedef void (*terminateSmallIntFt) (smallIntt **self);
41 typedef char* (*toStringSmallIntFt) (smallIntt *self);
42 typedef smallIntt* (*duplicateSmallIntFt) (smallIntt *self);
43 
44 // smallInt functions
51 typedef void (*smashSmallIntFt) (smallIntt **self);
52 
56 typedef void (*finishSmallIntFt) (smallIntt **self);
57 
58 typedef const char* (*helpSmallIntFt) (smallIntt *self);
59 
66 typedef int64_t (*getSmallIntFt) (smallIntt *self);
67 
74 typedef smallIntt* (*setSmallIntFt) (smallIntt *self, int64_t value);
75 
76 typedef smallIntt* (*setBoolSmallIntFt) (smallIntt* self, bool p2);
77 typedef smallIntt* (*setDoubleSmallIntFt) (smallIntt* self, double p2);
78 typedef smallIntt* (*setInt32SmallIntFt) (smallIntt* self, int32_t p2);
79 typedef smallIntt* (*setUint32SmallIntFt) (smallIntt* self, uint32_t p2);
80 typedef smallIntt* (*setUint64SmallIntFt) (smallIntt* self, uint64_t p2);
81 typedef smallIntt* (*setSSmallIntFt) (smallIntt* self, const char* p2);
82 typedef smallIntt* (*setSmallBoolSmallIntFt) (smallIntt* self, smallBoolt* p2);
83 typedef smallIntt* (*setSmallDoubleSmallIntFt)(smallIntt* self, smallDoublet* p2);
84 typedef smallIntt* (*setSmallIntSmallIntFt) (smallIntt* self, smallIntt* p2);
85 typedef smallIntt* (*setSmallJsonSmallIntFt) (smallIntt* self, smallJsont* p2);
86 typedef smallIntt* (*setSmallStringSmallIntFt)(smallIntt* self, smallStringt* p2);
87 
94 typedef int64_t* (*getPSmallIntFt) (smallIntt *self);
95 
96 typedef bool (*equalSmallIntChaFt) (smallIntt* self, char p2);
97 typedef bool (*equalSmallIntCharFt) (smallIntt* self, const char * p2);
98 typedef bool (*equalSmallIntBaseFt) (smallIntt* self, baset* p2);
99 typedef bool (*equalSmallIntBoolFt) (smallIntt* self, bool p2);
100 typedef bool (*equalSmallIntDoubleFt) (smallIntt* self, double p2);
101 typedef bool (*equalSmallIntInt64Ft) (smallIntt* self, int64_t p2);
102 typedef bool (*equalSmallIntInt32Ft) (smallIntt* self, int32_t p2);
103 typedef bool (*equalSmallIntUint32Ft) (smallIntt* self, uint32_t p2);
104 typedef bool (*equalSmallIntUint64Ft) (smallIntt* self, uint64_t p2);
105 typedef bool (*equalSmallIntSmallBoolFt) (smallIntt* self, smallBoolt* p2);
106 typedef bool (*equalSmallIntSmallBytesFt) (smallIntt* self, smallBytest* p2);
108 typedef bool (*equalSmallIntFt) (smallIntt* self, smallIntt* p2);
109 typedef bool (*equalSmallIntSmallJsonFt) (smallIntt* self, smallJsont* p2);
111 
121 typedef smallIntt* (*readFileSmallIntFt) (smallIntt *self, const char *filePath);
122 typedef smallIntt* (*readFileSmallJsonSmallIntFt) (smallIntt *self, smallJsont *filePath);
123 typedef smallIntt* (*readFileSmallStringSmallIntFt)(smallIntt *self, smallStringt *filePath);
124 typedef smallIntt* (*readStreamSmallIntFt) (smallIntt *self, FILE *fp);
125 
135 typedef int (*writeFileSmallIntFt) (smallIntt *self, const char *filePath);
136 typedef int (*writeFileSmallJsonSmallIntFt) (smallIntt *self, smallJsont *filePath);
137 typedef int (*writeFileSmallStringSmallIntFt)(smallIntt *self, smallStringt *filePath);
138 typedef int (*writeStreamSmallIntFt) (smallIntt *self, FILE *fp);
139 
149 typedef int (*appendFileSmallIntFt)(smallIntt *self, const char *filePath);
150 typedef int (*appendFileSmallStringSmallIntFt)(smallIntt *self, smallStringt *filePath);
151 
169 #define SMALLINTFUNCTIONST \
170  helpSmallIntFt help;\
171  getSmallIntFt get;\
172  setSmallIntFt set;\
173  setBoolSmallIntFt setBool;\
174  setDoubleSmallIntFt setDouble;\
175  setInt32SmallIntFt setInt32;\
176  setUint32SmallIntFt setUint32;\
177  setUint64SmallIntFt setUint64;\
178  setSSmallIntFt setS;\
179  setSmallBoolSmallIntFt setSmallBool;\
180  setSmallDoubleSmallIntFt setSmallDouble;\
181  setSmallIntSmallIntFt setSmallInt;\
182  setSmallJsonSmallIntFt setSmallJson;\
183  setSmallStringSmallIntFt setSmallString;\
184  getPSmallIntFt getP;\
185  equalSmallIntChaFt equalCha;\
186  equalSmallIntCharFt equalChar;\
187  equalSmallIntBaseFt equalBase;\
188  equalSmallIntBoolFt equalBool;\
189  equalSmallIntDoubleFt equalDouble;\
190  equalSmallIntInt64Ft equalInt64;\
191  equalSmallIntInt32Ft equalInt32;\
192  equalSmallIntUint32Ft equalUint32;\
193  equalSmallIntUint64Ft equalUint64;\
194  equalSmallIntSmallBoolFt equalSmallBool;\
195  equalSmallIntSmallBytesFt equalSmallBytes;\
196  equalSmallIntSmallDoubleFt equalSmallDouble;\
197  equalSmallIntFt equal;\
198  equalSmallIntSmallJsonFt equalSmallJson;\
199  equalSmallIntSmallStringFt equalSmallString;\
200  readFileSmallIntFt readFile;\
201  readFileSmallJsonSmallIntFt readFileSmallJson;\
202  readFileSmallStringSmallIntFt readFileSmallString;\
203  readStreamSmallIntFt readStream;\
204  writeFileSmallIntFt writeFile;\
205  writeFileSmallJsonSmallIntFt writeFileSmallJson;\
206  writeFileSmallStringSmallIntFt writeFileSmallString;\
207  writeStreamSmallIntFt writeStream;\
208  appendFileSmallIntFt appendFile;\
209  appendFileSmallStringSmallIntFt appendFileSmallString
210 
211 
212 typedef struct {
221 
225 struct smallInt {
226  const char *type;
228 
230 };
231 
232 // smallInt
233 
234 #define createSmallInt(obj) ;smallIntt obj; initiateSmallInt(&obj)
235 #define createAllocateSmallInt(obj) ;smallIntt *obj; initiateAllocateSmallInt(&obj)
236 
237 void initiateSmallInt(smallIntt *self);
239 void finalizeRecycleSmallInt(void *arg UNUSED);
240 void finalizeSmallInt(void);
241 
242 // initialize class methods, call registerMethodsSmallInt from classes inheriting this class
244 
245 smallIntt* allocSmallInt(int64_t value);
246 
247 // terminate smallIntt val when it is out of scope
249 
250 // free smallIntt local val when it is out of scope
252 
253 // free smallIntt val when it is out of scope
254 void cleanUpSmallIntFreeG(smallIntt **val);
255 
256 // finish smallIntt val when it is out of scope
258 
262 #define cleanSmallIntP(name) smallIntt *name CLEANUP(cleanUpSmallIntTerminateG)
263 
267 #define cleanAllocateSmallInt(obj) ;cleanSmallIntP(obj); initiateAllocateSmallInt(&obj)
268 
272 #define cleanSmallInt(name) smallIntt name CLEANUP(cleanUpSmallIntFreeLocalG); initiateSmallInt(&name)
273 
277 #define cleanFreeSmallInt(name) smallIntt *name CLEANUP(cleanUpSmallIntFreeG)
278 
282 #define cleanFinishSmallIntP(name) smallIntt *name CLEANUP(cleanUpSmallIntFinishG)
283 
285 
286 void freeSmallIntG (smallIntt *self);
287 
288 int64_t getIntSmallIntG (smallIntt *self, int64_t retType UNUSED, int64_t index UNUSED);
289 int64_t* getIntPSmallIntG (smallIntt *self, int64_t* retType UNUSED, int64_t index UNUSED);
290 int32_t getInt32SmallIntG (smallIntt *self, int32_t retType UNUSED, int64_t index UNUSED);
291 int32_t* getInt32PSmallIntG (smallIntt *self, int32_t* retType UNUSED, int64_t index UNUSED);
292 uint64_t getUintSmallIntG (smallIntt *self, uint64_t retType UNUSED, int64_t index UNUSED);
293 uint64_t* getUintPSmallIntG (smallIntt *self, uint64_t* retType UNUSED, int64_t index UNUSED);
294 uint32_t getUint32SmallIntG (smallIntt *self, uint32_t retType UNUSED, int64_t index UNUSED);
295 uint32_t* getUint32PSmallIntG (smallIntt *self, uint32_t* retType UNUSED, int64_t index UNUSED);
296 
297 smallIntt* setBoolSmallIntG (smallIntt* self, bool p2);
298 smallIntt* setDoubleSmallIntG (smallIntt* self, double p2);
299 smallIntt* setSmallIntG (smallIntt* self, int64_t p2);
300 smallIntt* setInt32SmallIntG (smallIntt* self, int32_t p2);
301 smallIntt* setUint32SmallIntG (smallIntt* self, uint32_t p2);
302 smallIntt* setUint64SmallIntG (smallIntt* self, uint64_t p2);
303 smallIntt* setSSmallIntG (smallIntt* self, const char* p2);
309 
310 bool equalSmallIntChaG (smallIntt* self, char p2);
311 bool equalSmallIntCharG (smallIntt* self, const char * p2);
312 bool equalSmallIntBaseG (smallIntt* self, baset* p2);
313 bool equalSmallIntBoolG (smallIntt* self, bool p2);
314 bool equalSmallIntDoubleG (smallIntt* self, double p2);
315 bool equalSmallIntInt64G (smallIntt* self, int64_t p2);
316 bool equalSmallIntInt32G (smallIntt* self, int32_t p2);
317 bool equalSmallIntUint32G (smallIntt* self, uint32_t p2);
318 bool equalSmallIntUint64G (smallIntt* self, uint64_t p2);
322 bool equalSmallIntFG (smallIntt* self, smallIntt* p2);
325 
326 smallIntt* readFileSmallIntG (smallIntt *self, const char *filePath);
329 smallIntt* readStreamSmallIntG (smallIntt *self, FILE *fp);
330 int writeFileSmallIntG (smallIntt *self, const char *filePath);
331 int writeFileSmallJsonSmallIntG (smallIntt *self, smallJsont *filePath);
333 int writeStreamSmallIntG (smallIntt *self, FILE *fp);
334 int appendFileSmallIntFG (smallIntt *self, const char *filePath); //TODO remove F - oGMacros generates a macro making the compilation fail
336 // end class smallInt
void finalizeSmallInt(void)
smallIntt * readFileSmallIntG(smallIntt *self, const char *filePath)
bool(* equalSmallIntInt64Ft)(smallIntt *self, int64_t p2)
smallIntt * setUint64SmallIntG(smallIntt *self, uint64_t p2)
void registerMethodsSmallInt(smallIntFunctionst *f)
bool equalSmallIntInt64G(smallIntt *self, int64_t p2)
void cleanUpSmallIntTerminateG(smallIntt **val)
int writeFileSmallIntG(smallIntt *self, const char *filePath)
bool(* equalSmallIntCharFt)(smallIntt *self, const char *p2)
bool equalSmallIntUint64G(smallIntt *self, uint64_t p2)
bool(* equalSmallIntBaseFt)(smallIntt *self, baset *p2)
bool equalSmallIntBaseG(smallIntt *self, baset *p2)
void(* terminateSmallIntFt)(smallIntt **self)
int writeFileSmallStringSmallIntG(smallIntt *self, smallStringt *filePath)
bool equalSmallIntCharG(smallIntt *self, const char *p2)
int64_t getIntSmallIntG(smallIntt *self, int64_t retType UNUSED, int64_t index UNUSED)
bool equalSmallIntChaG(smallIntt *self, char p2)
void finalizeRecycleSmallInt(void *arg UNUSED)
bool equalSmallIntSmallJsonG(smallIntt *self, smallJsont *p2)
bool equalSmallIntDoubleG(smallIntt *self, double p2)
void initiateSmallInt(smallIntt *self)
int writeFileSmallJsonSmallIntG(smallIntt *self, smallJsont *filePath)
int64_t(* getSmallIntFt)(smallIntt *self)
get int
smallIntt * duplicateSmallIntG(smallIntt *self)
smallIntt * setUint32SmallIntG(smallIntt *self, uint32_t p2)
const char * type
smallIntt * readStreamSmallIntG(smallIntt *self, FILE *fp)
terminateSmallIntFt terminate
bool equalSmallIntBoolG(smallIntt *self, bool p2)
bool(* equalSmallIntSmallBytesFt)(smallIntt *self, smallBytest *p2)
int(* writeFileSmallJsonSmallIntFt)(smallIntt *self, smallJsont *filePath)
small int
void(* finishSmallIntFt)(smallIntt **self)
free container
bool(* equalSmallIntSmallDoubleFt)(smallIntt *self, smallDoublet *p2)
int64_t * getIntPSmallIntG(smallIntt *self, int64_t *retType UNUSED, int64_t index UNUSED)
void cleanUpSmallIntFinishG(smallIntt **val)
uint32_t * getUint32PSmallIntG(smallIntt *self, uint32_t *retType UNUSED, int64_t index UNUSED)
int appendFileSmallStringSmallIntG(smallIntt *self, smallStringt *filePath)
bool equalSmallIntSmallDoubleG(smallIntt *self, smallDoublet *p2)
smallIntt * readFileSmallJsonSmallIntG(smallIntt *self, smallJsont *filePath)
int appendFileSmallIntFG(smallIntt *self, const char *filePath)
smallIntt * setDoubleSmallIntG(smallIntt *self, double p2)
smallIntt * allocSmallInt(int64_t value)
smallIntt * setInt32SmallIntG(smallIntt *self, int32_t p2)
uint32_t getUint32SmallIntG(smallIntt *self, uint32_t retType UNUSED, int64_t index UNUSED)
int32_t getInt32SmallIntG(smallIntt *self, int32_t retType UNUSED, int64_t index UNUSED)
int(* appendFileSmallIntFt)(smallIntt *self, const char *filePath)
append int to filePath
bool(* equalSmallIntFt)(smallIntt *self, smallIntt *p2)
int32_t * getInt32PSmallIntG(smallIntt *self, int32_t *retType UNUSED, int64_t index UNUSED)
bool equalSmallIntInt32G(smallIntt *self, int32_t p2)
END_TEST FILE * fp
bool(* equalSmallIntBoolFt)(smallIntt *self, bool p2)
bool equalSmallIntSmallStringG(smallIntt *self, smallStringt *p2)
smallIntt * setSSmallIntG(smallIntt *self, const char *p2)
uint64_t * getUintPSmallIntG(smallIntt *self, uint64_t *retType UNUSED, int64_t index UNUSED)
int(* writeStreamSmallIntFt)(smallIntt *self, FILE *fp)
bool(* equalSmallIntChaFt)(smallIntt *self, char p2)
int(* writeFileSmallStringSmallIntFt)(smallIntt *self, smallStringt *filePath)
void(* freeSmallIntFt)(smallIntt *self)
smallIntt * setSmallIntSmallIntG(smallIntt *self, smallIntt *p2)
smallIntt * setSmallIntG(smallIntt *self, int64_t p2)
smashSmallIntFt smash
int(* writeFileSmallIntFt)(smallIntt *self, const char *filePath)
write int to file
bool(* equalSmallIntSmallJsonFt)(smallIntt *self, smallJsont *p2)
void freeSmallIntG(smallIntt *self)
smallIntt * readFileSmallStringSmallIntG(smallIntt *self, smallStringt *filePath)
bool(* equalSmallIntUint64Ft)(smallIntt *self, uint64_t p2)
bool equalSmallIntUint32G(smallIntt *self, uint32_t p2)
in value value
bool equalSmallIntSmallBoolG(smallIntt *self, smallBoolt *p2)
bool(* equalSmallIntInt32Ft)(smallIntt *self, int32_t p2)
void cleanUpSmallIntFreeLocalG(smallIntt *val)
int(* appendFileSmallStringSmallIntFt)(smallIntt *self, smallStringt *filePath)
bool equalSmallIntSmallBytesG(smallIntt *self, smallBytest *p2)
void initiateAllocateSmallInt(smallIntt **self)
bool(* equalSmallIntUint32Ft)(smallIntt *self, uint32_t p2)
toStringSmallIntFt toString
void cleanUpSmallIntFreeG(smallIntt **val)
smallIntt *(* duplicateSmallIntFt)(smallIntt *self)
bool equalSmallIntFG(smallIntt *self, smallIntt *p2)
#define UNUSED
Definition: libsheepy.h:8195
smallIntt * setSmallJsonSmallIntG(smallIntt *self, smallJsont *p2)
bool(* equalSmallIntDoubleFt)(smallIntt *self, double p2)
char *(* toStringSmallIntFt)(smallIntt *self)
void(* smashSmallIntFt)(smallIntt **self)
free self but not the smallInt buffer
int writeStreamSmallIntG(smallIntt *self, FILE *fp)
smallIntt * setBoolSmallIntG(smallIntt *self, bool p2)
smallIntt * setSmallDoubleSmallIntG(smallIntt *self, smallDoublet *p2)
base class
smallIntt * setSmallBoolSmallIntG(smallIntt *self, smallBoolt *p2)
smallIntt * setSmallStringSmallIntG(smallIntt *self, smallStringt *p2)
bool(* equalSmallIntSmallBoolFt)(smallIntt *self, smallBoolt *p2)
smallIntFunctionst * f
finishSmallIntFt finish
bool(* equalSmallIntSmallStringFt)(smallIntt *self, smallStringt *p2)
uint64_t getUintSmallIntG(smallIntt *self, uint64_t retType UNUSED, int64_t index UNUSED)
duplicateSmallIntFt duplicate