offbrand
A collection of generic, reference counted datastructures in C for C
|
offbrand Standard Library More...
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <assert.h>
#include <time.h>
Go to the source code of this file.
Macros | |
#define | OB_EQUAL_TO 0 |
#define | OB_GREATER_THAN 1 |
#define | OB_LESS_THAN -1 |
#define | OB_NOT_EQUAL 2 |
#define | OB_LEAST_TO_GREATEST -1 |
#define | OB_GREATEST_TO_LEAST 1 |
Typedefs | |
typedef struct obj_struct * | obj |
typedef uint32_t | ob_ref_count_t |
typedef void(* | ob_dealloc_fptr )(obj *) |
typedef size_t | ob_hash_t |
typedef ob_hash_t(* | ob_hash_fptr )(const obj *) |
typedef int8_t(* | ob_compare_fptr )(const obj *, const obj *) |
typedef void(* | ob_display_fptr )(const obj *) |
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... | |
offbrand Standard Library
The standard library defines all data structures and function calls required for memory management via reference count, class membership tests, hashing, and others.
#define OB_EQUAL_TO 0 |
Comparison Constant, two elements are equal
#define OB_GREATER_THAN 1 |
Comparison Constant, the first element is greater than the second
#define OB_GREATEST_TO_LEAST 1 |
Sorting Order Constant, sort elements from greatest to least
#define OB_LEAST_TO_GREATEST -1 |
Sorting Order Constant, sort elements from least to greatest
#define OB_LESS_THAN -1 |
Comparison Constant, the first element is less than the second
#define OB_NOT_EQUAL 2 |
Comparison Constant, the first element is not equal to the second, and no other relation ship can be infered
function pointer to a comparision function that takes pointers to any two offbrand compatible classes and returns one of the comparision constants listed in the constants section.
typedef void(* ob_dealloc_fptr)(obj *) |
function pointer to a deallocator for any OffBrand compatible class
typedef void(* ob_display_fptr)(const obj *) |
function pointer to a display function for any offbrand compatible class
function pointer to a hash function for any offbrand compatible class
typedef size_t ob_hash_t |
hash value, used returned from hash functions
typedef uint32_t ob_ref_count_t |
reference count, tracks references to instances of offbrand compatible classes
typedef struct obj_struct* obj |
basic generic type used to track reference counts, store class specific function pointers, and form the basis for all generic container classes and functions.
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 |