regify utility  2.0.0-0
Container Type Specifications

This section contains specifications for objects in collections. More...

Modules

 64 Bit Integer
 This section contains collection support for 64 Bit Integers such as int64_t.
 
 Long Integer
 This section contains collection support for long Integers such as long.
 
 32 Bit Integer
 This section contains collection support for 32 Bit Integers such as int32_t.
 
 16 Bit Integer
 This section contains collection support for 16 Bit Integers such as int16_t.
 
 8 Bit Integer
 This section contains collection support for 8 Bit Integers such as int8_t.
 
 Boolean
 This section contains collection support for booleans such as bool.
 
 Pointer size Integer
 This section contains collection support for Pointer size Integers such as intptr_t or ru_int.
 
 Strings
 This section contains collection support for single byte strings such as char*.
 

Typedefs

typedef void * ruType
 An opaque type representing a type specification. More...
 
typedef ru_uint(* ruHashFunc) (trans_ptr key)
 Function signature of a hashing function for ruMap or ruSet keys. More...
 
typedef bool(* ruMatchFunc) (trans_ptr testKey, trans_ptr existingKey)
 Function signature of a matching function for ruMap or ruSet keys. More...
 
typedef int32_t(* ruCompFunc) (trans_ptr a, trans_ptr b)
 Signature of a generic comparator function for sorting. More...
 
typedef ptr(* ruCloneFunc) (ptr val)
 Signature of a generic clone function. This is the signature of the in function in ruTypeNew. More...
 
typedef int32_t(* ruPtr2TypeFunc) (ptr src, ptr *dst)
 Signature of a function that stores the value of the first pointer in a certain type by de-referencing the second pointer. This is the signature of the out function in ruTypeNew. More...
 

Functions

RUAPI ruType ruTypePtrFree (void)
 Returns an ruType used for malloced types that use standard free. More...
 
RUAPI ruType ruTypeNew (ruHashFunc hash, ruMatchFunc match, ruCompFunc comp, ruClearFunc free, ruCloneFunc in, ruPtr2TypeFunc out)
 Creates a custom type specification usable as a map key. More...
 
RUAPI ruType ruTypePtr (ruClearFunc free)
 Creates a custom ruTypeIntPtr specification. More...
 
RUAPI ruType ruTypeClone (ruType tp)
 Returns a copy of the given ruType. More...
 
RUAPI ruType ruTypeFree (ruType tp)
 Frees given custom ruType. More...
 

Detailed Description

This section contains specifications for objects in collections.

These are used in ruMap, ruSet and ruList.

Typedef Documentation

◆ ruCloneFunc

typedef ptr(* ruCloneFunc) (ptr val)

Signature of a generic clone function. This is the signature of the in function in ruTypeNew.

Parameters
valaddress where data to clone is stored

◆ ruCompFunc

typedef int32_t(* ruCompFunc) (trans_ptr a, trans_ptr b)

Signature of a generic comparator function for sorting.

◆ ruHashFunc

typedef ru_uint(* ruHashFunc) (trans_ptr key)

Function signature of a hashing function for ruMap or ruSet keys.

◆ ruMatchFunc

typedef bool(* ruMatchFunc) (trans_ptr testKey, trans_ptr existingKey)

Function signature of a matching function for ruMap or ruSet keys.

◆ ruPtr2TypeFunc

typedef int32_t(* ruPtr2TypeFunc) (ptr src, ptr *dst)

Signature of a function that stores the value of the first pointer in a certain type by de-referencing the second pointer. This is the signature of the out function in ruTypeNew.

Parameters
srcWhere the outgoing value is stored, usually in the collection.
dstWhere the value will be copied to and properly type casted.

◆ ruType

typedef void* ruType

An opaque type representing a type specification.

Function Documentation

◆ ruTypeClone()

RUAPI ruType ruTypeClone ( ruType  tp)

Returns a copy of the given ruType.

Parameters
tpruType to copy
Returns
A copy or reference of the given ruType. Needs consuming or freeing only if the original did.

◆ ruTypeFree()

RUAPI ruType ruTypeFree ( ruType  tp)

Frees given custom ruType.

This function need not be called on standard ruType references from ruTypeInt64 or similar, but will handle these gracefully.

Parameters
tpruType from ruTypeNew or ruTypePtr to free
Returns
NULL

◆ ruTypeNew()

RUAPI ruType ruTypeNew ( ruHashFunc  hash,
ruMatchFunc  match,
ruCompFunc  comp,
ruClearFunc  free,
ruCloneFunc  in,
ruPtr2TypeFunc  out 
)

Creates a custom type specification usable as a map key.

Example:

// error checking left out for brevity
perm_chars k1 = "23";
perm_chars k2 = "42";
int64_t v1 = 42, v2 = 23, r = 0;
// this is the same as returned by ruTypeStrRef()
ruType ks = ruTypeNew(ruStrHash, ruStrMatch, ruStrComp, NULL, NULL, NULL);
// this can also be accomplished by ruTypeInt64()
ruType vs = ruTypeNew(NULL, NULL, NULL, NULL, ruInt64, ruRefPtrInt64);
ruMap rm = ruMapNew(ks, vs);
ruMapPut(rm, k1, &v1);
ruMapPut(rm, k2, &v2);
ruMapGet(rm, k1, &r);
printf("k: '%s' v: %ld\n", k1, r);
ruMapGet(rm, k2, &r);
printf("k: '%s' v: %ld\n", k2, r);
RUAPI ruMap ruMapNew(ruType keyType, ruType valueType)
Creates a new ruMap based on the given specifications.
RUAPI ruMap ruMapFree(ruMap rm)
Frees the given map and its members.
#define ruMapGet(rm, key, val)
Runs ruMapGetValue with a ptr cast.
Definition: map.h:134
#define ruMapPut(map, key, val)
Runs ruMapPutData with ptr casts.
Definition: map.h:75
void * ruMap
An opaque type representing a map object.
Definition: map.h:33
const char * perm_chars
A permanent NULL terminated string pointer.
Definition: regify-util.h:176
void * ruType
An opaque type representing a type specification.
Definition: regify-util.h:344
RUAPI ruType ruTypeNew(ruHashFunc hash, ruMatchFunc match, ruCompFunc comp, ruClearFunc free, ruCloneFunc in, ruPtr2TypeFunc out)
Creates a custom type specification usable as a map key.
RUAPI int32_t ruRefPtrInt64(ptr src, ptr *dst)
Copies the 64 bit integer stored in src to dst.
RUAPI ru_Int64 ruInt64(ptr val)
Allocates given 64 bit integer on the heap and returns the pointer.
RUAPI bool ruStrMatch(trans_ptr s1, trans_ptr s2)
Convenience match function for Maps.
RUAPI ru_uint ruStrHash(trans_ptr key)
Returns a hash for given string.
RUAPI int32_t ruStrComp(trans_ptr testVal, trans_ptr existingVal)
String comparator function for the ruType system.
Parameters
hashThe hashing function. Required for ruMap or ruSet keys.
matchThe matching function. Required for ruMap or ruSet keys.
compA comparator function for list sorting functionality.
freeThe free function to be called when the type is removed from a collection.
inThis function is called when storing the given value such as the ruMapPut or ruListAppend functions
outThis function is called in retrieval functions to place the proper type in the recipient pointers.
Returns
New type specification for collections. This is usually freed by the collection that it's given to. Otherwise free with ruTypeFree.

◆ ruTypePtr()

RUAPI ruType ruTypePtr ( ruClearFunc  free)

Creates a custom ruTypeIntPtr specification.

Parameters
freeThe free function to be called when the type is removed from a collection.
Returns
New type specification for collections. This is usually freed by the collection that it's given to. Otherwise free with ruTypeFree.

◆ ruTypePtrFree()

RUAPI ruType ruTypePtrFree ( void  )

Returns an ruType used for malloced types that use standard free.

Returns
Freeable type specification. Caller need not free.