Programming I version 1.5.3
Programming I C Library
Loading...
Searching...
No Matches
Data Structures | Typedefs | Enumerations | Functions
basedefs.h File Reference

Type definitions for Programming I Library. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
#include <stdbool.h>

Go to the source code of this file.

Data Structures

struct  AnyPair
 A pair of Anys. More...
 
struct  AnyTriple
 A tuple of three Anys. More...
 
struct  ByteOption
 A byte option represents either a byte or nothing. More...
 
struct  DoubleOption
 A double option represents either an double or nothing. More...
 
struct  DoublePair
 A pair of doubles. More...
 
struct  DoubleTriple
 Three doubles. More...
 
struct  IntOption
 An integer option represents either an integer or nothing. More...
 
struct  IntPair
 A pair of integers. More...
 
struct  IntTriple
 Three integers. More...
 
struct  StringOption
 A String option represents either a String or nothing. More...
 
struct  StringPair
 A pair of Strings. More...
 
struct  StringTriple
 A tuple of three Strings. More...
 

Typedefs

typedef void * Any
 Represents a pointer to an unspecified type.
 
typedef void * AnyFn
 Represents a pointer to a function of an unspecified type.
 
typedef unsigned char Byte
 A Byte represents a single byte of memory.
 
typedef struct ByteOption ByteOption
 A byte option represents either a byte or nothing.
 
typedef CmpResult(* Comparator) (ConstAny a, ConstAny b)
 A comparator is a function that take two (comparable) entities, compares them and returns a comparison result.
 
typedef const void * ConstAny
 Represents a constant pointer to an unspecified type.
 
typedef struct DoubleOption DoubleOption
 A double option represents either an double or nothing.
 
typedef struct IntOption IntOption
 An integer option represents either an integer or nothing.
 
typedef char * String
 A String is a sequence of characters.
 
typedef struct StringOption StringOption
 A String option represents either a String or nothing.
 

Enumerations

enum  CmpResult { LT = -1 , EQ = 0 , GT = 1 }
 The possible results of comparing two comparable entities a and b: More...
 

Functions

AnyPair make_any_pair (Any a, Any b)
 Creates a pair of Anys (on the stack).
 
AnyTriple make_any_triple (Any a, Any b, Any c)
 Creates a tuple of three Anys (on the stack).
 
ByteOption make_byte_none (void)
 Creates a non-present byte option (on the stack).
 
ByteOption make_byte_some (Byte some)
 Creates a byte option for some value (on the stack).
 
DoubleOption make_double_none (void)
 Creates a non-present double option (on the stack).
 
DoublePair make_double_pair (double i, double j)
 Creates a pair of doubles (on the stack).
 
DoubleOption make_double_some (double some)
 Creates a double option for some value (on the stack).
 
DoubleTriple make_double_triple (double i, double j, double k)
 Creates a pair of doubles (on the stack).
 
IntOption make_int_none (void)
 Creates a non-present integer option (on the stack).
 
IntPair make_int_pair (int i, int j)
 Creates a pair of integers (on the stack).
 
IntOption make_int_some (int some)
 Creates an integer option for some value (on the stack).
 
IntTriple make_int_triple (int i, int j, int k)
 Creates a pair of integers (on the stack).
 
StringOption make_string_none (void)
 Creates a non-present String option (on the stack).
 
StringPair make_string_pair (String a, String b)
 Creates a pair of Strings (on the stack).
 
StringOption make_string_some (String some)
 Creates a String option for some value (on the stack).
 
StringTriple make_string_triple (String a, String b, String c)
 Creates a tuple of three Strings (on the stack).
 

Detailed Description

Type definitions for Programming I Library.

Author
Michael Rohs
Date
15.10.2015, 26.09.2020, 25.09.2023

Typedef Documentation

◆ Any

typedef void* Any

Represents a pointer to an unspecified type.

A pointer to anything.

◆ AnyFn

typedef void* AnyFn

Represents a pointer to a function of an unspecified type.

◆ Byte

typedef unsigned char Byte

A Byte represents a single byte of memory.

◆ ByteOption

typedef struct ByteOption ByteOption

A byte option represents either a byte or nothing.

Option types are typically used with functions that may return a value of the given type or nothing (i.e. the return value is optional). The none member is true if the value is not present. Otherwise the value can be accessed with the some member.

Example:

ByteOption op = index_of_byte_value(array, 123); // index of value 123?
if (op.none) {
printsln("value not found");
} else {
}
void printiln(int i)
Prints an integer followed by a line break.
void printsln(String s)
Prints a String followed by a line break.
A byte option represents either a byte or nothing.
Definition basedefs.h:170
Byte some
Definition basedefs.h:172
bool none
Definition basedefs.h:171
See also
make_byte_none
make_byte_some

◆ Comparator

typedef CmpResult(* Comparator) (ConstAny a, ConstAny b)

A comparator is a function that take two (comparable) entities, compares them and returns a comparison result.

It is often used with sorting algorithms to encode the sorting criteria.

Parameters
[in]afirst entity to compare
[in]bsecond entity to compare
Returns
comparison result

◆ ConstAny

typedef const void* ConstAny

Represents a constant pointer to an unspecified type.

A variable of this type cannot be modified.

◆ DoubleOption

typedef struct DoubleOption DoubleOption

A double option represents either an double or nothing.

Option types are typically used with functions that may return a value of the given type or nothing (i.e. the return value is optional). The none member is true if the value is not present. Otherwise the value can be accessed with the some member.

Example:

DoubleOption op = index_of_double_value(array, 0.5, EPSILON); // index of value 0.5?
if (op.none) {
printsln("value not found");
} else {
}
#define EPSILON
A very small positive value.
Definition base.h:956
void printdln(double d)
Prints a double followed by a line break.
A double option represents either an double or nothing.
Definition basedefs.h:191
bool none
Definition basedefs.h:192
double some
Definition basedefs.h:193
See also
make_double_none
make_double_some

◆ IntOption

typedef struct IntOption IntOption

An integer option represents either an integer or nothing.

Option types are typically used with functions that may return a value of the given type or nothing (i.e. the return value is optional). The none member is true if the value is not present. Otherwise the value can be accessed with the some member.

Example:

IntOption op = index_of_int_value(array, 123); // index of value 123?
if (op.none) {
printsln("value not found");
} else {
}
An integer option represents either an integer or nothing.
Definition basedefs.h:149
int some
Definition basedefs.h:151
bool none
Definition basedefs.h:150
See also
make_int_none
make_int_some

◆ String

typedef char* String

A String is a sequence of characters.

◆ StringOption

typedef struct StringOption StringOption

A String option represents either a String or nothing.

Option types are typically used with functions that may return a value of the given type or nothing (i.e. the return value is optional). The none member is true if the value is not present. Otherwise the value can be accessed with the some member.

See also
make_string_none
make_string_some

Enumeration Type Documentation

◆ CmpResult

enum CmpResult

The possible results of comparing two comparable entities a and b:

  • a may be less than b (LT),
  • a may be equal to b (EQ), or
  • a may be greater than b (GT).
Enumerator
LT 
EQ 
GT 

Function Documentation

◆ make_any_pair()

AnyPair make_any_pair ( Any  a,
Any  b 
)

Creates a pair of Anys (on the stack).

Parameters
[in]afirst element
[in]bsecond element
Returns
the pair

◆ make_any_triple()

AnyTriple make_any_triple ( Any  a,
Any  b,
Any  c 
)

Creates a tuple of three Anys (on the stack).

Parameters
[in]afirst element
[in]bsecond element
[in]cthird element
Returns
the triple

◆ make_byte_none()

ByteOption make_byte_none ( void  )

Creates a non-present byte option (on the stack).

Returns
the option value

◆ make_byte_some()

ByteOption make_byte_some ( Byte  some)

Creates a byte option for some value (on the stack).

Parameters
[in]somesome value
Returns
the option value

◆ make_double_none()

DoubleOption make_double_none ( void  )

Creates a non-present double option (on the stack).

Returns
the option value

◆ make_double_pair()

DoublePair make_double_pair ( double  i,
double  j 
)

Creates a pair of doubles (on the stack).

Parameters
[in]ifirst element
[in]jsecond element
Returns
the pair

◆ make_double_some()

DoubleOption make_double_some ( double  some)

Creates a double option for some value (on the stack).

Parameters
[in]somesome value
Returns
the option value

◆ make_double_triple()

DoubleTriple make_double_triple ( double  i,
double  j,
double  k 
)

Creates a pair of doubles (on the stack).

Parameters
[in]ifirst element
[in]jsecond element
[in]kthird element
Returns
the triple

◆ make_int_none()

IntOption make_int_none ( void  )

Creates a non-present integer option (on the stack).

Returns
the option value

◆ make_int_pair()

IntPair make_int_pair ( int  i,
int  j 
)

Creates a pair of integers (on the stack).

Parameters
[in]ifirst element
[in]jsecond element
Returns
the pair

◆ make_int_some()

IntOption make_int_some ( int  some)

Creates an integer option for some value (on the stack).

Parameters
[in]somesome value
Returns
the option value

◆ make_int_triple()

IntTriple make_int_triple ( int  i,
int  j,
int  k 
)

Creates a pair of integers (on the stack).

Parameters
[in]ifirst element
[in]jsecond element
[in]kthird element
Returns
the triple

◆ make_string_none()

StringOption make_string_none ( void  )

Creates a non-present String option (on the stack).

Returns
the option value

◆ make_string_pair()

StringPair make_string_pair ( String  a,
String  b 
)

Creates a pair of Strings (on the stack).

Parameters
[in]afirst element
[in]bsecond element
Returns
the pair

◆ make_string_some()

StringOption make_string_some ( String  some)

Creates a String option for some value (on the stack).

Parameters
[in]somesome value
Returns
the option value

◆ make_string_triple()

StringTriple make_string_triple ( String  a,
String  b,
String  c 
)

Creates a tuple of three Strings (on the stack).

Parameters
[in]afirst element
[in]bsecond element
[in]cthird element
Returns
the triple