symbolic4
foundation.h File Reference
#include "symbolic4.h"

Go to the source code of this file.

Data Structures

struct  error
 

Macros

#define ERROR_CHECK(F)   if ((F) == RETS_ERROR) return RETS_ERROR
 Check if the return status of a function is RETS_ERROR. If so, return RETS_ERROR. More...
 

Enumerations

enum  error_domain {
  ERRD_NULL, ERRD_SYSTEM, ERRD_SYNTAX, ERRD_MATH,
  ERRD_EXPRESSION, ERRD_PARSER, ERRD_SIMPLFY, ERRD_SOLVE,
  ERRD_DERIVATIVE, ERRD_INTEGRAL, ERRD_POLY, ERRD_MATRIX,
  ERRD_VECTOR
}
 
enum  error_identifier {
  ERRI_NULL, ERRI_MEMORY_ALLOCATION, ERRI_UNEXPECTED_CHARACTER, ERRI_UNEXPECTED_EXPRESSION,
  ERRI_FUNCTION_CALL_SYNTAX, ERRI_SYNTAX, ERRI_PARENTHESIS_MISMATCH, ERRI_MAX_INT_VALUE_EXCEEDED,
  ERRI_ARGUMENTS, ERRI_VECTOR_DIMENSIONS, ERRI_UNDEFINED_VALUE, ERRI_NON_DIFFERENTIABLE
}
 
enum  return_status {
  RETS_NULL, RETS_ERROR, RETS_SUCCESS, RETS_CHANGED,
  RETS_UNCHANGED
}
 

Functions

void * smart_alloc (uint8_t length, size_t size)
 Allocates and keeps track of memory. More...
 
void * smart_realloc (void *source, uint8_t length, size_t size)
 Resizes a pointer. More...
 
void smart_free (void *pointer)
 Frees a pointer. More...
 
void smart_free_all (void)
 Frees all pointers. More...
 
uint8_t set_error (error_domain domain, error_identifier identifier, const char *body)
 Sets current_error to the arguments provided. More...
 
void set_handle_unrecoverable_error (error_domain domain, error_identifier identifier, const char *body)
 Handles severe and unrecoverable errors. More...
 
double uintmax_max_value (void)
 
char * string_to_lower (const char *string)
 Converts a string to lowercase. More...
 
void itoa (char *buffer, uintmax_t source)
 
void dtoa (char *buffer, uint8_t length, double source)
 

Variables

error current_error
 
void ** allocated_pointers
 
bool smart_alloc_is_recording
 

Macro Definition Documentation

◆ ERROR_CHECK

#define ERROR_CHECK (   F)    if ((F) == RETS_ERROR) return RETS_ERROR

Check if the return status of a function is RETS_ERROR. If so, return RETS_ERROR.

Definition at line 31 of file foundation.h.

Enumeration Type Documentation

◆ error_domain

Enumerator
ERRD_NULL 
ERRD_SYSTEM 
ERRD_SYNTAX 
ERRD_MATH 
ERRD_EXPRESSION 
ERRD_PARSER 
ERRD_SIMPLFY 
ERRD_SOLVE 
ERRD_DERIVATIVE 
ERRD_INTEGRAL 
ERRD_POLY 
ERRD_MATRIX 
ERRD_VECTOR 

Definition at line 33 of file foundation.h.

◆ error_identifier

Enumerator
ERRI_NULL 
ERRI_MEMORY_ALLOCATION 
ERRI_UNEXPECTED_CHARACTER 
ERRI_UNEXPECTED_EXPRESSION 
ERRI_FUNCTION_CALL_SYNTAX 
ERRI_SYNTAX 
ERRI_PARENTHESIS_MISMATCH 
ERRI_MAX_INT_VALUE_EXCEEDED 
ERRI_ARGUMENTS 
ERRI_VECTOR_DIMENSIONS 
ERRI_UNDEFINED_VALUE 
ERRI_NON_DIFFERENTIABLE 

Definition at line 49 of file foundation.h.

◆ return_status

Enumerator
RETS_NULL 
RETS_ERROR 
RETS_SUCCESS 
RETS_CHANGED 
RETS_UNCHANGED 

Definition at line 64 of file foundation.h.

Function Documentation

◆ dtoa()

void dtoa ( char *  buffer,
uint8_t  length,
double  source 
)

Definition at line 233 of file foundation.c.

◆ itoa()

void itoa ( char *  buffer,
uintmax_t  source 
)

Definition at line 216 of file foundation.c.

◆ set_error()

uint8_t set_error ( error_domain  domain,
error_identifier  identifier,
const char *  body 
)

Sets current_error to the arguments provided.

Parameters
[in]domain
[in]identifier
[in]body
Returns
  • Returns always RETS_ERROR

Definition at line 152 of file foundation.c.

◆ set_handle_unrecoverable_error()

void set_handle_unrecoverable_error ( error_domain  domain,
error_identifier  identifier,
const char *  body 
)

Handles severe and unrecoverable errors.

This function serves as the last resort when the program encounters exceptionally severe errors, such as a failed memory allocation, from which it can't recover itself. The

while (true);

loop may be replaced with system-specific error handling.

Warning
  • This function should only be called if everything else has failed.
Parameters
[in]domainThe error domain.
[in]identifierThe error identifier.
[in]bodyThe error body.

Definition at line 181 of file foundation.c.

◆ smart_alloc()

void* smart_alloc ( uint8_t  length,
size_t  size 
)

Allocates and keeps track of memory.

The pointer to the allocated memory is stored in the allocated_pointers array.

Precondition
  • The allocated_pointers array must be initialized with NULL, or else the loop won't work.
Warning
Parameters
[in]lengthThe length/count of the elements.
[in]sizeThe size of one element (see sizeof()).
Returns
  • A void-pointer to the allocated memory.
See also

Definition at line 59 of file foundation.c.

◆ smart_free()

void smart_free ( void *  pointer)

Frees a pointer.

This function frees a pointer and sets its corresponding entry in the allocated_pointers array to NULL.

Parameters
[in]pointerThe pointer to be freed.
See also

Definition at line 112 of file foundation.c.

◆ smart_free_all()

void smart_free_all ( void  )

Frees all pointers.

This function frees all pointers allocated with smart_alloc() by iteratively calling smart_free().

See also

Definition at line 133 of file foundation.c.

◆ smart_realloc()

void* smart_realloc ( void *  source,
uint8_t  length,
size_t  size 
)

Resizes a pointer.

The resized pointer to the allocated memory is stored in the allocated_pointers array.

Parameters
[in]sourceThe pointer to be resized.
[in]lengthThe new length/count of the elements.
[in]sizeThe size of one element (see sizeof()).
See also

Definition at line 86 of file foundation.c.

◆ string_to_lower()

char* string_to_lower ( const char *  string)

Converts a string to lowercase.

This function copies the source string and converts that copy character-wise to lowercase. The resulting string must be freed.

Parameters
[in]stringThe string to convert.
Returns
  • The new string in lowercase letters.

Definition at line 206 of file foundation.c.

◆ uintmax_max_value()

double uintmax_max_value ( void  )

Definition at line 188 of file foundation.c.

Variable Documentation

◆ allocated_pointers

void** allocated_pointers

Definition at line 29 of file foundation.c.

◆ current_error

error current_error

Definition at line 28 of file foundation.c.

◆ smart_alloc_is_recording

bool smart_alloc_is_recording

Definition at line 30 of file foundation.c.