pelib  2.0.0
include/pelib/structure.h File Reference
#include <stdio.h>
#include <stddef.h>
#include <pelib/template.h>
Include dependency graph for structure.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define pelib_alloc_buffer(elem)   PELIB_CONCAT_3(pelib_,elem,_alloc_buffer)
#define pelib_set_buffer(elem)   PELIB_CONCAT_3(pelib_,elem,_set_buffer)
#define pelib_alloc_struct(elem)   PELIB_CONCAT_3(pelib_,elem,_alloc_struct)
#define pelib_alloc(elem)   PELIB_CONCAT_3(pelib_,elem,_alloc)
#define pelib_alloc_collection(elem)   PELIB_CONCAT_3(pelib_,elem,_alloc_collection)
#define pelib_alloc_from(elem)   PELIB_CONCAT_3(pelib_,elem,_alloc_from)
#define pelib_init(elem)   PELIB_CONCAT_3(pelib_,elem,_init)
#define pelib_copy(elem)   PELIB_CONCAT_3(pelib_,elem,_copy)
#define pelib_free_buffer(elem)   PELIB_CONCAT_3(pelib_,elem,_free_buffer)
#define pelib_free_struct(elem)   PELIB_CONCAT_3(pelib_,elem,_free_struct)
#define pelib_free(elem)   PELIB_CONCAT_3(pelib_,elem,_free)
#define pelib_destroy(elem)   PELIB_CONCAT_3(pelib_,elem,_destroy)
#define pelib_compare(elem)   PELIB_CONCAT_3(pelib_,elem,_compare)
#define pelib_printf(elem)   PELIB_CONCAT_3(pelib_,elem,_printf)
#define pelib_printf_detail(elem)   PELIB_CONCAT_3(pelib_,elem,_printf_detail)
#define pelib_fwrite(elem)   PELIB_CONCAT_3(pelib_,elem,_fwrite)
#define pelib_fread(elem)   PELIB_CONCAT_3(pelib_,elem,_fread)
#define pelib_string(elem)   PELIB_CONCAT_3(pelib_,elem,_string)
#define pelib_string_detail(elem)   PELIB_CONCAT_3(pelib_,elem,_string_detail)

Functions

STRUCT_T *pelib_alloc_struct() STRUCT_T ()
int pelib_alloc_buffer() STRUCT_T (STRUCT_T *obj, size_t n)
int pelib_set_buffer() STRUCT_T (STRUCT_T *obj, void *buffer, size_t n)
STRUCT_T *pelib_alloc_collection() STRUCT_T (size_t n)
STRUCT_T *pelib_alloc_from() STRUCT_T (void *buffer, size_t n)
int pelib_init() STRUCT_T (STRUCT_T *obj)
int pelib_copy() STRUCT_T (STRUCT_T src, STRUCT_T *dst)
int pelib_destroy() STRUCT_T (STRUCT_T)
int pelib_compare() STRUCT_T (STRUCT_T a, STRUCT_T b)
FILE *pelib_printf() STRUCT_T (FILE *str, STRUCT_T obj)
FILE *pelib_printf_detail() STRUCT_T (FILE *str, STRUCT_T obj, int lvl)
size_t pelib_fwrite() STRUCT_T (STRUCT_T obj, FILE *str)
size_t pelib_fread() STRUCT_T (STRUCT_T *obj, FILE *str)
char *pelib_string_detail() STRUCT_T (STRUCT_T, int)

Define Documentation

#define pelib_alloc (   elem)    PELIB_CONCAT_3(pelib_,elem,_alloc)

Definition at line 39 of file structure.h.

#define pelib_alloc_buffer (   elem)    PELIB_CONCAT_3(pelib_,elem,_alloc_buffer)

Definition at line 36 of file structure.h.

#define pelib_alloc_collection (   elem)    PELIB_CONCAT_3(pelib_,elem,_alloc_collection)

Definition at line 40 of file structure.h.

#define pelib_alloc_from (   elem)    PELIB_CONCAT_3(pelib_,elem,_alloc_from)

Definition at line 41 of file structure.h.

#define pelib_alloc_struct (   elem)    PELIB_CONCAT_3(pelib_,elem,_alloc_struct)

Definition at line 38 of file structure.h.

#define pelib_compare (   elem)    PELIB_CONCAT_3(pelib_,elem,_compare)

Definition at line 48 of file structure.h.

#define pelib_copy (   elem)    PELIB_CONCAT_3(pelib_,elem,_copy)

Definition at line 43 of file structure.h.

#define pelib_destroy (   elem)    PELIB_CONCAT_3(pelib_,elem,_destroy)

Definition at line 47 of file structure.h.

#define pelib_fread (   elem)    PELIB_CONCAT_3(pelib_,elem,_fread)

Definition at line 52 of file structure.h.

#define pelib_free (   elem)    PELIB_CONCAT_3(pelib_,elem,_free)

Definition at line 46 of file structure.h.

#define pelib_free_buffer (   elem)    PELIB_CONCAT_3(pelib_,elem,_free_buffer)

Definition at line 44 of file structure.h.

#define pelib_free_struct (   elem)    PELIB_CONCAT_3(pelib_,elem,_free_struct)

Definition at line 45 of file structure.h.

#define pelib_fwrite (   elem)    PELIB_CONCAT_3(pelib_,elem,_fwrite)

Definition at line 51 of file structure.h.

#define pelib_init (   elem)    PELIB_CONCAT_3(pelib_,elem,_init)

Definition at line 42 of file structure.h.

#define pelib_printf (   elem)    PELIB_CONCAT_3(pelib_,elem,_printf)

Definition at line 49 of file structure.h.

#define pelib_printf_detail (   elem)    PELIB_CONCAT_3(pelib_,elem,_printf_detail)

Definition at line 50 of file structure.h.

#define pelib_set_buffer (   elem)    PELIB_CONCAT_3(pelib_,elem,_set_buffer)

Definition at line 37 of file structure.h.

#define pelib_string (   elem)    PELIB_CONCAT_3(pelib_,elem,_string)

Definition at line 53 of file structure.h.

#define pelib_string_detail (   elem)    PELIB_CONCAT_3(pelib_,elem,_string_detail)

Definition at line 54 of file structure.h.


Function Documentation

Allocates the base structure of a pelib object

Returns:
A pointer to the newly allocated base structure

Allocate a new pelib simple data structure

Returns:
A pointer to a newly allocated data structure

Allocates the buffer of a pelib collection

Parameters:
objPointer to pelib colelction that will receive the buffer
nNumber of element this buffer should accept
int pelib_set_buffer() STRUCT_T ( STRUCT_T obj,
void buffer,
size_t  n 
)

Replaces the buffer of a pelib collection with a new memory address. The reference to the old buffer is lost and the old buffer is not freed

Parameters:
objPelib collection whose buffer is replaced
bufferNew buffer for the pelib collection
nNumber of element the new buffer can hold
Returns:
0 if the operation failed and non-zero otherwise

Allocates a new pelib collection without initializing it

Parameters:
nNumber of element the collection can hold after instanciation
Returns:
Pointer to newly instanciated pelib collection
STRUCT_T* pelib_alloc_from() STRUCT_T ( void buffer,
size_t  n 
)

Allocate a new pelib collection and uses an existing memory location as buffer

Parameters:
bufferAddress of the memory to use as buffer
nNumber of elements the new collection can hold
Returns:
Newly allocated pelib collection

Initializes a newly allocated pelib object

Parameters:
objPelib object instance to be initialized
Returns:
0 if the operation failed and non-zero otherwise

Frees the memory associated to the base structure of a pelib object

Parameters:
objPelib object to be freed
Returns:
0 if the operation failed and non-zero otherwise

Frees the memory associated to the buffer of a pelib collection

Parameters:
Pelibcollection whose buffer is to be freed
Returns:
0 if the operation failed and non-zero otherwise

Frees a comple pelib simple or collection object, including its buffer

Returns:
0 if the operation failed and non-zero otherwise
int pelib_copy() STRUCT_T ( STRUCT_T  src,
STRUCT_T dst 
)

Copies a pelib object instance to another

Parameters:
srcPelib object source
dstPelib object that receives the copy

Destroys a pelib object before its memory is freed

Returns:
0 if the operation failed and non-zero otherwise

Returns a simple human-readable string representation of an instance of pelib object

Compares two pelib object

Returns:
-1 if a < b, 1 if a > b and 0 if a == b
FILE* pelib_printf() STRUCT_T ( FILE *  str,
STRUCT_T  obj 
)

Writes a simple human-readable representation of a pelib object instance to some stream

Parameters:
strOutput stream to write the object to
objPelib object to be written
Returns:
output stream after the pelib object was written
FILE* pelib_printf_detail() STRUCT_T ( FILE *  str,
STRUCT_T  obj,
int  lvl 
)

Writes a detailed human-redable representation of a pelib object instance to some stream

Parameters:
strOutput stream to write the object to
objPelib object to be written
lvlLevel of details to be written to output stream. For a collection, will write all elements in the collection with detail level = lvl - 1. Useful to display collections of complex objects and visualize all objects in details in a single line of code
Returns:
Output stream after the object instance was written
size_t pelib_fwrite() STRUCT_T ( STRUCT_T  obj,
FILE *  str 
)

Writes a pelib object instance to output stream. pelib_fread must be able to read back the written object instance and store it to memory

Parameters:
objPelib object instance to be written
stroutput stream that receives the written pelib object instance
Returns:
Number of bytes written
size_t pelib_fread() STRUCT_T ( STRUCT_T obj,
FILE *  str 
)

Reads a pelib object from input stream produced by pelib_fwrite and write it in an existing pelib object instance

Parameters:
objPointer to object that receives the data read from input stream
strInput stream whose content is produced by pelib_fwrite to read data from
Returns:
Number of bytes read
char* pelib_string_detail() STRUCT_T ( STRUCT_T  ,
int   
)

Returns a detailed view human-readable string representation of an instance of pelib object. For a collection, the same function is run for all pelib object instances held is the collection with a lower level value.

Parameters:
objPelib object to be written to
lvlLevel of details to be generated