dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
NodeFactory.hpp
1// SPDX-FileCopyrightText: 2025 Vincent Leroy
2// SPDX-License-Identifier: MIT
3//
4// This file is part of dfx.
5//
6// Licensed under the MIT License. See the LICENSE file in the project root
7// for full license information.
8
9#pragma once
10
11// Standard includes
12#include <functional>
13
14// Third-party includes
15#include <nlohmann/json.hpp>
16
17// Project includes
18#include <dfx-core/Node.hpp>
20#include <dfx-utilities/JsonValidator.hpp>
21#include <dfx-utilities/StringMap.hpp>
22
23namespace dfx::Graph
24{
60{
61public:
66 using NodeBuilder = std::move_only_function<dfx::Core::NodePtr (Core::Node::Id, std::string)>;
67
68public:
81
87 bool hasBuilderForType(std::string_view type) const noexcept
88 { return _builders.find(type) != _builders.end(); }
89
91 std::vector<std::string> allNodeType() const;
92
107 bool isConfigValidForType(std::string_view type, nlohmann::json const & config, std::vector<std::string> * errors = nullptr) const;
108
118 nlohmann::json getSchemaOfType(std::string_view type) const;
119
130 nlohmann::json getMetadataOfType(std::string_view type) const;
131
150 Core::NodePtr create(std::string_view type, Core::Node::Id id, std::string_view name, nlohmann::json config = {});
151
152private:
153 void _initNode(Core::NodePtr node, nlohmann::json config);
154
155private:
157 Utils::JsonValidator _configValidator;
158 Utils::JsonValidator _metadataValidator;
160};
161} // !namespace dfx::Core
Convenience macros to explicitly control copy and move semantics.
Base class for all runtime-executed nodes in a dfx dataflow graph.
uint32_t Id
Node identifier type (unique and stable within a graph instance).
Definition Node.hpp:113
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.
nlohmann::json getMetadataOfType(std::string_view type) const
Get the metadata JSON associated with a node type.
std::vector< std::string > allNodeType() const
List all registered node types.
bool hasBuilderForType(std::string_view type) const noexcept
Check whether a node type is registered.
Definition NodeFactory.hpp:87
ENABLE_DEFAULT_MOVE_DISABLE_COPY(NodeFactory)
Move is allowed, copy is disabled.
NodeFactory()
Construct the factory and register built-in 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.
std::move_only_function< dfx::Core::NodePtr(Core::Node::Id, std::string)> NodeBuilder
Callable used to build a node instance for a given type.
Definition NodeFactory.hpp:66
Registry of JSON Schemas with validation helpers.
Definition JsonValidator.hpp:46
std::shared_ptr< Node > NodePtr
Shared ownership pointer type for Nodes..
Definition Node.hpp:61
Definition Node.hpp:42
std::unordered_map< std::string, T, TransparentHash, TransparentEqual, Allocator > UnorderedStringMap
Convenience alias for an unordered map keyed by std::string with transparent lookup.
Definition StringMap.hpp:76