|
| 1 | +# Getting Started with Flow Core |
| 2 | + |
| 3 | +## Basic Concepts |
| 4 | + |
| 5 | +Flow Core is built around these key concepts: |
| 6 | + |
| 7 | +- **Nodes**: Basic computation units |
| 8 | +- **Connections**: Data flow between nodes |
| 9 | +- **Graph**: Network of connected nodes |
| 10 | +- **Flow**: Complete execution sequence |
| 11 | + |
| 12 | +## Creating Your First Flow |
| 13 | + |
| 14 | +### 1. Basic Setup |
| 15 | + |
| 16 | +```cpp |
| 17 | +#include <flow/core/Env.hpp> |
| 18 | +#include <flow/core/Graph.hpp> |
| 19 | +#include <flow/core/NodeFactory.hpp> |
| 20 | + |
| 21 | +int main() { |
| 22 | + auto factory = std::make_shared<flow::NodeFactory>(); |
| 23 | + auto env = flow::Env::Create(factory); |
| 24 | + auto graph = std::make_shared<flow::Graph>("MyGraph", env); |
| 25 | + |
| 26 | + // ... |
| 27 | + |
| 28 | + return 0; |
| 29 | +} |
| 30 | +``` |
| 31 | + |
| 32 | +### 2. Creating Nodes |
| 33 | + |
| 34 | +```cpp |
| 35 | +// Create nodes via factory |
| 36 | +auto source_node = factory->CreateNode(flow::TypeName_v<NumberSourceNode>, UUID{}, "Source", env); |
| 37 | +auto processing_node = factory->CreateNode(flow::TypeName_v<MultiplyNode>, UUID{}, "Multiply", env); |
| 38 | +auto output_node = factory->CreateNode(flow::TypeName_v<PrintNode>, UUID{}, "Output", env); |
| 39 | + |
| 40 | +// Add nodes to graph |
| 41 | +graph->AddNode(source_node); |
| 42 | +graph->AddNode(processing_node); |
| 43 | +graph->AddNode(output_node); |
| 44 | +``` |
| 45 | +
|
| 46 | +### 3. Connecting Nodes |
| 47 | +
|
| 48 | +```cpp |
| 49 | +// Connect nodes to create a flow |
| 50 | +graph->ConnectNodes(source_node->ID(), "output", processing_node->ID(), "input"); |
| 51 | +graph->ConnectNodes(processing_node->ID(), "output", output_node->ID(), "input"); |
| 52 | +
|
| 53 | +// Start the flow |
| 54 | +graph->Run(); |
| 55 | +``` |
| 56 | + |
| 57 | +## Building Custom Nodes |
| 58 | + |
| 59 | +### 1. Define Node Class |
| 60 | + |
| 61 | +```cpp |
| 62 | +// filepath: custom_node.hpp |
| 63 | + |
| 64 | +class CustomNode : public flow::Node |
| 65 | +{ |
| 66 | + public: |
| 67 | + CustomNode(const UUID& uuid, std::string_view class_name, std::string_view name, std::shared_ptr<Env> env) |
| 68 | + : Node(uuid, class_name, name, std::move(env)) |
| 69 | + { |
| 70 | + // Add inputs and outputs |
| 71 | + } |
| 72 | + |
| 73 | + virtual ~CustomNode() = default; |
| 74 | + |
| 75 | + void Compute() override |
| 76 | + { |
| 77 | + // Your computation logic |
| 78 | + } |
| 79 | +}; |
| 80 | +``` |
| 81 | + |
| 82 | +### 2. Register Node |
| 83 | + |
| 84 | +```cpp |
| 85 | +factory->RegisterNodeClass<CustomNode>("Custom Category", "Custom Node"); |
| 86 | +``` |
| 87 | + |
| 88 | +## Best Practices |
| 89 | + |
| 90 | +1. **Type Safety** |
| 91 | + |
| 92 | + - Always use proper type checking |
| 93 | + - Validate inputs before processing |
| 94 | + |
| 95 | +2. **Performance** |
| 96 | + |
| 97 | + - Minimize allocations in Compute() methods |
| 98 | + - Use thread-safe operations when needed |
| 99 | + |
| 100 | +3. **Testing** |
| 101 | + - Write unit tests for custom nodes |
| 102 | + - Test edge cases and error conditions |
0 commit comments