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>
#include <assert.h>

Go to the source code of this file.

Macros

#define CMR_UNUSED(x)   (void)(x)
 
#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 , CMR_ERROR_TIMEOUT = 6
}
 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

◆ CMR_CALL

#define CMR_CALL (   call)
Value:
do \
{ \
CMR_ERROR _cmr_error = call; \
if (_cmr_error) \
{ \
if (_cmr_error == CMR_ERROR_INPUT) \
fprintf(stderr, "User input error"); \
else if (_cmr_error == CMR_ERROR_MEMORY) \
fprintf(stderr, "Memory (re)allocation failed"); \
else if (_cmr_error == CMR_ERROR_INVALID) \
fprintf(stderr, "Invalid input"); \
else if (_cmr_error == CMR_ERROR_TIMEOUT) \
fprintf(stderr, "Time limit exceeded"); \
else \
fprintf(stderr, "Unknown error"); \
fprintf(stderr, " in %s:%d.\n", __FILE__, __LINE__); \
return _cmr_error; \
} \
} while (false)
@ CMR_ERROR_TIMEOUT
Definition: env.h:39
@ CMR_ERROR_MEMORY
Definition: env.h:36
@ CMR_ERROR_INVALID
Definition: env.h:37
@ CMR_ERROR_INPUT
Definition: env.h:34

Call wrapper for calls returning a CMR_ERROR.

◆ CMR_UNUSED

#define CMR_UNUSED (   x)    (void)(x)

◆ CMRallocBlock

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

◆ CMRallocBlockArray

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

◆ CMRduplicateBlockArray

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

◆ CMRfreeBlock

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

Frees a block memory chunk allocated with CMRallocBlock.

◆ CMRfreeBlockArray

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

Carries out the deallocation for CMRfreeBlockArray.

Note
Use CMRfreeBlockArray to free a block memory array.

◆ CMRreallocBlockArray

#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

◆ CMR

typedef struct CMR_ENVIRONMENT CMR

Environment for computations.

Manages memory, threading, output and parameters.

Enumeration Type Documentation

◆ CMR_ERROR

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.

CMR_ERROR_TIMEOUT 

Time limit exceeded.

Function Documentation

◆ _CMRallocBlock()

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.

◆ _CMRallocBlockArray()

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.

◆ _CMRduplicateBlockArray()

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.

◆ _CMRfreeBlock()

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.

◆ _CMRfreeBlockArray()

CMR_EXPORT CMR_ERROR _CMRfreeBlockArray ( CMR cmr,
void **  ptr 
)

◆ _CMRreallocBlockArray()

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.

◆ CMRclearErrorMessage()

CMR_EXPORT void CMRclearErrorMessage ( CMR cmr)

Clears the error message.

Parameters
cmrCMR environment.

◆ CMRcreateEnvironment()

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.

◆ CMRfreeEnvironment()

CMR_EXPORT CMR_ERROR CMRfreeEnvironment ( CMR **  pcmr)

Frees a CMR environment.

Parameters
pcmrPointer to CMR environment.

◆ CMRgetErrorMessage()

CMR_EXPORT char* CMRgetErrorMessage ( CMR cmr)

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

Parameters
cmrCMR environment.