![]() |
rego-cpp 1.4.0
A C++ implementation of the Rego language and runtime
|
Encapsulates the output of a Rego query. More...
#include <rego.hh>
Public Member Functions | |
| Output (Node node) | |
| Constructor. | |
| bool | ok () const |
| Whether the Output is OK (i.e., has not resulted in one or more errors) | |
| Node | node () const |
| Gets the underlying node. | |
| size_t | size () const |
| Gets the number of results. | |
| Node | expressions_at (size_t index) const |
| Gets the expressions for the result at the specified index. | |
| Node | expressions () const |
| Gets the expressions for the first result. | |
| Node | binding_at (size_t index, const std::string &name) const |
| Gets the binding for the specified name at the specified result index. | |
| Node | binding (const std::string &name) const |
| Gets the binding for the specified name at the first result. | |
| const std::string & | json () const |
| Gets the JSON representation of the output. | |
| std::vector< std::string > | errors () const |
| Gets the errors in the output. | |
Encapsulates the output of a Rego query.
The Output class encapsulates the output of a Rego query. A Rego query result can be either undefined (no results), one or more errors, or one or more results. The fact that a query can result in one or more results may seem surprising. The query a = [1, 2, 3, 4]; x = a[_]; x % 2 == 0; x / 2 results in two distinct solutions:
Each result consists of a list of expressions (one for each statement in the query) and a lookup table of bindings, with assigned values for each named local. This class provides methods for accessing these value. Using the output above:
| rego::Output::Output | ( | Node | node | ) |
Constructor.
| node | A Results or ErrorSeq node. |
Gets the binding for the specified name at the first result.
| name | The name of the binding. |
Gets the binding for the specified name at the specified result index.
| index | The index of the result. |
| name | The name of the binding. |
| std::vector< std::string > rego::Output::errors | ( | ) | const |
Gets the errors in the output.
If the output is not OK, this method can be used to retrieve the error messages.
| Node rego::Output::expressions | ( | ) | const |
Gets the expressions for the first result.
Gets the expressions for the result at the specified index.
| index | The index of the result. |
| const std::string & rego::Output::json | ( | ) | const |
Gets the JSON representation of the output.
| Node rego::Output::node | ( | ) | const |
Gets the underlying node.
| bool rego::Output::ok | ( | ) | const |
| size_t rego::Output::size | ( | ) | const |
Gets the number of results.
There will be one result per solution to the query.