2018-04-12 23:54:58 -07:00
|
|
|
#ifndef LIBABACUS_VALUE_H
|
|
|
|
#define LIBABACUS_VALUE_H
|
|
|
|
|
2018-04-17 15:49:09 -07:00
|
|
|
#include "refcount.h"
|
2018-04-21 14:09:01 -07:00
|
|
|
#include "result.h"
|
2018-04-12 23:54:58 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A struct that represents a value.
|
|
|
|
*/
|
|
|
|
struct libab_value_s {
|
|
|
|
/**
|
|
|
|
* The type of the value.
|
|
|
|
*/
|
|
|
|
libab_ref type;
|
|
|
|
/**
|
|
|
|
* The data that is specific to this value.
|
|
|
|
*/
|
2018-05-14 17:41:41 -07:00
|
|
|
libab_ref data;
|
2018-04-12 23:54:58 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct libab_value_s libab_value;
|
|
|
|
|
|
|
|
/**
|
2018-05-14 17:41:41 -07:00
|
|
|
* Initializes a new value with the given reference counted data
|
2018-04-12 23:54:58 -07:00
|
|
|
* and the given type.
|
2018-05-14 17:41:41 -07:00
|
|
|
* @param value the value to initialize.
|
2018-05-17 14:53:48 -07:00
|
|
|
* @param data the data for this value. Its refcount is decreased when the value
|
|
|
|
* is freed.
|
2018-04-12 23:54:58 -07:00
|
|
|
* @param type the type of this value.
|
|
|
|
*/
|
2018-05-14 17:41:41 -07:00
|
|
|
void libab_value_init_ref(libab_value* value, libab_ref* data, libab_ref* type);
|
|
|
|
/**
|
|
|
|
* Initializes a new value with the given raw allocated data, and a type,
|
2018-05-17 14:53:48 -07:00
|
|
|
* whose basetype's free function is used to release the data when the value is
|
|
|
|
* freed.
|
2018-05-14 17:41:41 -07:00
|
|
|
* @param value the value to initialize.
|
|
|
|
* @param data the data this value holds.
|
|
|
|
* @param type the type of this value.
|
|
|
|
* @return the result of any necessary allocations.
|
|
|
|
*/
|
2018-05-17 14:53:48 -07:00
|
|
|
libab_result libab_value_init_raw(libab_value* value, void* data,
|
|
|
|
libab_ref* type);
|
2018-04-12 23:54:58 -07:00
|
|
|
/**
|
|
|
|
* Frees the given value.
|
|
|
|
* @param value the value to free.
|
|
|
|
*/
|
|
|
|
void libab_value_free(libab_value* value);
|
|
|
|
|
|
|
|
#endif
|