Hyperon C
Loading...
Searching...
No Matches
space_api_t Struct Reference

A table of functions to define the behavior of a Space implemented in C. More...

#include <hyperon.h>

Public Attributes

struct bindings_set_t(* query )(const struct space_params_t *params, const atom_ref_t *atom)
 Performs a query against atoms in a space.
struct atom_vec_t(* subst )(const struct space_params_t *params, const atom_ref_t *pattern, const atom_ref_t *tmpl)
 Substitutes atoms matched by a query with atoms in a form derived from a template.
void(* add )(const struct space_params_t *params, atom_t atom)
 Adds an atom to the space.
bool(* remove )(const struct space_params_t *params, const atom_ref_t *atom)
 Removes an atom from the space.
bool(* replace )(const struct space_params_t *params, const atom_ref_t *from, atom_t to)
 Replaces one atom in the space with another.
intptr_t(* atom_count )(const struct space_params_t *params)
 Returns the number of atoms contained within the space.
void *(* new_atom_iterator_state )(const struct space_params_t *params)
 Initializes state necessary to perform an iteration over all top-level atoms.
atom_ref_t(* next_atom )(const struct space_params_t *params, void *state)
 Advances to the next top-level atom in the iteration sequence of the Space.
void(* free_atom_iterator_state )(const struct space_params_t *params, void *state)
 Frees the iterator state allocated by new_atom_iterator_state
void(* free_payload )(void *payload)
 Frees the payload buffer passed when the space was created.

Detailed Description

A table of functions to define the behavior of a Space implemented in C.

See also
space_new

Member Data Documentation

◆ add

void(* space_api_t::add) (const struct space_params_t *params, atom_t atom)

Adds an atom to the space.

Parameters
[in]paramsA pointer to the space's params
[in]atomAn atom_t representing the atom to add to the space
See also
space_add
Note
This function must take ownership responsibility for the provided atom, and ultimately free it when the space is freed

◆ atom_count

intptr_t(* space_api_t::atom_count) (const struct space_params_t *params)

Returns the number of atoms contained within the space.

Parameters
[in]paramsA pointer to the space's params
Returns
The number of top-level atoms contained within the Space
See also
space_atom_count
Note
If an atom_count function is provided, it will be called. NULL should be provided for spaces that cannot readily determine the number of contained atoms

◆ free_atom_iterator_state

void(* space_api_t::free_atom_iterator_state) (const struct space_params_t *params, void *state)

Frees the iterator state allocated by new_atom_iterator_state

Parameters
[in]paramsA pointer to the space's params
[in]stateA pointer to the iteration state allocated by new_atom_iterator_state()
See also
space_iterate
Note
This function is optional for Spaces that don't support iteration. However, if a new_atom_iterator_state implementation is provided then free_atom_iterator_state must also be provided

◆ free_payload

void(* space_api_t::free_payload) (void *payload)

Frees the payload buffer passed when the space was created.

Parameters
[in]payloadThe pointer to the space's payload
See also
space_new
Note
This function is responsible for freeing the payload buffer, as well as any other objects and resources stored by the space. This includes freeing all atom_t objects and other buffers, as well as closing any connections and releasing any other resources held by the Space

◆ new_atom_iterator_state

void *(* space_api_t::new_atom_iterator_state) (const struct space_params_t *params)

Initializes state necessary to perform an iteration over all top-level atoms.

Parameters
[in]paramsA pointer to the space's params
Returns
A pointer to an allocated "iterator state" object storing the necessary information to iterate each top-level atom contained within the space
See also
space_iterate
Note
If an new_atom_iterator_state function is provided, it will be called. NULL should be provided for spaces that cannot iterate all top-level atoms in an orderly way

◆ next_atom

atom_ref_t(* space_api_t::next_atom) (const struct space_params_t *params, void *state)

Advances to the next top-level atom in the iteration sequence of the Space.

Parameters
[in]paramsA pointer to the space's params
[in]stateA pointer to the iteration state allocated by new_atom_iterator_state()
Returns
A reference to an atom owned by the space, or a null atom_ref_t to signal the iteration has finished
See also
space_iterate
Note
This function is optional for Spaces that don't support iteration. However, if a new_atom_iterator_state implementation is provided then next_atom must also be provided

◆ query

struct bindings_set_t(* space_api_t::query) (const struct space_params_t *params, const atom_ref_t *atom)

Performs a query against atoms in a space.

Parameters
[in]paramsA pointer to the space's params
[in]atomA pointer to the query atom
Returns
A bindings_set_t representing the query results
See also
space_query

◆ remove

bool(* space_api_t::remove) (const struct space_params_t *params, const atom_ref_t *atom)

Removes an atom from the space.

Parameters
[in]paramsA pointer to the space's params
[in]atomA pointer to an atom_ref_t or atom_t to specify which atom to remove from the space
Returns
true if the atom was removed, otherwise returns false
See also
space_remove
Warning
This function should NOT take ownership of the atom argument

◆ replace

bool(* space_api_t::replace) (const struct space_params_t *params, const atom_ref_t *from, atom_t to)

Replaces one atom in the space with another.

Parameters
[in]paramsA pointer to the space's params
[in]fromA pointer to an atom_ref_t or atom_t to specify the existing atom to replace in the space
[in]toAn atom_t representing the atom to add to the space
Returns
true if the atom was replaced, otherwise returns false
See also
space_replace
Warning
This function should NOT take ownership of the atom argument, but this function SHOULD take ownership of the to atom

◆ subst

struct atom_vec_t(* space_api_t::subst) (const struct space_params_t *params, const atom_ref_t *pattern, const atom_ref_t *tmpl)

Substitutes atoms matched by a query with atoms in a form derived from a template.

Parameters
[in]paramsA pointer to the space's params
[in]patternA pointer to the the pattern atom to match
[in]tmplA pointer to the the template atom from which to construct the substituted atoms
Returns
An atom_vec_t containing all newly created atoms from the substitution
See also
space_subst
Note
If a subst function is provided, it will be called. If NULL is provided, the default implementation will be called.

The documentation for this struct was generated from the following file: