libabacus/include/basetype.h

68 lines
1.8 KiB
C
Raw Normal View History

#ifndef LIBABACUS_BASETYPE_H
#define LIBABACUS_BASETYPE_H
#include "result.h"
2018-04-21 14:09:01 -07:00
#include "vec.h"
/**
* An enum that represents the various
* types of the basetype parameters.
*/
2018-04-21 14:09:01 -07:00
enum libab_basetype_variant_e { BT_NAME, BT_LIST };
/**
* A struct that holds information about the basetype
* parameter, such as a type name or a "..." (called a list).
*/
struct libab_basetype_param_s {
/**
* The variant of this type parameter.
*/
enum libab_basetype_variant_e variant;
/**
* The name of the parameter, if one is appropriate.
*/
const char* name;
};
/**
* A struct that holds all the information about a base type.
*/
struct libab_basetype_s {
/**
* The function used to free the value.
*/
void (*free_function)(void*);
/**
* The parameters of the type. This is a constant array, and
* doesn't need memory allocation.
*/
const struct libab_basetype_param_s* params;
/**
* The size of the param aray.
*/
int count;
};
typedef enum libab_basetype_variant_e libab_basetype_variant;
typedef struct libab_basetype_param_s libab_basetype_param;
typedef struct libab_basetype_s libab_basetype;
/**
* Initializes a base type, including all the parameters that it needs
* to take.
* @param basetype the type that is being initialized.
2018-05-17 15:33:38 -07:00
* @param free_function to function used to free the data in this basetype.
* @param n the number of type parameters it has.
* @param params the parameters this basetype accepts.
*/
2018-05-17 14:53:48 -07:00
void libab_basetype_init(libab_basetype* basetype, void (*free_function)(void*),
int n, const libab_basetype_param params[]);
/**
* Frees the given basetype.
* @param basetype the type to free.
*/
void libab_basetype_free(libab_basetype* basetype);
#endif