libsheepy
libsheepyCSmallBytes.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 // Class smallBytes
25 typedef struct smallBytes smallBytest;
26 
32 #define helpTextSmallBytes "TODO smallBytes help brief, class description /*, definitions,*/ methods, examples"
33 
34 // for object inheriting smallBytes, cast to smallBytes to be able to use this class functions and generics
35 #define cBy(self) ( (smallBytest*) self )
36 
37 typedef void (*freeSmallBytesFt) (smallBytest *self);
38 typedef void (*terminateSmallBytesFt) (smallBytest **self);
39 typedef char* (*toStringSmallBytesFt) (smallBytest *self);
40 typedef smallBytest* (*duplicateSmallBytesFt) (smallBytest *self);
41 
45 typedef void (*finishSmallBytesFt)(smallBytest **self);
46 
47 typedef const char* (*helpSmallBytesFt) (smallBytest *self);
48 
52 typedef void* (*getSmallBytesFt) (smallBytest *self);
53 
64 typedef smallBytest* (*setSmallBytesFt) (smallBytest *self, void *data, uint32_t size);
65 
72 typedef smallBytest* (*pushSmallBytesFt) (smallBytest *self, char data);
73 
82 typedef smallBytest* (*pushBufferSmallBytesFt) (smallBytest *self, void *data, uint32_t size);
83 
92 typedef char (*getAtSmallBytesFt) (smallBytest *self, int64_t index);
93 
101 typedef size_t (*lenSmallBytesFt) (smallBytest *self);
102 
108 typedef bool (*isEmptySmallBytesFt)(smallBytest *self);
109 
119 typedef smallBytest* (*readFileSmallBytesFt)(smallBytest *self, const char *filePath);
120 typedef smallBytest* (*readFileSmallJsonSmallBytesFt)(smallBytest *self, smallJsont *filePath);
121 typedef smallBytest* (*readFileSmallStringSmallBytesFt)(smallBytest *self, smallStringt *filePath);
122 typedef smallBytest* (*readStreamSmallBytesFt)(smallBytest *self, FILE *fp);
123 
133 typedef int (*writeFileSmallBytesFt)(smallBytest *self, const char *filePath);
134 typedef int (*writeFileSmallJsonSmallBytesFt)(smallBytest *self, smallJsont *filePath);
136 typedef int (*writeStreamSmallBytesFt)(smallBytest *self, FILE *fp);
137 
148 typedef int (*appendFileSmallBytesFt)(smallBytest *self, const char *filePath);
150 
162 typedef bool (*equalSmallBytesBoolFt)(smallBytest *self, bool value);
163 typedef bool (*equalSmallBytesDoubleFt)(smallBytest *self, double value);
164 typedef bool (*equalSmallBytesInt64Ft)(smallBytest *self, int64_t value);
165 typedef bool (*equalSmallBytesInt32Ft)(smallBytest *self, int32_t value);
166 typedef bool (*equalSmallBytesUint32Ft)(smallBytest *self, uint32_t value);
167 typedef bool (*equalSmallBytesUint64Ft)(smallBytest *self, uint64_t value);
171 typedef bool (*equalSmallBytesCharFt)(smallBytest *self, const char *value);
173 typedef bool (*equalSmallBytesBaseFt)(smallBytest *self, baset *value);
174 
175 /* *
176  * class functions
177  * allocated once for all objects
178  *
179  * freed with finalizeSmallBytes or finalizeLibsheepy
180  */
181 
192 #define SMALLBYTESFUNCTIONST \
193  helpSmallBytesFt help;\
194  getSmallBytesFt get;\
195  setSmallBytesFt set;\
196  pushSmallBytesFt push;\
197  pushBufferSmallBytesFt pushBuffer;\
198  getAtSmallBytesFt getAt;\
199  /*setAt*/\
200  lenSmallBytesFt len;\
201  isEmptySmallBytesFt isEmpty;\
202  readFileSmallBytesFt readFile;\
203  readFileSmallJsonSmallBytesFt readFileSmallJson;\
204  readFileSmallStringSmallBytesFt readFileSmallString;\
205  readStreamSmallBytesFt readStream;\
206  writeFileSmallBytesFt writeFile;\
207  writeFileSmallJsonSmallBytesFt writeFileSmallJson;\
208  writeFileSmallStringSmallBytesFt writeFileSmallString;\
209  writeStreamSmallBytesFt writeStream;\
210  appendFileSmallBytesFt appendFile;\
211  appendFileSmallStringSmallBytesFt appendFileSmallString;\
212  equalSmallBytesFt equal;\
213  equalSmallBytesBoolFt equalBool;\
214  equalSmallBytesDoubleFt equalDouble;\
215  equalSmallBytesInt64Ft equalInt64;\
216  equalSmallBytesInt32Ft equalInt32;\
217  equalSmallBytesUint32Ft equalUint32;\
218  equalSmallBytesUint64Ft equalUint64;\
219  equalSmallBytesSmallBoolFt equalSmallBool;\
220  equalSmallBytesSmallDoubleFt equalSmallDouble;\
221  equalSmallBytesSmallIntFt equalSmallInt;\
222  equalSmallBytesCharFt equalS;\
223  equalSmallBytesSmallStringFt equalSmallString;\
224  equalSmallBytesBaseFt equalBase
225 
226  typedef struct {
235 
239 struct smallBytes {
240  const char *type;
242 
243  // internal
245 };
246 
247 // smallBytes
248 
249 #define createSmallBytes(obj) ;smallBytest obj; initiateSmallBytes(&obj)
250 #define createAllocateSmallBytes(obj) ;smallBytest *obj; initiateAllocateSmallBytes(&obj)
251 
252 void initiateSmallBytes(smallBytest *self);
254 void finalizeRecycleSmallBytes(void *arg UNUSED);
255 void finalizeSmallBytes(void);
256 
257 // initialize class methods, call registerMethodsSmallBytes from classes inheriting this class
259 
260 smallBytest* allocSmallBytes(void *data, uint32_t size);
261 
262 // terminate smallBytest val when it is out of scope
264 
265 // free smallBytest val declared locally in a code block when it is out of scope
267 
268 // free smallBytest val when it is out of scope
270 
271 // finish smallBytest val when it is out of scope
273 
277 #define cleanSmallBytesP(name) smallBytest *name CLEANUP(cleanUpSmallBytesTerminateG)
278 
282 #define cleanAllocateSmallBytes(obj) ;cleanSmallBytesP(obj); initiateAllocateSmallBytes(&obj)
283 
287 #define cleanSmallBytes(name) smallBytest name CLEANUP(cleanUpSmallBytesFreeLocalG); initiateSmallBytes(&name)
288 
292 #define cleanFreeSmallBytes(name) smallBytest *name CLEANUP(cleanUpSmallBytesFreeG)
293 
297 #define cleanFinishSmallBytesP(name) smallBytest *name CLEANUP(cleanUpSmallBytesFinishG)
298 
300 
301 void freeSmallBytesG (smallBytest *self);
302 
303 smallBytest* setSmallBytesG(smallBytest *self, void *data, uint32_t size);
304 char getAtSmallBytesG(smallBytest *self, char retType UNUSED, int64_t index);
306 size_t lenSmallBytesG(smallBytest *self);
307 bool isEmptySmallBytesG(smallBytest *self);
310 smallBytest* readFileSmallBytesG(smallBytest *self, const char *filePath);
312 int writeFileSmallBytesG(smallBytest *self, const char *filePath);
315 int writeStreamSmallBytesG(smallBytest *self, FILE *fp);
316 int appendFileSmallBytesG(smallBytest *self, const char *filePath);
319 bool equalSmallBytesBoolG(smallBytest *self, bool value);
320 bool equalSmallBytesDoubleG(smallBytest *self, double value);
321 bool equalSmallBytesInt64G(smallBytest *self, int64_t value);
322 bool equalSmallBytesInt32G(smallBytest *self, int32_t value);
323 bool equalSmallBytesUint32G(smallBytest *self, uint32_t value);
324 bool equalSmallBytesUint64G(smallBytest *self, uint64_t value);
328 bool equalSmallBytesCharG(smallBytest *self, const char *value);
331 
332 // end class smallBytes
int writeFileSmallBytesG(smallBytest *self, const char *filePath)
int(* appendFileSmallBytesFt)(smallBytest *self, const char *filePath)
append self to filePath
int(* writeFileSmallStringSmallBytesFt)(smallBytest *self, smallStringt *filePath)
void finalizeSmallBytes(void)
size_t(* lenSmallBytesFt)(smallBytest *self)
return buffer size in bytes
bool(* equalSmallBytesSmallBoolFt)(smallBytest *self, smallBoolt *value)
size_t lenSmallBytesG(smallBytest *self)
void freeSmallBytesG(smallBytest *self)
char getAtSmallBytesG(smallBytest *self, char retType UNUSED, int64_t index)
void cleanUpSmallBytesFreeLocalG(smallBytest *val)
smallBytest * duplicateSmallBytesG(smallBytest *self)
void cleanUpSmallBytesTerminateG(smallBytest **val)
bool equalSmallBytesSmallIntG(smallBytest *self, smallIntt *value)
bool equalSmallBytesG(smallBytest *self, smallBytest *value)
bool(* equalSmallBytesUint32Ft)(smallBytest *self, uint32_t value)
bool equalSmallBytesDoubleG(smallBytest *self, double value)
bool(* equalSmallBytesSmallIntFt)(smallBytest *self, smallIntt *value)
char data[7]
Definition: libsheepy.c:19690
int writeFileSmallJsonSmallBytesG(smallBytest *self, smallJsont *filePath)
bool equalSmallBytesUint64G(smallBytest *self, uint64_t value)
int(* writeFileSmallBytesFt)(smallBytest *self, const char *filePath)
write self to file
small bytes
int writeFileSmallStringSmallBytesG(smallBytest *self, smallStringt *filePath)
bool isEmptySmallBytesG(smallBytest *self)
bool equalSmallBytesCharG(smallBytest *self, const char *value)
bool equalSmallBytesUint32G(smallBytest *self, uint32_t value)
bool(* equalSmallBytesFt)(smallBytest *self, smallBytest *value)
equal compare self to value
int writeStreamSmallBytesG(smallBytest *self, FILE *fp)
bool(* equalSmallBytesUint64Ft)(smallBytest *self, uint64_t value)
smallBytest * readFileSmallStringSmallBytesG(smallBytest *self, smallStringt *filePath)
bool equalSmallBytesInt32G(smallBytest *self, int32_t value)
bool equalSmallBytesInt64G(smallBytest *self, int64_t value)
bool equalSmallBytesBaseG(smallBytest *self, baset *value)
void cleanUpSmallBytesFreeG(smallBytest **val)
void cleanUpSmallBytesFinishG(smallBytest **val)
duplicateSmallBytesFt duplicate
bool equalSmallBytesSmallBoolG(smallBytest *self, smallBoolt *value)
bool(* equalSmallBytesSmallStringFt)(smallBytest *self, smallStringt *value)
END_TEST FILE * fp
bool equalSmallBytesBoolG(smallBytest *self, bool value)
smallBytest * readFileSmallJsonSmallBytesG(smallBytest *self, smallJsont *filePath)
int appendFileSmallStringSmallBytesG(smallBytest *self, smallStringt *filePath)
void initiateSmallBytes(smallBytest *self)
finishSmallBytesFt finish
void initiateAllocateSmallBytes(smallBytest **self)
bool(* equalSmallBytesInt32Ft)(smallBytest *self, int32_t value)
char *(* toStringSmallBytesFt)(smallBytest *self)
smallBytesFunctionst * f
smallBytest * readStreamSmallBytesG(smallBytest *self, FILE *fp)
finishSmallBytesFt smash
void registerMethodsSmallBytes(smallBytesFunctionst *f)
const char * type
smallBytest * pushSmallBytesG(smallBytest *self, char data)
int(* writeFileSmallJsonSmallBytesFt)(smallBytest *self, smallJsont *filePath)
smallBytest *(* duplicateSmallBytesFt)(smallBytest *self)
bool equalSmallBytesSmallDoubleG(smallBytest *self, smallDoublet *value)
toStringSmallBytesFt toString
in value value
bool(* equalSmallBytesDoubleFt)(smallBytest *self, double value)
bool equalSmallBytesSmallStringG(smallBytest *self, smallStringt *value)
bool(* equalSmallBytesCharFt)(smallBytest *self, const char *value)
smallBytest * allocSmallBytes(void *data, uint32_t size)
bool(* isEmptySmallBytesFt)(smallBytest *self)
int appendFileSmallBytesG(smallBytest *self, const char *filePath)
terminateSmallBytesFt terminate
smallBytest * setSmallBytesG(smallBytest *self, void *data, uint32_t size)
char(* getAtSmallBytesFt)(smallBytest *self, int64_t index)
get char at index
void(* freeSmallBytesFt)(smallBytest *self)
smallBytest * readFileSmallBytesG(smallBytest *self, const char *filePath)
#define UNUSED
Definition: libsheepy.h:8195
bool(* equalSmallBytesSmallDoubleFt)(smallBytest *self, smallDoublet *value)
bool(* equalSmallBytesBoolFt)(smallBytest *self, bool value)
base class
int(* appendFileSmallStringSmallBytesFt)(smallBytest *self, smallStringt *filePath)
void(* terminateSmallBytesFt)(smallBytest **self)
bool(* equalSmallBytesBaseFt)(smallBytest *self, baset *value)
void finalizeRecycleSmallBytes(void *arg UNUSED)
bool(* equalSmallBytesInt64Ft)(smallBytest *self, int64_t value)
void(* finishSmallBytesFt)(smallBytest **self)
free container
int(* writeStreamSmallBytesFt)(smallBytest *self, FILE *fp)