![]() |
dfx 0.1.0
Linux-based dynamic dataflow executor
|
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. | |
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:
The factory is used by dfx::Graph::Controller to materialize nodes during graph creation and runtime graph mutations.
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).
| 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.
| dfx::Graph::NodeFactory::NodeFactory | ( | ) |
Construct the factory and register built-in node types.
The constructor is responsible for populating:
It is currently not possible to add node type at runtime but this capability may be added through plugins in the future.
| std::vector< std::string > dfx::Graph::NodeFactory::allNodeType | ( | ) | const |
List all registered node types.
| 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.
| type | Node type name. |
| id | Node identifier (typically allocated by the graph controller). |
| name | Node name. |
| config | Optional configuration JSON (defaults to {}). |
| dfx::Utils::Exception | Thrown if:
|
| dfx::Graph::NodeFactory::ENABLE_DEFAULT_MOVE_DISABLE_COPY | ( | NodeFactory | ) |
Move is allowed, copy is disabled.
| 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.
| type | Node type name. |
| dfx::Utils::Exception | If type is not registered |
| 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).
| type | Node type name. |
| dfx::Utils::Exception | If type is not registered |
|
inlinenoexcept |
Check whether a node type is registered.
| type | Node type name. |
| 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.
| type | Node type name. |
| config | Configuration JSON to validate. |
| errors | Optional output list of human-readable validation errors. |
| true | Configuration is valid for this type. |
| false | Configuration is invalid (and errors is populated when provided). |
| dfx::Utils::Exception | If type is not registered |