libabacus/include/value.h
Danila Fedorin cf3136a237 Switch values to having their data refcounted separately.
This allows for values to be "cast" and have a different type, while
still referencing the same data.
2018-05-14 17:41:41 -07:00

47 lines
1.2 KiB
C

#ifndef LIBABACUS_VALUE_H
#define LIBABACUS_VALUE_H
#include "refcount.h"
#include "result.h"
/**
* 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.
*/
libab_ref data;
};
typedef struct libab_value_s libab_value;
/**
* Initializes a new value with the given reference counted data
* and the given type.
* @param value the value to initialize.
* @param data the data for this value. Its refcount is decreased when the value is freed.
* @param type the type of this value.
*/
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,
* whose basetype's free function is used to release the data when the value is freed.
* @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.
*/
libab_result libab_value_init_raw(libab_value* value, void* data, libab_ref* type);
/**
* Frees the given value.
* @param value the value to free.
*/
void libab_value_free(libab_value* value);
#endif