Mathematic Expressions Library  0.1
The core math data structures and manipulators
types.h File Reference
#include <stddef.h>
#include <limits.h>
#include <ctype.h>
Include dependency graph for types.h:

Go to the source code of this file.

Data Structures

union  value_data
 value data container provider More...
 
struct  value
 Represents a numeric value or an error. More...
 

Macros

#define SYS_INT_LONG_T_MIN   LONG_MIN
 
#define SYS_INT_LONG_T_MAX   LONG_MAX
 
#define SYS_INT_LONG_T_STR_SIZE   11
 The length in chars for a long int string. 4 byte long - $ {\tt ceiling} \left( {\tt log10}(2^{4 \times 8 - 1}) \right) + 1$. More...
 
#define SIZE_T_MAX   ( ~( (size_t) (0) ) )
 
#define PINDEX_MAX   SIZE_T_MAX
 The max value of pindex_t. More...
 
#define PINDEX_BAD   PINDEX_MAX
 Special value of pindex_t that signals a bad value. More...
 
#define IS_WHITESPACE(c)   ( ((c) == ' ') || ((c) == '\t') )
 
#define IS_DIGIT(c)   ( ( '0' <= (c) ) && ( (c) <= '9') )
 
#define IS_ALPHA(c)   isalpha(c)
 
#define IS_ALNUM(c)   isalnum(c)
 

Typedefs

typedef int long sys_int_long
 
typedef size_t pindex_t
 Type for an index into an expression string during parsing. More...
 
typedef size_t pcount_t
 Type for an item count during parsing. More...
 
typedef struct value value_t
 

Enumerations

enum  value_types { VAL_ERROR, VAL_UNDEF, VAL_INF, VAL_LINT }
 value type selector More...
 

Functions

value_t value_new_type (enum value_types type)
 
value_t value_new_lint (sys_int_long lint)
 
value_t string_to_value (size_t src_str_len, char const *src_str)
 Create value from a string. More...
 
void value_to_string (char *dst_str, value_t src_val)
 
pindex_t find_matching (size_t str_len, const char *str, pindex_t start)
 Find the index of the matching closing paren in a string. More...
 

Detailed Description

Date
Apr 23, 2014
Author
Craig Hesling

Contains standard types, macros, and functions used throughout the library. Most notably, this is the home of the value_t.

Macro Definition Documentation

◆ IS_ALNUM

#define IS_ALNUM (   c)    isalnum(c)

◆ IS_ALPHA

#define IS_ALPHA (   c)    isalpha(c)

◆ IS_DIGIT

#define IS_DIGIT (   c)    ( ( '0' <= (c) ) && ( (c) <= '9') )
Note
Is defined in
See also
types.c.

◆ IS_WHITESPACE

#define IS_WHITESPACE (   c)    ( ((c) == ' ') || ((c) == '\t') )

◆ PINDEX_BAD

#define PINDEX_BAD   PINDEX_MAX

Special value of pindex_t that signals a bad value.

◆ PINDEX_MAX

#define PINDEX_MAX   SIZE_T_MAX

The max value of pindex_t.

◆ SIZE_T_MAX

#define SIZE_T_MAX   ( ~( (size_t) (0) ) )

◆ SYS_INT_LONG_T_MAX

#define SYS_INT_LONG_T_MAX   LONG_MAX

◆ SYS_INT_LONG_T_MIN

#define SYS_INT_LONG_T_MIN   LONG_MIN

◆ SYS_INT_LONG_T_STR_SIZE

#define SYS_INT_LONG_T_STR_SIZE   11

The length in chars for a long int string. 4 byte long - $ {\tt ceiling} \left( {\tt log10}(2^{4 \times 8 - 1}) \right) + 1$.

Typedef Documentation

◆ pcount_t

typedef size_t pcount_t

Type for an item count during parsing.

◆ pindex_t

typedef size_t pindex_t

Type for an index into an expression string during parsing.

◆ sys_int_long

typedef int long sys_int_long

◆ value_t

typedef struct value value_t

Enumeration Type Documentation

◆ value_types

value type selector

Enumerator
VAL_ERROR 
VAL_UNDEF 
VAL_INF 
VAL_LINT 

Function Documentation

◆ find_matching()

pindex_t find_matching ( size_t  str_len,
const char *  str,
pindex_t  start 
)

Find the index of the matching closing paren in a string.

Parameters
str_lenOverall string length.
strString to search in.
startIndex of the open paren to match.
Returns
The index of the matching paren or PINDEX_BAD if no match was found.
Note
Assumes start is the index of the open paren to match and then moves forward.

◆ string_to_value()

value_t string_to_value ( size_t  src_str_len,
char const *  src_str 
)

Create value from a string.

Parameters
src_str_lenThe length of the actual buffer (not the number size).
src_strThe source string.
Returns
The value in the source string.
Note
Must have first char be digit
Currently we only do Long Ints

<

Note
Here we assume it is a Long Int

<

Warning
Uses system atol() function at index 0 on the bare string given
Here is the call graph for this function:

◆ value_new_lint()

value_t value_new_lint ( sys_int_long  lint)

◆ value_new_type()

value_t value_new_type ( enum value_types  type)

◆ value_to_string()

void value_to_string ( char *  dst_str,
value_t  src_val 
)

<

Warning
Unknown types of value_t will just assert(false) here.