CMR  1.3.0
Macros | Typedefs | Enumerations | Functions
env.h File Reference

Basic functionality of the software library. More...

#include <cmr/config.h>
#include <cmr/export.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>

Go to the source code of this file.

Macros

#define CMR_CALL(call)
 Call wrapper for calls returning a CMR_ERROR. More...
 
#define CMRallocBlock(cmr, ptr)   _CMRallocBlock(cmr, (void**) ptr, sizeof(**ptr))
 Allocates block memory for *ptr. More...
 
#define CMRfreeBlock(cmr, ptr)   _CMRfreeBlock(cmr, (void**) ptr, sizeof(**ptr))
 Frees a block memory chunk allocated with CMRallocBlock. More...
 
#define CMRallocBlockArray(cmr, ptr, length)   _CMRallocBlockArray(cmr, (void**) ptr, sizeof(**ptr), length)
 Allocates block memory for an array of chunks. More...
 
#define CMRreallocBlockArray(cmr, ptr, length)   _CMRreallocBlockArray(cmr, (void**) ptr, sizeof(**ptr), length)
 Reallocates block memory of an array of chunks. More...
 
#define CMRduplicateBlockArray(cmr, ptr, length, source)   _CMRduplicateBlockArray(cmr, (void**) ptr, sizeof(**ptr), length, source)
 Allocates block memory for an array of chunks and copies it from source. More...
 
#define CMRfreeBlockArray(cmr, ptr)   _CMRfreeBlockArray(cmr, (void**) ptr)
 Carries out the deallocation for CMRfreeBlockArray. More...
 

Typedefs

typedef struct CMR_ENVIRONMENT CMR
 Environment for computations. More...
 

Enumerations

enum  CMR_ERROR {
  CMR_OKAY = 0, CMR_ERROR_INPUT = 1, CMR_ERROR_OUTPUT = 2, CMR_ERROR_MEMORY = 3,
  CMR_ERROR_INVALID = 4, CMR_ERROR_OVERFLOW = 5
}
 Type for return codes of library functions. More...
 

Functions

CMR_EXPORT CMR_ERROR CMRcreateEnvironment (CMR **pcmr)
 Allocates and initializes a default CMR environment. More...
 
CMR_EXPORT CMR_ERROR CMRfreeEnvironment (CMR **pcmr)
 Frees a CMR environment. More...
 
CMR_EXPORT CMR_ERROR _CMRallocBlock (CMR *cmr, void **ptr, size_t size)
 Carries out the allocation for CMRallocBlock. More...
 
CMR_EXPORT CMR_ERROR _CMRfreeBlock (CMR *cmr, void **ptr, size_t size)
 Carries out the deallocation for CMRfreeBlock. More...
 
CMR_EXPORT CMR_ERROR _CMRallocBlockArray (CMR *cmr, void **ptr, size_t size, size_t length)
 Carries out the allocation for CMRallocBlockArray. More...
 
CMR_EXPORT CMR_ERROR _CMRreallocBlockArray (CMR *cmr, void **ptr, size_t size, size_t length)
 Carries out the reallocation for CMRreallocBlockArray. More...
 
CMR_EXPORT CMR_ERROR _CMRduplicateBlockArray (CMR *cmr, void **ptr, size_t size, size_t length, void *source)
 Carries out the duplication for CMRduplicateBlockArray. More...
 
CMR_EXPORT CMR_ERROR _CMRfreeBlockArray (CMR *cmr, void **ptr)
 
CMR_EXPORT char * CMRgetErrorMessage (CMR *cmr)
 Returns the error message (or NULL if no error with a message occured). More...
 
CMR_EXPORT void CMRclearErrorMessage (CMR *cmr)
 Clears the error message. More...
 

Detailed Description

Basic functionality of the software library.

Author
Matthias Walter

Macro Definition Documentation

#define CMR_CALL (   call)
Value:
do \
{ \
CMR_ERROR _cmr_error = call; \
if (_cmr_error) \
{ \
if (_cmr_error == CMR_ERROR_INPUT) \
printf("User input error"); \
else if (_cmr_error == CMR_ERROR_MEMORY) \
printf("Memory (re)allocation failed"); \
else if (_cmr_error == CMR_ERROR_INVALID) \
printf("Invalid input"); \
else \
printf("Unknown error"); \
printf(" in %s:%d.\n", __FILE__, __LINE__); \
return _cmr_error; \
} \
} while (false)
Definition: env.h:29
CMR_ERROR
Type for return codes of library functions.
Definition: env.h:26
Definition: env.h:32
Definition: env.h:31

Call wrapper for calls returning a CMR_ERROR.

#define CMRallocBlock (   cmr,
  ptr 
)    _CMRallocBlock(cmr, (void**) ptr, sizeof(**ptr))

Allocates block memory for *ptr.

Block memory shall be freed with CMRfreeBlock. The size is determined automatically.

#define CMRallocBlockArray (   cmr,
  ptr,
  length 
)    _CMRallocBlockArray(cmr, (void**) ptr, sizeof(**ptr), length)

Allocates block memory for an array of chunks.

The block memory shall be freed with CMRfreeBlockArray. Its size can be changed via CMRreallocBlockArray. The size of each chunk is determined automatically.

#define CMRduplicateBlockArray (   cmr,
  ptr,
  length,
  source 
)    _CMRduplicateBlockArray(cmr, (void**) ptr, sizeof(**ptr), length, source)

Allocates block memory for an array of chunks and copies it from source.

The block memory shall be freed with CMRfreeBlockArray. Its size can be changed via CMRreallocBlockArray. The size of each chunk is determined automatically.

#define CMRfreeBlock (   cmr,
  ptr 
)    _CMRfreeBlock(cmr, (void**) ptr, sizeof(**ptr))

Frees a block memory chunk allocated with CMRallocBlock.

#define CMRfreeBlockArray (   cmr,
  ptr 
)    _CMRfreeBlockArray(cmr, (void**) ptr)

Carries out the deallocation for CMRfreeBlockArray.

Note
Use CMRfreeBlockArray to free a block memory array.
#define CMRreallocBlockArray (   cmr,
  ptr,
  length 
)    _CMRreallocBlockArray(cmr, (void**) ptr, sizeof(**ptr), length)

Reallocates block memory of an array of chunks.

The block memory shall be freed with CMRfreeBlockArray. The size of each chunk is determined automatically.

Typedef Documentation

typedef struct CMR_ENVIRONMENT CMR

Environment for computations.

Manages memory, threading, output and parameters.

Enumeration Type Documentation

enum CMR_ERROR

Type for return codes of library functions.

Enumerator
CMR_OKAY 

No error.

CMR_ERROR_INPUT 

Bad user input.

CMR_ERROR_OUTPUT 

Error when writing user output.

CMR_ERROR_MEMORY 

Error during (re)allocation.

CMR_ERROR_INVALID 

Other invalid data.

CMR_ERROR_OVERFLOW 

Overflow in numerical computations.

Function Documentation

CMR_EXPORT CMR_ERROR _CMRallocBlock ( CMR cmr,
void **  ptr,
size_t  size 
)

Carries out the allocation for CMRallocBlock.

Note
Use CMRallocBlock to allocate block memory.
CMR_EXPORT CMR_ERROR _CMRallocBlockArray ( CMR cmr,
void **  ptr,
size_t  size,
size_t  length 
)

Carries out the allocation for CMRallocBlockArray.

Note
Use CMRallocBlockArray to allocate block memory.
CMR_EXPORT CMR_ERROR _CMRduplicateBlockArray ( CMR cmr,
void **  ptr,
size_t  size,
size_t  length,
void *  source 
)

Carries out the duplication for CMRduplicateBlockArray.

Note
Use CMRduplicateBlockArray to duplicate block memory.
CMR_EXPORT CMR_ERROR _CMRfreeBlock ( CMR cmr,
void **  ptr,
size_t  size 
)

Carries out the deallocation for CMRfreeBlock.

Note
Use CMRfreeBlock to free block memory.
CMR_EXPORT CMR_ERROR _CMRfreeBlockArray ( CMR cmr,
void **  ptr 
)
CMR_EXPORT CMR_ERROR _CMRreallocBlockArray ( CMR cmr,
void **  ptr,
size_t  size,
size_t  length 
)

Carries out the reallocation for CMRreallocBlockArray.

Note
Use CMRreallocBlockArray to reallocate block memory.
CMR_EXPORT void CMRclearErrorMessage ( CMR cmr)

Clears the error message.

Parameters
cmrCMR environment.
CMR_EXPORT CMR_ERROR CMRcreateEnvironment ( CMR **  pcmr)

Allocates and initializes a default CMR environment.

It has default parameters and outputs to stdout.

Parameters
pcmrPointer at which the CMR environment shall be allocated.
CMR_EXPORT CMR_ERROR CMRfreeEnvironment ( CMR **  pcmr)

Frees a CMR environment.

Parameters
pcmrPointer to CMR environment.
CMR_EXPORT char* CMRgetErrorMessage ( CMR cmr)

Returns the error message (or NULL if no error with a message occured).

Parameters
cmrCMR environment.