23 #include "../libsheepyObject.h" 27 #define internal static 117 self->type =
"smallBytes";
125 self->f = smallBytesF;
173 #if (recycleContainers) 190 #if (recycleContainers) 212 r->
f->pushBuffer(r, data, size);
251 #if (NFreeStackCheck) 254 register u64 rsp
asm(
"rsp");
255 if ((
u64)*
self > rsp) {
256 logW(
"Probably trying to free a smallBytes on stack: "BLD PRIx64
RST" sp: "BLD PRIx64
RST, *
self, rsp);
260 #if (recycleContainers) 274 #if (recycleContainers) 295 return(strdup(
"[]"));
341 if (index >= self->B->count) {
344 if (index < -(int64_t)self->B->count) {
348 index = (int64_t)self->B->count + index;
351 return((&(self->B->data))[index]);
360 return(self->B->count);
374 if (!filePath ||
isBlankS(filePath)) {
386 void *buffer = malloc((
size_t)len);
391 f = fopen(filePath,
"r");
392 readStatus = fread(buffer, 1, (
size_t)len , f);
401 if (readStatus != (
size_t)len) {
403 shEPrintfS(
"The path was: \"%s\"\n", filePath);
422 if (!
eqS(type,
"string")) {
459 void *buffer = malloc((
size_t)len);
464 readStatus = fread(buffer, 1, (
size_t)len , fp);
472 if (readStatus != (
size_t)len) {
486 if (!filePath ||
isBlankS(filePath) || !self->B) {
490 len =
self->B->count;
492 f = fopen(filePath,
"w");
495 shEPrintfS(
"The path was: \"%s\"\n", filePath);
498 writeStatus = fwrite(
sBytesGet(self->B), 1, len , f);
501 if (writeStatus != len) {
503 shEPrintfS(
"The path was: \"%s\"\n", filePath);
522 if (!
eqS(type,
"string")) {
547 if (!fp || !self->B) {
551 len =
self->B->count;
553 writeStatus = fwrite(
sBytesGet(self->B), 1, len , fp);
555 if (writeStatus != len) {
569 if (!filePath ||
isBlankS(filePath) || !self->B) {
573 len =
self->B->count;
575 f = fopen(filePath,
"a");
578 shEPrintfS(
"The path was: \"%s\"\n", filePath);
581 writeStatus = fwrite(
sBytesGet(self->B), 1, len , f);
584 if (writeStatus != len) {
586 shEPrintfS(
"The path was: \"%s\"\n", filePath);
603 if (!self->B || !value || !value->
B) {
607 if (self->B->count != value->
B->
count) {
655 return(val == value);;
684 return(val == value);;
713 return(val == value);;
740 uint32_t val = (uint32_t)
parseInt(s);
742 return(val == value);;
769 uint64_t val = (uint64_t)
parseInt(s);
771 return(val == value);;
776 if (!self->B || !value || !value->
value) {
785 if (!self->B || !value || !value->
value) {
794 if (!self->B || !value || !value->
value) {
804 if (!self->B || !value) {
808 size_t size = strlen(value) + 1;
809 if (self->B->count != size) {
813 return(memcmp(
sBytesGet(self->B), value, size) == 0);;
818 if (!self->B || !value || !value->
data) {
822 if (self->B->count != (value->
_len + 1)) {
831 if (!self->B || !value) {
848 return(self->f->duplicate(
self));
855 return(self->f->set(
self, data, size));
860 return(self->f->getAt(
self,index));
865 return(self->f->push(
self, data));
870 return(self->f->len(
self));
875 return(self->f->isEmpty(
self));
880 return(self->f->readFile(
self, filePath));
885 return(self->f->readFileSmallJson(
self,filePath));
890 return(self->f->readFileSmallString(
self,filePath));
895 return(self->f->readStream(
self, fp));
901 return(self->f->writeFile(
self, filePath));
906 return(self->f->writeFileSmallJson(
self, filePath));
911 return(self->f->writeFileSmallString(
self, filePath));
916 return(self->f->writeStream(
self, fp));
921 return(self->f->appendFile(
self, filePath));
926 return(self->f->appendFileSmallString(
self, filePath));
931 return(self->f->equal(
self, value));
936 return(self->f->equalBool(
self, value));
941 return(self->f->equalDouble(
self, value));
946 return(self->f->equalInt64(
self, value));
951 return(self->f->equalInt32(
self, value));
956 return(self->f->equalUint32(
self, value));
961 return(self->f->equalUint64(
self, value));
966 return(self->f->equalSmallBool(
self, value));
971 return(self->f->equalSmallDouble(
self, value));
976 return(self->f->equalSmallInt(
self, value));
981 return(self->f->equalS(
self, value));
986 return(self->f->equalSmallString(
self, value));
991 return(self->f->equalBase(
self, value));
smallBytest * setSmallBytesG(smallBytest *self, void *data, uint32_t size)
void finalizeSmallBytes(void)
internal bool equalSmallBytesChar(smallBytest *self, const char *value)
bool eqS(const char *string1, const char *string2)
string Equal compare string1 to string2
internal char * toStringSmallBytes(smallBytest *self)
bool isBlankS(const char *string)
is Blank String
bool equalSmallBytesG(smallBytest *self, smallBytest *value)
char * sToString(smallt *obj)
stringify object
bool equalSmallBytesBoolG(smallBytest *self, bool value)
bool isEmptySmallBytesG(smallBytest *self)
#define ssGet(obj)
get a pointer to the string in the smallString object
void cleanUpSmallBytesTerminateG(smallBytest **val)
internal smallBytest * pushBufferSmallBytes(smallBytest *self, void *data, uint32_t size)
#define rangeDown(index, maxCount)
range down loop, index is ssize_t
internal void finishSmallBytes(smallBytest **self)
int writeFileSmallJsonSmallBytesG(smallBytest *self, smallJsont *filePath)
#define RST
reset for color function
int appendFileSmallBytesG(smallBytest *self, const char *filePath)
bool equalSmallBytesDoubleG(smallBytest *self, double value)
internal bool equalSmallBytesInt64(smallBytest *self, int64_t value)
internal size_t lenSmallBytes(smallBytest *self)
void sBytesPush(sBytest **bytes, char data)
push char to bytes
createAllocateSmallBytes(obj2)
smallBytest * duplicateSmallBytesG(smallBytest *self)
ssize_t fileSizeFP(FILE *fp)
get file size from file pointer
#define pFuncError
print function name and system error
smallBytest * readFileSmallStringSmallBytesG(smallBytest *self, smallStringt *filePath)
base class for the small objects all small objects have a type
#define isError(assigned, left)
is Assigment Error catch error when assigned is false, 0 or NULL after being assigned with left ...
internal smallBytest * readFileSmallStringSmallBytes(smallBytest *self, smallStringt *filePath)
bool equalSmallBytesCharG(smallBytest *self, const char *value)
void cleanUpSmallBytesFreeLocalG(smallBytest *val)
internal bool equalSmallBytesSmallInt(smallBytest *self, smallIntt *value)
bool equalSmallBytesInt32G(smallBytest *self, int32_t value)
internal smallBytest * pushSmallBytes(smallBytest *self, char data)
char * sStringGetTiny(sStringt *string)
get string in a small string object
void cleanUpSmallBytesFreeG(smallBytest **val)
#define getTopTypeO(self)
int writeFileSmallStringSmallBytesG(smallBytest *self, smallStringt *filePath)
#define isOSmallJson(obj)
test if obj type is smallJson
void finalizeRecycleSmallBytes(void *arg UNUSED)
internal const char * helpSmallBytes(smallBytest UNUSED *self)
#define terminateO(obj)
free buffers and obj itself
internal smallBytest * readFileSmallBytes(smallBytest *self, const char *filePath)
#define isOSmallBytes(obj)
test if obj type is smallBytes
void registerMethodsSmallBytes(smallBytesFunctionst *f)
bool equalSmallBytesBaseG(smallBytest *self, baset *value)
internal bool isEmptySmallBytes(smallBytest *self)
smallBytest * readStreamSmallBytesG(smallBytest *self, FILE *fp)
bool equalSmallBytesSmallBoolG(smallBytest *self, smallBoolt *value)
internal char getAtSmallBytes(smallBytest *self, int64_t index)
internal bool equalSmallBytesSmallBool(smallBytest *self, smallBoolt *value)
duplicateSmallBytesFt duplicate
internal bool equalSmallBytesSmallString(smallBytest *self, smallStringt *value)
internal bool equalSmallBytesInt32(smallBytest *self, int32_t value)
internal int writeStreamSmallBytes(smallBytest *self, FILE *fp)
size_t lenSmallBytesG(smallBytest *self)
bool isNumber(const char *string)
is Number (integer or float) String
finishSmallBytesFt finish
internal int writeFileSmallBytes(smallBytest *self, const char *filePath)
void sBytesPushBuffer(sBytest **bytes, void *data, uint32_t size)
push data buffer to bytes
internal smallBytest * readStreamSmallBytes(smallBytest *self, FILE *fp)
internal smallBytest * setSmallBytes(smallBytest *self, void *data, uint32_t size)
smallBytest * pushSmallBytesG(smallBytest *self, char data)
internal void freeSmallBytes(smallBytest *self)
internal int appendFileSmallStringSmallBytes(smallBytest *self, smallStringt *filePath)
internal void terminateSmallBytes(smallBytest **self)
bool equalSmallBytesSmallIntG(smallBytest *self, smallIntt *value)
internal bool equalSmallBytesDouble(smallBytest *self, double value)
#define helpTextSmallBytes
help text for this class It is public declaration so that child classes can add their help text easil...
int writeStreamSmallBytesG(smallBytest *self, FILE *fp)
bool isInt(const char *string)
is Integer String
internal bool equalSmallBytesUint32(smallBytest *self, uint32_t value)
internal smallBytest * duplicateSmallBytes(smallBytest *self)
void * sBytesGet(sBytest *bytes)
get buffer in small bytes
double parseDouble(const char *string)
convert string to double
bool equalSmallBytesSmallDoubleG(smallBytest *self, smallDoublet *value)
smallBytest * allocSmallBytes(void *data, uint32_t size)
#define BLD
bold for color function
smallBytest * readFileSmallJsonSmallBytesG(smallBytest *self, smallJsont *filePath)
internal void * getSmallBytes(smallBytest *self)
toStringSmallBytesFt toString
void cleanUpSmallBytesFinishG(smallBytest **val)
internal bool equalSmallBytes(smallBytest *self, smallBytest *value)
internal bool equalSmallBytesUint64(smallBytest *self, uint64_t value)
int appendFileSmallStringSmallBytesG(smallBytest *self, smallStringt *filePath)
void initiateSmallBytes(smallBytest *self)
terminateSmallBytesFt terminate
void initiateAllocateSmallBytes(smallBytest **self)
int writeFileSmallBytesG(smallBytest *self, const char *filePath)
bool equalSmallBytesInt64G(smallBytest *self, int64_t value)
bool equalSmallBytesUint64G(smallBytest *self, uint64_t value)
internal bool equalSmallBytesSmallDouble(smallBytest *self, smallDoublet *value)
void shEPrintfS(const char *fmt,...)
sheepy Error printf String print with logE
#define freeO(obj)
free buffers in obj
internal bool equalSmallBytesBool(smallBytest *self, bool value)
void sFree(smallt *obj)
free non null objects
internal bool equalSmallBytesBase(smallBytest *self, baset *value)
void freeSmallBytesG(smallBytest *self)
int64_t parseInt(const char *string)
convert string to decimal integer
ssize_t fileSize(const char *filePath)
get file size
char getAtSmallBytesG(smallBytest *self, char retType UNUSED, int64_t index)
smallBytest * readFileSmallBytesG(smallBytest *self, const char *filePath)
bool equalSmallBytesUint32G(smallBytest *self, uint32_t value)
internal smallBytest * readFileSmallJsonSmallBytes(smallBytest *self, smallJsont *filePath)
internal int appendFileSmallBytes(smallBytest *self, const char *filePath)
bool equalSmallBytesSmallStringG(smallBytest *self, smallStringt *value)
#define finishO(obj)
free container only
internal int writeFileSmallJsonSmallBytes(smallBytest *self, smallJsont *filePath)
internal int writeFileSmallStringSmallBytes(smallBytest *self, smallStringt *filePath)
smallt * sDuplicate(smallt *o)
duplicate small object
#define isOSmallString(obj)
test if obj type is smallString