Commit cfb94241 authored by Chris Müller's avatar Chris Müller

doc: add documentatzion for standard.h

parent 7e782619
......@@ -19,19 +19,36 @@
#ifndef CRYSTAL_STANDARD_H
#define CRYSTAL_STANDARD_H
/**
* @file standard.h
* Sets general operations, definitions and typdefs used by crystal modules (header, implementation)
*/
#include <stdlib.h>
#include <stdint.h>
/**
* Convenient Macro for generating tuple types, returning error codes
* and data in a synchronous manner (without using return arguments via pointers)
* @param type Sets the type for the data field of this tuple
* @param T Sets the name for this tuple struct
*/
#define crydefine__tuple(type, T) \
struct T { \
return_code code; \
type data; \
}
/** General error code indicating all is fine */
#define CRY_OKAY 0
/** typedef to hide void* pointers for clearer interfaces */
typedef void* pointer;
/** typedef to hide void* const_pointers for clearer interfaces */
typedef const void* const_pointer;
/** General typedef for setting an error code identifier */
typedef int return_code;
crydefine__tuple(pointer, tuple_pointer);
......@@ -42,11 +59,38 @@ crydefine__tuple(long, tuple_long);
crydefine__tuple(double, tuple_double);
crydefine__tuple(float, tuple_float);
/**
* Crystal's malloc macro for allocating memory based on a type
* @param Type Set directly the type for this memory block (dont use sizeof)
*/
#define cry_malloc(Type) malloc(sizeof(Type))
/**
* Crystal's calloc macro for allocating memory based on a type
* @param Type Set directly the type for this memory block (dont use sizeof)
* @param num Set the number of elements (of type Type)
*/
#define cry_calloc(Type, num) calloc(num, sizeof(Type))
/**
* Crystal's realloc macro for allocating memory based on a type
* @param Type Set directly the type for this memory block (dont use sizeof)
* @param Pointer Set the Adress of the existing memory block that should be reallocated.
* @param num Set the number of elements (of type Type)
*/
#define cry_realloc(Type, Pointer, num) realloc(Pointer, sizeof(Pointer) * num)
/**
* Crystal free macro for deallocating memory (equivalent to free(Pointer))
* @param Pointer The address of the freeing memory block
*/
#define cry_free(Pointer) free(Pointer)
/**
* Convenient casting operator for cleaner code similar to c++ static_cast in its appearance.
* @param Type The type the variable Var should be casted
* @param Var The given variable that should be casted
*/
#define cry_cast(Type, Var) ((Type)Var)
#endif // CRYSTAL_STANDARD_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment