|
libsheepy
|
Functions for the small objects smallt. More...
#include "libsheepySmall.h"#include <inttypes.h>#include <stdint.h>#include <stdlib.h>#include <stdbool.h>#include <string.h>#include <stdio.h>
Go to the source code of this file.
Macros | |
| #define | internal static |
| #define | SDICT_MIN_ELEMENTS 12 |
| #define | SDICT_REALLOC_STEPS 4 |
| #define | SARRAY_MIN_ELEMENTS 4 |
| #define | SARRAY_REALLOC_STEPS 4 |
Functions | |
| bool | isSTypeF (smallt *obj, char sType) |
| is Small Type true if obj has type sType More... | |
| size_t | sSizeTiny (smallt *obj) |
| unused function and wrong result TODO update or remove More... | |
| sBoolt * | allocSBool (bool value) |
| allocate a small bool More... | |
| sContainert * | allocSContainer (void *data) |
| allocate a small container The container holds a pointer to a user buffer More... | |
| sDictt * | allocSDict (void) |
| allocate a small dict More... | |
| sDoublet * | allocSDouble (double value) |
| allocate a small double More... | |
| sIntt * | allocSInt (int64_t value) |
| allocate a small int More... | |
| sStringt * | allocSStringTiny (const char *data) |
| allocate a small string More... | |
| sArrayt * | allocSArray (void) |
| allocate a small array More... | |
| sUndefinedt * | allocSUndefined (void) |
| allocate a small undefined object More... | |
| sBytest * | allocSBytes (void) |
| allocate a small bytes object More... | |
| void | sFree (smallt *obj) |
| free non null objects More... | |
| void | sFreeTiny (smallt *obj) |
| free any type of small object More... | |
| void | sDictFreeElement (sDictElemt *e) |
| free a dictionary element More... | |
| void | sDictFreeElements (sDictt *dict) |
| free dictionary elements More... | |
| void | sDictFreeTiny (sDictt *dict) |
| free dictionary elements and dictionary object More... | |
| void | sArrayFreeElements (sArrayt *array) |
| free array elements More... | |
| void | sArrayFreeTiny (sArrayt *array) |
| free array elements and array object More... | |
| smallt * | sDuplicate (smallt *o) |
| duplicate small object More... | |
| smallt * | sDuplicateTiny (smallt *obj) |
| duplicate small object More... | |
| sDictt * | sDictDuplicateTiny (sDictt *dict) |
| duplicate dictionary More... | |
| sArrayt * | sArrayDuplicateTiny (sArrayt *array) |
| duplicate array More... | |
| char * | sToStringTiny (smallt *obj) |
| stringify a small object More... | |
| char * | sToString (smallt *obj) |
| stringify object More... | |
| char * | sBoolToStringTiny (sBoolt *obj) |
| stringify bool More... | |
| char * | sContainerToStringTiny (sContainert *obj UNUSED) |
| stringify container More... | |
| char * | sDictToStringTiny (sDictt *obj) |
| stringify dictionary More... | |
| char * | sDoubleToStringTiny (sDoublet *obj) |
| stringify double More... | |
| char * | sIntToStringTiny (sIntt *obj) |
| stringify int More... | |
| char * | sStringToStringTiny (sStringt *obj) |
| stringify string More... | |
| char * | sArrayToStringTiny (sArrayt *obj) |
| stringify array More... | |
| char * | sUndefinedToStringTiny (sUndefinedt *obj UNUSED) |
| stringify undefined More... | |
| char * | sBytesToStringTiny (sBytest *obj) |
| stringify small bytes More... | |
| char * | sEscapeTiny (smallt *obj) |
| stringify a small object More... | |
| char * | sEscape (smallt *obj) |
| stringify object More... | |
| char * | sDictEscapeTiny (sDictt *obj) |
| stringify dictionary More... | |
| char * | sStringEscapeTiny (sStringt *obj) |
| stringify string More... | |
| char * | sArrayEscapeTiny (sArrayt *obj) |
| stringify array More... | |
| char * | sTypesTiny (smallt *obj) |
| get list of object types string More... | |
| sBytest * | sTypesToBytesTiny (smallt *obj) |
| collect the types in an array or dictionary More... | |
| const char ** | sDictTypeStrings (sDictt *obj) |
| list first level of dictionary types in a list of strings More... | |
| const char ** | sTypesToStrings (sBytest *types) |
| convert a list of object types to a list of strings More... | |
| sBytest * | sDictTypes (sDictt *obj) |
| list first level of object types in dictionary More... | |
| sBytest * | sDictTypesTiny (sDictt *obj) |
| list first level of object types in dictionary More... | |
| const char ** | sArrayTypeStrings (sArrayt *obj) |
| list first level of array types in a list of strings More... | |
| sBytest * | sArrayTypes (sArrayt *obj) |
| list first level of object types in array More... | |
| sBytest * | sArrayTypesTiny (sArrayt *obj) |
| list first level of object types in array More... | |
| smallt * | sDictGet (sDictt *dict, const char *key) |
| get object stored at key More... | |
| smallt ** | sDictGetP (sDictt *dict, const char *key) |
| get pointer to object at key More... | |
| smallt * | sDictGetTiny (sDictt *dict, const char *key) |
| get object stored at key More... | |
| void | sDictSetP (sDictt **dict, const char *key, smallt *data) |
| dictionary set pointer More... | |
| void | sDictSetTiny (sDictt **dict, const char *key, smallt *data) |
| dictionary set key, value More... | |
| void | sDictPushTiny (sDictt **dict, const char *key, smallt *data) |
| push new key-value More... | |
| void | sDictDelTiny (sDictt *dict, const char *key) |
| delete dictionary element More... | |
| char * | sStringGetTiny (sStringt *string) |
| get string in a small string object More... | |
| void | sStringSetTiny (sStringt **string, const char *news) |
| set string in small string More... | |
| void | sArrayPushTiny (sArrayt **array, smallt *data) |
| push data to array More... | |
| void | sArrayPrependTiny (sArrayt **array, smallt *data) |
| prepend data in array More... | |
| smallt * | sArrayPopTiny (sArrayt *array) |
| pop object from array More... | |
| smallt * | sArrayDequeueTiny (sArrayt *array) |
| dequeue object from array More... | |
| smallt ** | sArrayGetP (sArrayt *array, uint32_t index) |
| get pointer to object at index More... | |
| smallt * | sArrayGetTiny (sArrayt *array, uint32_t index) |
| get object at index More... | |
| void | sArraySetShortTiny (sArrayt *array, uint32_t index, smallt *value) |
| set value at index More... | |
| void | sArraySetP (sArrayt *array, uint32_t index, smallt *value) |
| set value at index More... | |
| void | sArraySetTiny (sArrayt *array, uint32_t index, smallt *value) |
| set value at index More... | |
| int | sArrayReverseTiny (sArrayt *array) |
| reverse element order More... | |
| void | sArrayDelTiny (sArrayt *array, uint32_t index) |
| delete element at index More... | |
| void | sArrayDelRangeTiny (sArrayt *array, uint32_t start, uint32_t end) |
| delete range and shift elements More... | |
| void * | sBytesGet (sBytest *bytes) |
| get buffer in small bytes More... | |
| void * | sBytesGetTiny (sBytest *bytes) |
| get buffer in small bytes More... | |
| void | sBytesPush (sBytest **bytes, char data) |
| push char to bytes More... | |
| void | sBytesPushBuffer (sBytest **bytes, void *data, uint32_t size) |
| push data buffer to bytes More... | |
| void | sBytesPushBufferTiny (sBytest **bytes, void *data, uint32_t size) |
| push data buffer to bytes More... | |
| sBytest * | sSerial (smallt *obj) |
| serialize object to small bytes More... | |
| sBytest * | sSerialTiny (smallt *obj) |
| serialize object to small bytes More... | |
| void | sDictSerialElementsTiny (sBytest **r, sDictt *dict) |
| serialize dictionary More... | |
| void | sArraySerialElementsTiny (sBytest **r, sArrayt *array) |
| serialize array More... | |
| smallt * | sDeserial (sBytest *obj) |
| deserialize small bytes object More... | |
| smallt * | sDeserialTiny (sBytest *obj) |
| deserialize small bytes object More... | |
| void | sDictDeserialElementsTiny (sDictt **dict, char **data) |
| deserialize dictionary from data More... | |
| void | sArrayDeserialElementsTiny (sArrayt **array, char **data) |
| deserialize array from data More... | |
Functions for the small objects smallt.
The small objects are used internally in the small baset objects: smallBoolt, smallContainert...
The functions here implement basic functionnality.
The *Tiny functions dont sanitize the parameters. The *Short functions dont create objects and do the minimum possible and have no checks.
Adjust SDICT_MIN_ELEMENTS, SDICT_REALLOC_STEPS, SARRAY_MIN_ELEMENTS and SARRAY_REALLOC_STEPS to balance speed and memory usage.
Definition in file libsheepySmall.c.
| #define internal static |
Definition at line 26 of file libsheepySmall.c.
| #define SDICT_MIN_ELEMENTS 12 |
Definition at line 131 of file libsheepySmall.c.
| #define SDICT_REALLOC_STEPS 4 |
Definition at line 132 of file libsheepySmall.c.
| #define SARRAY_MIN_ELEMENTS 4 |
Definition at line 134 of file libsheepySmall.c.
| #define SARRAY_REALLOC_STEPS 4 |
Definition at line 135 of file libsheepySmall.c.
| bool isSTypeF | ( | smallt * | obj, |
| char | sType | ||
| ) |
is Small Type true if obj has type sType
| obj | small object to check |
Definition at line 146 of file libsheepySmall.c.
| size_t sSizeTiny | ( | smallt * | obj | ) |
unused function and wrong result TODO update or remove
Definition at line 158 of file libsheepySmall.c.
| sBoolt * allocSBool | ( | bool | value | ) |
allocate a small bool
| value | initialize object with value |
Definition at line 221 of file libsheepySmall.c.

| sContainert * allocSContainer | ( | void * | data | ) |
allocate a small container The container holds a pointer to a user buffer
| data | initialize object with data pointer |
Definition at line 239 of file libsheepySmall.c.

| sDictt * allocSDict | ( | void | ) |
allocate a small dict
Definition at line 256 of file libsheepySmall.c.

| sDoublet * allocSDouble | ( | double | value | ) |
allocate a small double
| value | initialize object with value |
Definition at line 274 of file libsheepySmall.c.

| sIntt * allocSInt | ( | int64_t | value | ) |
allocate a small int
| value | initialize object with value |
Definition at line 291 of file libsheepySmall.c.

| sStringt * allocSStringTiny | ( | const char * | data | ) |
allocate a small string
| value | initialize object with value |
Definition at line 308 of file libsheepySmall.c.

| sArrayt * allocSArray | ( | void | ) |
allocate a small array
Definition at line 329 of file libsheepySmall.c.

| sUndefinedt * allocSUndefined | ( | void | ) |
allocate a small undefined object
Definition at line 345 of file libsheepySmall.c.

| sBytest * allocSBytes | ( | void | ) |
allocate a small bytes object
Definition at line 359 of file libsheepySmall.c.

| void sFree | ( | smallt * | obj | ) |
free non null objects
Definition at line 371 of file libsheepySmall.c.


| void sFreeTiny | ( | smallt * | obj | ) |
free any type of small object
objects that are not of type sDict or sArray are freed with the standard free
| obj | object to free |
Definition at line 386 of file libsheepySmall.c.


| void sDictFreeElement | ( | sDictElemt * | e | ) |
free a dictionary element
the key and the object are freed
| e | element to free |
Definition at line 417 of file libsheepySmall.c.


| void sDictFreeElements | ( | sDictt * | dict | ) |
free dictionary elements
| dict | dictionary to free |
Definition at line 432 of file libsheepySmall.c.


| void sDictFreeTiny | ( | sDictt * | dict | ) |
free dictionary elements and dictionary object
| dict | dictionary to free |
Definition at line 445 of file libsheepySmall.c.


| void sArrayFreeElements | ( | sArrayt * | array | ) |
free array elements
| array | array to free |
Definition at line 457 of file libsheepySmall.c.


| void sArrayFreeTiny | ( | sArrayt * | array | ) |
free array elements and array object
| array | array to free |
Definition at line 470 of file libsheepySmall.c.


duplicate small object
| o | small object |
Definition at line 485 of file libsheepySmall.c.


duplicate small object
for containers, the pointer is copied to new object
| obj | small object |
Definition at line 504 of file libsheepySmall.c.


duplicate dictionary
| dict | dictionary to duplicate |
Definition at line 559 of file libsheepySmall.c.


duplicate array
| array | array to duplicate |
Definition at line 583 of file libsheepySmall.c.


| char * sToStringTiny | ( | smallt * | obj | ) |
stringify a small object
the returned string has to be freed
| obj | object |
Definition at line 606 of file libsheepySmall.c.


| char * sToString | ( | smallt * | obj | ) |
stringify object
the returned string has to be freed
| obj | object |
Definition at line 654 of file libsheepySmall.c.


| char * sBoolToStringTiny | ( | sBoolt * | obj | ) |
stringify bool
the returned string has to be freed
| obj | object |
Definition at line 672 of file libsheepySmall.c.

| char * sContainerToStringTiny | ( | sContainert *obj | UNUSED | ) |
stringify container
Definition at line 688 of file libsheepySmall.c.

| char * sDictToStringTiny | ( | sDictt * | obj | ) |
stringify dictionary
the returned string has to be freed
| obj | object |
Definition at line 703 of file libsheepySmall.c.


| char * sDoubleToStringTiny | ( | sDoublet * | obj | ) |
stringify double
the returned string has to be freed
| obj | object |
Definition at line 757 of file libsheepySmall.c.

| char * sIntToStringTiny | ( | sIntt * | obj | ) |
stringify int
the returned string has to be freed
| obj | object |
Definition at line 776 of file libsheepySmall.c.

| char * sStringToStringTiny | ( | sStringt * | obj | ) |
stringify string
the returned string has to be freed
| obj | object |
Definition at line 795 of file libsheepySmall.c.


| char * sArrayToStringTiny | ( | sArrayt * | obj | ) |
stringify array
the returned string has to be freed
| obj | object |
Definition at line 810 of file libsheepySmall.c.


| char * sUndefinedToStringTiny | ( | sUndefinedt *obj | UNUSED | ) |
stringify undefined
the returned string has to be freed
| obj | object |
Definition at line 862 of file libsheepySmall.c.

| char * sBytesToStringTiny | ( | sBytest * | obj | ) |
stringify small bytes
the returned string has to be freed
| obj | object |
Definition at line 877 of file libsheepySmall.c.


| char * sEscapeTiny | ( | smallt * | obj | ) |
stringify a small object
Escape characters to produce a parsable json
the returned string has to be freed
| obj | object |
Definition at line 901 of file libsheepySmall.c.


| char * sEscape | ( | smallt * | obj | ) |
stringify object
the returned string has to be freed
| obj | object |
Definition at line 949 of file libsheepySmall.c.


| char * sDictEscapeTiny | ( | sDictt * | obj | ) |
stringify dictionary
the returned string has to be freed
| obj | object |
Definition at line 967 of file libsheepySmall.c.


| char * sStringEscapeTiny | ( | sStringt * | obj | ) |
stringify string
the returned string has to be freed
| obj | object |
Definition at line 1029 of file libsheepySmall.c.


| char * sArrayEscapeTiny | ( | sArrayt * | obj | ) |
stringify array
the returned string has to be freed
| obj | object |
Definition at line 1044 of file libsheepySmall.c.


| char * sTypesTiny | ( | smallt * | obj | ) |
get list of object types string
only the types in the first level are listed
| obj | small array or dictionary |
Definition at line 1104 of file libsheepySmall.c.

collect the types in an array or dictionary
| obj | array or dictionary |
Definition at line 1145 of file libsheepySmall.c.


| const char ** sDictTypeStrings | ( | sDictt * | obj | ) |
list first level of dictionary types in a list of strings
free the return value because the strings are const - dont use listFreeS
| obj | dictionary |
Definition at line 1170 of file libsheepySmall.c.

| const char ** sTypesToStrings | ( | sBytest * | types | ) |
convert a list of object types to a list of strings
| types | object types in a sBytes object, this parameter is freed at the end of the function, except when there is an error |
Definition at line 1186 of file libsheepySmall.c.


list first level of object types in dictionary
| obj | dictionary |
Definition at line 1218 of file libsheepySmall.c.


list first level of object types in dictionary
| obj | dictionary |
Definition at line 1235 of file libsheepySmall.c.


| const char ** sArrayTypeStrings | ( | sArrayt * | obj | ) |
list first level of array types in a list of strings
free the return because the strings are const - dont use listFreeS
| obj | array |
Definition at line 1257 of file libsheepySmall.c.


list first level of object types in array
| obj | array |
Definition at line 1273 of file libsheepySmall.c.


list first level of object types in array
| obj | array |
Definition at line 1290 of file libsheepySmall.c.


get object stored at key
| dict | dictionary key key to search in dictionary |
Definition at line 1312 of file libsheepySmall.c.


get pointer to object at key
| dict | dictionary |
| key | key to search in dictionary |
Definition at line 1332 of file libsheepySmall.c.

get object stored at key
| dict | dictionary key key to search in dictionary |
Definition at line 1357 of file libsheepySmall.c.

dictionary set pointer
when the key already exists, the associated object is not freed. This is useful for updating arrays, dictionaries and strings in the dictionary
when dict is NULL, a new dictionary is allocated
when the key doesn't exist, a new element is created
when data is NULL, the element is not set
| dict | dictionary key key associated with data data object to store |
Definition at line 1386 of file libsheepySmall.c.

dictionary set key, value
when the key already exists, the associated object is freed. The new data replaces the previous data
when dict is NULL, a new dictionary is allocated
when the key doesn't exist, a new element is created
when data is NULL, the element is not set
| dict | dictionary key key associated with data data object to store |
Definition at line 1426 of file libsheepySmall.c.


push new key-value
when data is NULL, the element is not created
this function doesnt check if key already exists
when dict is NULL, a new dictionary is allocated
the dictionary is reallocated when count is greater than maxCount
| dict | dictionary key key associated with data data object to store |
Definition at line 1468 of file libsheepySmall.c.


| void sDictDelTiny | ( | sDictt * | dict, |
| const char * | key | ||
| ) |
delete dictionary element
| dict | dictionary key key to search |
Definition at line 1518 of file libsheepySmall.c.


| char * sStringGetTiny | ( | sStringt * | string | ) |
get string in a small string object
| string | small string object |
Definition at line 1538 of file libsheepySmall.c.

| void sStringSetTiny | ( | sStringt ** | string, |
| const char * | news | ||
| ) |
set string in small string
| string | small string news new string |
Definition at line 1550 of file libsheepySmall.c.


push data to array
when array is NULL, a new array is allocated
the array is reallocated when count is greater than maxCount
| array | data data to store |
Definition at line 1569 of file libsheepySmall.c.


prepend data in array
when array is NULL, a new array is allocated
the array is reallocated when count is greater than maxCount
| array | data data to store |
Definition at line 1617 of file libsheepySmall.c.


pop object from array
Definition at line 1660 of file libsheepySmall.c.


dequeue object from array
Definition at line 1674 of file libsheepySmall.c.

get pointer to object at index
| array | index in array |
Definition at line 1699 of file libsheepySmall.c.
get object at index
| array | index in array |
Definition at line 1713 of file libsheepySmall.c.

set value at index
the previous element is not freed. This is useful for updating arrays, dictionaries and strings in the array
| array | index where the value is set value to store |
Definition at line 1729 of file libsheepySmall.c.

set value at index
the previous element is not freed. This is useful for updating arrays, dictionaries and strings in the array
| array | index where the value is set value to store |
Definition at line 1745 of file libsheepySmall.c.

set value at index
the previous element is freed. The new data replaces the previous data
| array | index where the value is set value to store |
Definition at line 1761 of file libsheepySmall.c.


| int sArrayReverseTiny | ( | sArrayt * | array | ) |
reverse element order
the last element becomes the first one
| array | to reverse |
Definition at line 1782 of file libsheepySmall.c.

| void sArrayDelTiny | ( | sArrayt * | array, |
| uint32_t | index | ||
| ) |
delete element at index
the element is freed and NULL is set at index count is unchanged
| array | index |
Definition at line 1806 of file libsheepySmall.c.


| void sArrayDelRangeTiny | ( | sArrayt * | array, |
| uint32_t | start, | ||
| uint32_t | end | ||
| ) |
delete range and shift elements
the elements are freed and count is reduced
the range [start, end] is not checked for validity
| array | |
| start | |
| end |
Definition at line 1826 of file libsheepySmall.c.


| void * sBytesGet | ( | sBytest * | bytes | ) |
get buffer in small bytes
| bytes | small bytes |
Definition at line 1852 of file libsheepySmall.c.


| void * sBytesGetTiny | ( | sBytest * | bytes | ) |
get buffer in small bytes
| bytes | small bytes |
Definition at line 1869 of file libsheepySmall.c.

| void sBytesPush | ( | sBytest ** | bytes, |
| char | data | ||
| ) |
push char to bytes
when bytes is NULL, a new small bytes object is allocated
the small bytes object is reallocated
| bytes | small bytes data char to push |
Definition at line 1885 of file libsheepySmall.c.


| void sBytesPushBuffer | ( | sBytest ** | bytes, |
| void * | data, | ||
| uint32_t | size | ||
| ) |
push data buffer to bytes
when bytes is NULL, a new small bytes object is allocated
the small bytes object is reallocated
when data is NULL, the function does nothing
| bytes | small bytes data buffer to push size size of buffer |
Definition at line 1925 of file libsheepySmall.c.


| void sBytesPushBufferTiny | ( | sBytest ** | bytes, |
| void * | data, | ||
| uint32_t | size | ||
| ) |
push data buffer to bytes
the small bytes object is reallocated
| bytes | small bytes data buffer to push size size of buffer |
Definition at line 1950 of file libsheepySmall.c.

serialize object to small bytes
| obj | object |
Definition at line 1986 of file libsheepySmall.c.


serialize object to small bytes
All elements are serialized recursively
the data in containers is not serialized
| obj | object |
Definition at line 2009 of file libsheepySmall.c.


serialize dictionary
the serialized dict is pushed to r. All elements are serialized recursively
the data in containers is not serialized
| r | small bytes object dict dictionary to serialize |
Definition at line 2066 of file libsheepySmall.c.


serialize array
the serialized array is pushed to r. All elements are serialized recursively
the data in containers is not serialized
| r | small bytes object array to serialize |
Definition at line 2131 of file libsheepySmall.c.


deserialize small bytes object
| obj | small bytes |
Definition at line 2196 of file libsheepySmall.c.


deserialize small bytes object
| obj | small bytes |
Definition at line 2215 of file libsheepySmall.c.


| void sDictDeserialElementsTiny | ( | sDictt ** | dict, |
| char ** | data | ||
| ) |
deserialize dictionary from data
a new dictionary is allocated
| dict | dictionary holding the elements data serialized dictionary |
Definition at line 2283 of file libsheepySmall.c.


| void sArrayDeserialElementsTiny | ( | sArrayt ** | array, |
| char ** | data | ||
| ) |
deserialize array from data
a new array is allocated
| array | holding the elements data serialized dictionary |
Definition at line 2384 of file libsheepySmall.c.


1.8.13