offbrand
A collection of generic, reference counted datastructures in C for C
|
Standard Library Implementation. More...
Functions | |
void | ob_init_base (obj *instance, ob_dealloc_fptr dealloc_funct, ob_hash_fptr hash_funct, ob_compare_fptr compare_funct, ob_display_fptr display_funct, const char *classname) |
Initializes instances of all offbrand compatible classes with a reference count of 1, a deallocator, a hash function, and the provided class name. More... | |
obj * | ob_release (obj *instance) |
Decrements the instances reference count by 1. If the reference count is reduced to 0 then release automatically calls the instances deallocator. More... | |
obj * | ob_retain (obj *instance) |
Increments the instances reference count by 1, indicating that the calling code has "referenced" that instance for later use. More... | |
uint32_t | ob_reference_count (obj *instance) |
Returns the current reference count of the given instance. More... | |
uint8_t | ob_has_class (const obj *a, const char *classname) |
Checks that the given obj is of the provided class. More... | |
uint8_t | ob_has_same_class (const obj *a, const obj *b) |
Checks that two objs are of the same class. More... | |
ob_hash_t | ob_hash (const obj *to_hash) |
Computes the hash value of the instance using a class specific hash function if one is available or the defaultHash function if not. More... | |
int8_t | ob_compare (const obj *a, const obj *b) |
comparision operator between any two offbrand compatible classes More... | |
void | ob_display (const obj *to_print) |
display operation prints information about the instance of any offbrand compatible class to stderr, for debug More... | |
Standard Library Implementation.
comparision operator between any two offbrand compatible classes
a | An instance of any offbrand compatible class |
b | An instance of any offbrand compatible class |
OB_LESS_THAN | obj a is less than b |
OB_GREATER_THAN | obj a is equivalent to b |
OB_EQUAL_TO | obj a is greater than b |
OB_NOT_EQUAL | obj a is not equal to b, but no other relationship can be infered |
void ob_display | ( | const obj * | to_print) |
display operation prints information about the instance of any offbrand compatible class to stderr, for debug
to_print | An instance of any offbrand compativle class |
uint8_t ob_has_class | ( | const obj * | a, |
const char * | classname | ||
) |
Checks that the given obj is of the provided class.
a | An instance of any offbrand compatible class |
classname | An C string describing a class name |
0 | a is not an instance of classname |
non-zero | a is an instance of classname |
Checks that two objs are of the same class.
a | An instance of any offbrand compatible class |
b | An instance of any offbrand compatible class |
0 | a and b are not of the same class |
non-zero | a and b are of the same class |
Computes the hash value of the instance using a class specific hash function if one is available or the defaultHash function if not.
to_hash | An instance of any offbrand compatible class |
void ob_init_base | ( | obj * | instance, |
ob_dealloc_fptr | dealloc_funct, | ||
ob_hash_fptr | hash_funct, | ||
ob_compare_fptr | compare_funct, | ||
ob_display_fptr | display_funct, | ||
const char * | classname | ||
) |
Initializes instances of all offbrand compatible classes with a reference count of 1, a deallocator, a hash function, and the provided class name.
instance | An newly allocated instance of any offbrand compatible class |
dealloc_funct | Function pointer to the deallocator for the instances class |
hash_funct | Function pointer to the hash function for the instances class |
compare_funct | Function pointer to the compare function for the instances class |
display_funct | Function pointer to the display function for the instances class |
classname | C string containing instances classname. |
uint32_t ob_reference_count | ( | obj * | instance) |
Returns the current reference count of the given instance.
instance | An instance of any offbrand compatible class |
Decrements the instances reference count by 1. If the reference count is reduced to 0 then release automatically calls the instances deallocator.
instance | An instance of any offbrand compatible class |
&instance | Reference count was decremented but the instance is still referenced |
NULL | Reference count was decremented to 0 and deallocator was called on instance |