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

Runtime node instantiation and validation facility (builders + config/metadata schemas). More...

#include <dfx-graph/NodeFactory.hpp>

Public Types

using NodeBuilder = std::move_only_function<dfx::Core::NodePtr (Core::Node::Id, std::string)>
 Callable used to build a node instance for a given type.

Public Member Functions

 NodeFactory ()
 Construct the factory and register built-in node types.
 ENABLE_DEFAULT_MOVE_DISABLE_COPY (NodeFactory)
 Move is allowed, copy is disabled.
bool hasBuilderForType (std::string_view type) const noexcept
 Check whether a node type is registered.
std::vector< std::string > allNodeType () const
 List all registered node types.
bool isConfigValidForType (std::string_view type, nlohmann::json const &config, std::vector< std::string > *errors=nullptr) const
 Validate a configuration object against the schema of a given node type.
nlohmann::json getSchemaOfType (std::string_view type) const
 Get the JSON schema associated with a node type configuration.
nlohmann::json getMetadataOfType (std::string_view type) const
 Get the metadata JSON associated with a node type.
Core::NodePtr create (std::string_view type, Core::Node::Id id, std::string_view name, nlohmann::json config={})
 Create a node instance of the given type and apply its configuration.

Detailed Description

Runtime node instantiation and validation facility (builders + config/metadata schemas).

NodeFactory is the central registry used by the graph layer to create nodes from a string type (typically coming from .dfx graph files or runtime control commands).

It combines three responsibilities:

  • Type registry: maps a node type name to a callable NodeBuilder.
  • Configuration validation: validates a node config JSON against the schema declared for that type.
  • Metadata exposure: stores and exposes per-type metadata JSON (UI/description/categories/icons…), validated against a metadata schema.

The factory is used by dfx::Graph::Controller to materialize nodes during graph creation and runtime graph mutations.

Builders
Builders create a node instance with the signature:
dfx::Core::NodePtr builder(Core::Node::Id id, std::string name);
uint32_t Id
Node identifier type (unique and stable within a graph instance).
Definition Node.hpp:113
std::shared_ptr< Node > NodePtr
Shared ownership pointer type for Nodes..
Definition Node.hpp:61
Note
Builder contract Builders are responsible for constructing the node object. Additional initialization (most notably applying JSON configuration) is performed by the factory.
Schemas
NodeFactory maintains two independent validators:
  • one that validates per-type node configuration JSON.
  • and another one that validates per-type metadata JSON (intended for tooling / UI).

This allows the runtime to reject invalid graph files early (wrong config shape) and to keep node metadata consistent (useful for editors like dfx-gui).

Member Typedef Documentation

◆ NodeBuilder

using dfx::Graph::NodeFactory::NodeBuilder = std::move_only_function<dfx::Core::NodePtr (Core::Node::Id, std::string)>

Callable used to build a node instance for a given type.

The builder receives the allocated node id and the node name and must return a fully constructed node instance.

Constructor & Destructor Documentation

◆ NodeFactory()

dfx::Graph::NodeFactory::NodeFactory ( )

Construct the factory and register built-in node types.

The constructor is responsible for populating:

  • the builder registry,
  • the per-type configuration schemas,
  • the per-type metadata.

It is currently not possible to add node type at runtime but this capability may be added through plugins in the future.

Member Function Documentation

◆ allNodeType()

std::vector< std::string > dfx::Graph::NodeFactory::allNodeType ( ) const

List all registered node types.

◆ create()

Core::NodePtr dfx::Graph::NodeFactory::create ( std::string_view type,
Core::Node::Id id,
std::string_view name,
nlohmann::json config = {} )

Create a node instance of the given type and apply its configuration.

This is the main entry point used by dfx::Graph::Controller when instantiating nodes from graph files or runtime mutations.

Parameters
typeNode type name.
idNode identifier (typically allocated by the graph controller).
nameNode name.
configOptional configuration JSON (defaults to {}).
Returns
The created node instance.
Exceptions
dfx::Utils::ExceptionThrown if:
  • the type is unknown (no builder),
  • config validation fails,
  • the builder fails to construct the node,
  • initialization/config application fails.

◆ ENABLE_DEFAULT_MOVE_DISABLE_COPY()

dfx::Graph::NodeFactory::ENABLE_DEFAULT_MOVE_DISABLE_COPY ( NodeFactory )

Move is allowed, copy is disabled.

◆ getMetadataOfType()

nlohmann::json dfx::Graph::NodeFactory::getMetadataOfType ( std::string_view type) const

Get the metadata JSON associated with a node type.

Metadata is intended for presentation and tooling (categories, descriptions, icons, etc.). It is validated against the internal metadata schema at registration time.

Parameters
typeNode type name.
Returns
Metadata JSON for this type.
Exceptions
dfx::Utils::ExceptionIf type is not registered

◆ getSchemaOfType()

nlohmann::json dfx::Graph::NodeFactory::getSchemaOfType ( std::string_view type) const

Get the JSON schema associated with a node type configuration.

This is primarily intended for tooling (e.g. GUI editors, CLI introspection).

Parameters
typeNode type name.
Returns
Schema JSON for this type.
Exceptions
dfx::Utils::ExceptionIf type is not registered

◆ hasBuilderForType()

bool dfx::Graph::NodeFactory::hasBuilderForType ( std::string_view type) const
inlinenoexcept

Check whether a node type is registered.

Parameters
typeNode type name.
Returns
True if a builder exists for this type.

◆ isConfigValidForType()

bool dfx::Graph::NodeFactory::isConfigValidForType ( std::string_view type,
nlohmann::json const & config,
std::vector< std::string > * errors = nullptr ) const

Validate a configuration object against the schema of a given node type.

This validates the shape of config according to the registered schema for type. If errors is null, invalid configs are still detected (false return) but the caller does not get detailed diagnostics from this function.

Parameters
typeNode type name.
configConfiguration JSON to validate.
errorsOptional output list of human-readable validation errors.
Return values
trueConfiguration is valid for this type.
falseConfiguration is invalid (and errors is populated when provided).
Exceptions
dfx::Utils::ExceptionIf type is not registered

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