offbrand
A collection of generic, reference counted datastructures in C for C
 All Classes Files Functions Variables Typedefs Macros Groups
Functions
offbrand_stdlib.c File Reference

Standard Library Implementation. More...

#include "../include/offbrand.h"
#include "../include/private/obj_Private.h"

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...
 
objob_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...
 
objob_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...
 

Detailed Description

Standard Library Implementation.

Author
theck

Function Documentation

int8_t ob_compare ( const obj a,
const obj b 
)

comparision operator between any two offbrand compatible classes

Parameters
aAn instance of any offbrand compatible class
bAn instance of any offbrand compatible class
Return values
OB_LESS_THANobj a is less than b
OB_GREATER_THANobj a is equivalent to b
OB_EQUAL_TOobj a is greater than b
OB_NOT_EQUALobj 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

Parameters
to_printAn 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.

Parameters
aAn instance of any offbrand compatible class
classnameAn C string describing a class name
Return values
0a is not an instance of classname
non-zeroa is an instance of classname
uint8_t ob_has_same_class ( const obj a,
const obj b 
)

Checks that two objs are of the same class.

Parameters
aAn instance of any offbrand compatible class
bAn instance of any offbrand compatible class
Return values
0a and b are not of the same class
non-zeroa and b are of the same class
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.

Parameters
to_hashAn instance of any offbrand compatible class
Returns
Hash value
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.

Parameters
instanceAn newly allocated instance of any offbrand compatible class
dealloc_functFunction pointer to the deallocator for the instances class
hash_functFunction pointer to the hash function for the instances class
compare_functFunction pointer to the compare function for the instances class
display_functFunction pointer to the display function for the instances class
classnameC string containing instances classname.
uint32_t ob_reference_count ( obj instance)

Returns the current reference count of the given instance.

Parameters
instanceAn instance of any offbrand compatible class
Returns
An unsigned integer reference count
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.

Parameters
instanceAn instance of any offbrand compatible class
Return values
&instanceReference count was decremented but the instance is still referenced
NULLReference count was decremented to 0 and deallocator was called on instance
obj* ob_retain ( obj instance)

Increments the instances reference count by 1, indicating that the calling code has "referenced" that instance for later use.

Parameters
instanceAn instance of any offbrand compatible class
Returns
A reference to the argument instance.