dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
dfx::Graph::Loader Class Reference

Helper that loads a graph into a Controller from a JSON file or JSON object. More...

#include <dfx-graph/Loader.hpp>

Static Public Member Functions

static LoadingResult loadFromFile (fs::path const &path, Controller &controller, LoaderOptions const &options={})
 Load a graph JSON file into a controller.
static LoadingResult loadFromJson (nlohmann::json const &json, Controller &controller, LoaderOptions const &options={})
 Load a graph from an in-memory JSON object into a controller.

Detailed Description

Helper that loads a graph into a Controller from a JSON file or JSON object.

Loader builds graph content (nodes and channels) into an existing dfx::Graph::Controller.

The loader is designed to be all-or-nothing for the objects it creates:

  • if any node or channel fails to be created/validated, then every node created during that load call is immediately removed from the controller;
  • nodes and channels that were already present in the controller before the call are left untouched.

This behavior prevents "partial loads" where the controller ends up in a half-built state.

Input format
The JSON document is validated against the graph JSON schema before any mutations occur. The loader expects at least:
  • nodes: array of objects containing name, type, and optional config
  • channels: array of objects containing from and to

Channels are specified using the string form:

  • "<node>.<port>"

where the from side must reference an output port and the to side must reference an input port.

Channel verification
Channels are created through dfx::Graph::Controller::addChannel(). The loader forwards LoaderOptions::errorLimit as the controller’s errorLimit argument.

Since the loader does not collect errors itself, a verification failure will result in an exception from the controller path.

Starting nodes
If LoaderOptions::startNodes is true, the loader will start each newly created node after all nodes and channels have been created successfully.
Warning
This helper does not attempt to update existing nodes or reconcile conflicts. If a node name already exists (or a node type is unknown), loading fails and all nodes created during the call are rolled back.

Member Function Documentation

◆ loadFromFile()

LoadingResult dfx::Graph::Loader::loadFromFile ( fs::path const & path,
Controller & controller,
LoaderOptions const & options = {} )
static

Load a graph JSON file into a controller.

This function reads the file, parses it as JSON, and delegates to loadFromJson().

Parameters
pathPath to the .dfx JSON file.
controllerTarget controller to mutate.
optionsLoader options (rollback behavior is always enabled).
Returns
Id lists of nodes/channels created during this call.

◆ loadFromJson()

LoadingResult dfx::Graph::Loader::loadFromJson ( nlohmann::json const & json,
Controller & controller,
LoaderOptions const & options = {} )
static

Load a graph from an in-memory JSON object into a controller.

Implementation notes (behavioral contract):

  • Validates json against the graph schema before mutating the controller.
  • Creates all nodes first, then creates all channels.
  • Channel endpoints are parsed from "<node>.<port>" strings.
  • On failure at any stage, removes all nodes created during this call (removing a node also removes its channels, so channels do not need explicit rollback).
Parameters
jsonJSON graph document (validated against the graph schema).
controllerTarget controller to mutate.
optionsLoader options (rollback behavior is always enabled).
Returns
Id lists of nodes/channels created during this call.

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