rego-cpp 1.0.0
A C++ implementation of the Rego language and runtime
Loading...
Searching...
No Matches
rego::BundleDef Struct Reference

Represents a compiled Rego bundle. More...

#include <rego.hh>

Public Member Functions

std::optional< size_t > find_plan (const Location &name) const
 Finds a plan by name.
 
std::optional< size_t > find_function (const Location &name) const
 Finds a function by name.
 
bool is_function (const Location &name) const
 Determines whether the provided name refers to a function.
 
void save (std::ostream &stream) const
 Saves the bundle to a stream.
 
void save (const std::filesystem::path &path) const
 Saves the bundle to a file.
 

Static Public Member Functions

static Bundle from_node (Node bundle)
 Constructs a bundle from an AST node.
 
static Bundle load (std::istream &stream)
 Loads a bundle from a stream.
 
static Bundle load (const std::filesystem::path &path)
 Loads a bundle from a file.
 

Public Attributes

Node data
 The merged base data document.
 
std::map< Location, Node > builtin_functions
 The built-in functions required by the bundle.
 
std::map< Location, size_t > name_to_func
 Map from plan names to their indices.
 
std::map< Location, size_t > name_to_plan
 Map from function names to their indices.
 
std::vector< bundle::Planplans
 The plans in the bundle.
 
std::vector< bundle::Functionfunctions
 The functions in the bundle.
 
std::vector< Location > strings
 The string table for the bundle.
 
std::vector< Source > files
 The module source files which were compiled into the bundle.
 
size_t local_count
 The number of local variables required by the bundle.
 
std::optional< size_t > query_plan
 The index of the query plan, if one was included.
 
Source query
 The query, if one was included.
 

Detailed Description

Represents a compiled Rego bundle.

Member Function Documentation

◆ find_function()

std::optional< size_t > rego::BundleDef::find_function ( const Location & name) const

Finds a function by name.

Parameters
nameThe name of the function to find.
Returns
The index of the function if found, otherwise std::nullopt.

◆ find_plan()

std::optional< size_t > rego::BundleDef::find_plan ( const Location & name) const

Finds a plan by name.

Parameters
nameThe name of the plan to find.
Returns
The index of the plan if found, otherwise std::nullopt.

◆ from_node()

static Bundle rego::BundleDef::from_node ( Node bundle)
static

Constructs a bundle from an AST node.

The node provided must adhere to the wf_bundle well-formedness definition. Typically, this node is produced by the Interpreter method build.

Parameters
bundleThe AST node representing the bundle.
Returns
The bundle.

◆ is_function()

bool rego::BundleDef::is_function ( const Location & name) const

Determines whether the provided name refers to a function.

Parameters
nameThe name to check.
Returns
True if the name refers to a function, otherwise false.

◆ load() [1/2]

static Bundle rego::BundleDef::load ( const std::filesystem::path & path)
static

Loads a bundle from a file.

The bundle is expected to be in Rego Bundle Binary format. To learn more about this format, see the specification.

Parameters
pathThe path to the file to load from.
Returns
The bundle, or null if the bundle could not be loaded.

◆ load() [2/2]

static Bundle rego::BundleDef::load ( std::istream & stream)
static

Loads a bundle from a stream.

The bundle is expected to be in Rego Bundle Binary format. To learn more about this format, see the specification.

Parameters
streamThe stream to load from.
Returns
The bundle, or null if the bundle could not be loaded.

◆ save() [1/2]

void rego::BundleDef::save ( const std::filesystem::path & path) const

Saves the bundle to a file.

The bundle is saved in Rego Bundle Binary format. To learn more about this format, see the specification.

Parameters
pathThe path to the file to save to.

◆ save() [2/2]

void rego::BundleDef::save ( std::ostream & stream) const

Saves the bundle to a stream.

The bundle is saved in Rego Bundle Binary format. To learn more about this format, see the specification.

Parameters
streamThe stream to save to.

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