get_data
get_data
is how you retrieve the actual results (in a RegisterData
) from the ResultHandle
within the ExecutionData
from the Success
variant of an ExecutionResult
. The register name
provided to this function should match one that you provided to read_from
(or "ro"
if left at the default).
Definition
const struct RegisterData *get_data(const struct ResultHandle *handle, const char *name);
Safety
All inputs must be non-null. name
must be a nul-terminated string. handle
must come from the result of a non-error call to execute_on_qvm
or execute_on_qpu
. If there are no results matching the provided name
then the return value will be NULL
, make sure to check this return value.
Arguments
handle
is thehandle
attribute ofExecutionData
.name
is the name of a register you want the data from. It should correspond to a call toread_from
(or the default of"ro"
) and a QuilDECLARE
instruction.
Returns
A RegisterData
if there was data for the requested register, or NULL
if not.
Example
Executable *exe = executable_from_quil(REAL_MEMORY_PROGRAM);
read_from(exe, "first");
read_from(exe, "second");
ExecutionResult *result = execute_on_qvm(exe);
const RegisterData *first = get_data(result->success.handle, "first");
const RegisterData *second = get_data(result->success.handle, "second");
Our ExecutionResult
named result
is a Success
variant, so we can access the ExecutionData
via result->success
. We can then call get_data
with that ExecutionData
's handle
attribute and the name of a register we want to retrieve.