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

commit bd18e66127c60e0379a0f5a0d6db5bf85e03a251
parent b1f4c622db4eb643b14aa7f8520fbc27c8160d46
Author: Remy Noulin <loader2x@gmail.com>
Date:   Sat,  7 Sep 2019 11:13:43 +0200

make eqG and icEqG NULL safe, add isLSheepyObject macro to check if a variable is an instance of a libsheepy class

completion.txt            | 13 ++++++++
documentation.md          | 72 ++++++++++++++++++++++++++++++++++++++++++--
release/libsheepyObject.h | 77 ++++++++++++++++++++++++++++++++++++++++++-----
src/libsheepyObject.h     | 77 ++++++++++++++++++++++++++++++++++++++++++-----
4 files changed, 223 insertions(+), 16 deletions(-)

Diffstat:
Mcompletion.txt | 13+++++++++++++
Mdocumentation.md | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Mrelease/libsheepyObject.h | 77++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
Msrc/libsheepyObject.h | 77++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
4 files changed, 223 insertions(+), 16 deletions(-)

diff --git a/completion.txt b/completion.txt @@ -13,6 +13,16 @@ procbegin procend funcbegin funcend +MACRO( STATEMENTS ) +FUNC( STATEMENTS) +is +equals +shr +shl +inc +dec +ptr_to +val_of stringifyExpr(expr) stringifyExpr1(expr) libsheepyErrorMask @@ -1479,8 +1489,11 @@ replaceO(self, olds, news, max) replaceG(self, olds, news, max) icReplaceO(self, olds, news, max) icReplaceG(self, olds, news, max) +isLSheepyObject(self) eqG(self, obj) +eqDirectG(self, obj) icEqG(self, obj) +icEqDirectG(self, obj) eqIG(self, obj, index) startsWithG(self, obj) endsWithG(self, obj) diff --git a/documentation.md b/documentation.md @@ -44,6 +44,16 @@ procbegin procend funcbegin funcend +MACRO( STATEMENTS ) +FUNC( STATEMENTS) +is +equals +shr +shl +inc +dec +ptr_to +val_of stringifyExpr(expr) stringifyExpr1(expr) libsheepyErrorMask @@ -1406,6 +1416,39 @@ extern const bool FALSE; #define funcbegin ({ #define funcend }) /* + * do while(0) alternative macro definition + * + * #define macro(param) MACRO( logVarG(param) ) + */ +#define MACRO( STATEMENTS ) do { STATEMENTS } while(0) +/* + * Macro returning a value (GNU extension): + * #define macro(value) FUNC(\ + * int returnResult = value + 2;\ + * returnResult;\ + * ) + * + */ +#define FUNC( STATEMENTS) ({ STATEMENTS }) +/** additions to iso646 + * int a is 0; + * if (a equals 1 or a equals 2) a shl = 2; + * else a inc; + * return ptr_to a; + * + * int *b is &a; + * val_of b is a; + * val_of b dec; + */ +#define is = +#define equals == +#define shr >> +#define shl << +#define inc ++ +#define dec -- +#define ptr_to & +#define val_of * +/* * stringify Expression - Turn expression into a string literal * * Example: @@ -15099,8 +15142,11 @@ replaceO(self, olds, news, max) replaceG(self, olds, news, max) icReplaceO(self, olds, news, max) icReplaceG(self, olds, news, max) +isLSheepyObject(self) eqG(self, obj) +eqDirectG(self, obj) icEqG(self, obj) +icEqDirectG(self, obj) eqIG(self, obj, index) startsWithG(self, obj) endsWithG(self, obj) @@ -52506,8 +52552,30 @@ smallStringt* duplicateSmallStringG (smallStringt *self); #define replaceG(self, olds, news, max) #define icReplaceO(self, olds, news, max) (self)->f->icReplace(self, olds, news, max) #define icReplaceG(self, olds, news, max) -#define eqG(self, obj) -#define icEqG(self, obj) +/* + * is self a libsheepy object + */ +#define isLSheepyObject(self) +/* + * return true when self value and obj value are equal + * Checks if self is NULL before calling the methods + */ +#define eqG(self, obj) FUNC(\ +/* + * return true when self value and obj value are equal + * Directly calls the methods without NULL check + */ +#define eqDirectG(self, obj) +/* + * ignore case and return true when self value and obj value are equal + * Checks if self is NULL before calling the methods + */ +#define icEqG(self, obj) FUNC(\ +/* + * ignore case and return true when self value and obj value are equal + * Directly calls the methods without NULL check + */ +#define icEqDirectG(self, obj) #define eqIG(self, obj, index) #define startsWithG(self, obj) #define endsWithG(self, obj) diff --git a/release/libsheepyObject.h b/release/libsheepyObject.h @@ -3832,7 +3832,40 @@ void finishManyOF(void *paramType, ...); ) \ )(self, olds, news, max) -#define eqG(self, obj) _Generic((self), \ +/** + * is self a libsheepy object + */ +#define isLSheepyObject(self) _Generic((self), default: 0,\ + baset *: 1,\ + smallArrayt*: 1,\ + smallBoolt*: 1,\ + smallBytest*: 1,\ + smallDictt *: 1,\ + smallDoublet *: 1,\ + smallIntt *: 1,\ + smallJsont *: 1,\ + smallStringt *: 1,\ + smallContainert *: 1,\ + undefinedt *: 1\ + ) + +/** + * return true when self value and obj value are equal + * Checks if self is NULL before calling the methods + */ +#define eqG(self, obj) FUNC(\ + bool UNIQVAR(r);\ + /* if self is NULL and sheepy object, return false */\ + if (isLSheepyObject(self) and !(self)) UNIQVAR(r) = false;\ + else UNIQVAR(r) = eqDirectG(self, obj);\ + /*return*/UNIQVAR(r);\ + ) + +/** + * return true when self value and obj value are equal + * Directly calls the methods without NULL check + */ +#define eqDirectG(self, obj) _Generic((self), \ char: _Generic(obj, \ char *: eqCharS, \ const char *: eqCharS, \ @@ -4184,7 +4217,23 @@ void finishManyOF(void *paramType, ...); default: notEqualOG) \ )(self, obj) -#define icEqG(self, obj) _Generic((self), \ +/** + * ignore case and return true when self value and obj value are equal + * Checks if self is NULL before calling the methods + */ +#define icEqG(self, obj) FUNC(\ + bool UNIQVAR(r);\ + /* if self is NULL and sheepy object, return false */\ + if (isLSheepyObject(self) and !(self)) UNIQVAR(r) = false;\ + else UNIQVAR(r) = icEqDirectG(self, obj);\ + /*return*/UNIQVAR(r);\ + ) + +/** + * ignore case and return true when self value and obj value are equal + * Directly calls the methods without NULL check + */ +#define icEqDirectG(self, obj) _Generic((self), \ char: _Generic(obj, \ char *: icEqCharS, \ const char *: icEqCharS, \ @@ -8677,19 +8726,33 @@ typedef struct smallDict smallDictt; typedef struct smallArray smallArrayt; /** - * smallJson class - */ -typedef struct smallJson smallJsont; - -/** * smallBytes class */ typedef struct smallBytes smallBytest; +/** + * smallBool class + */ typedef struct smallBool smallBoolt; + +/** + * smallContainer class + */ typedef struct smallContainer smallContainert; + +/** + * smallDouble class + */ typedef struct smallDouble smallDoublet; + +/** + * smallInt class + */ typedef struct smallInt smallIntt; + +/** + * smallString class + */ typedef struct smallString smallStringt; #include "json/libsheepyCUndefined.h" diff --git a/src/libsheepyObject.h b/src/libsheepyObject.h @@ -3832,7 +3832,40 @@ void finishManyOF(void *paramType, ...); ) \ )(self, olds, news, max) -#define eqG(self, obj) _Generic((self), \ +/** + * is self a libsheepy object + */ +#define isLSheepyObject(self) _Generic((self), default: 0,\ + baset *: 1,\ + smallArrayt*: 1,\ + smallBoolt*: 1,\ + smallBytest*: 1,\ + smallDictt *: 1,\ + smallDoublet *: 1,\ + smallIntt *: 1,\ + smallJsont *: 1,\ + smallStringt *: 1,\ + smallContainert *: 1,\ + undefinedt *: 1\ + ) + +/** + * return true when self value and obj value are equal + * Checks if self is NULL before calling the methods + */ +#define eqG(self, obj) FUNC(\ + bool UNIQVAR(r);\ + /* if self is NULL and sheepy object, return false */\ + if (isLSheepyObject(self) and !(self)) UNIQVAR(r) = false;\ + else UNIQVAR(r) = eqDirectG(self, obj);\ + /*return*/UNIQVAR(r);\ + ) + +/** + * return true when self value and obj value are equal + * Directly calls the methods without NULL check + */ +#define eqDirectG(self, obj) _Generic((self), \ char: _Generic(obj, \ char *: eqCharS, \ const char *: eqCharS, \ @@ -4184,7 +4217,23 @@ void finishManyOF(void *paramType, ...); default: notEqualOG) \ )(self, obj) -#define icEqG(self, obj) _Generic((self), \ +/** + * ignore case and return true when self value and obj value are equal + * Checks if self is NULL before calling the methods + */ +#define icEqG(self, obj) FUNC(\ + bool UNIQVAR(r);\ + /* if self is NULL and sheepy object, return false */\ + if (isLSheepyObject(self) and !(self)) UNIQVAR(r) = false;\ + else UNIQVAR(r) = icEqDirectG(self, obj);\ + /*return*/UNIQVAR(r);\ + ) + +/** + * ignore case and return true when self value and obj value are equal + * Directly calls the methods without NULL check + */ +#define icEqDirectG(self, obj) _Generic((self), \ char: _Generic(obj, \ char *: icEqCharS, \ const char *: icEqCharS, \ @@ -8677,19 +8726,33 @@ typedef struct smallDict smallDictt; typedef struct smallArray smallArrayt; /** - * smallJson class - */ -typedef struct smallJson smallJsont; - -/** * smallBytes class */ typedef struct smallBytes smallBytest; +/** + * smallBool class + */ typedef struct smallBool smallBoolt; + +/** + * smallContainer class + */ typedef struct smallContainer smallContainert; + +/** + * smallDouble class + */ typedef struct smallDouble smallDoublet; + +/** + * smallInt class + */ typedef struct smallInt smallIntt; + +/** + * smallString class + */ typedef struct smallString smallStringt; #include "json/libsheepyCUndefined.h"