Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,12 @@ if(flow-ui_INSTALL)

write_basic_package_version_file(${PROJECT_NAME}ConfigVersion.cmake COMPATIBILITY SameMajorVersion)
endif()

# -----------------------------------------------------------------------------
# Examples
# -----------------------------------------------------------------------------

option(BUILD_EXAMPLES OFF)
if (BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(simple_module)
22 changes: 22 additions & 0 deletions examples/simple_module/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.10)

project(simple_module VERSION 1.0.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(APPLE)
enable_language(OBJC)
endif()

add_library(${PROJECT_NAME} SHARED src/register.cpp)
target_compile_definitions(${PROJECT_NAME} PRIVATE FLOW_SIMPLE_EXPORT)

if(MSVC)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
target_compile_options(${PROJECT_NAME} PRIVATE /W4)
endif()

add_dependencies(${PROJECT_NAME} flow-core)
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(${PROJECT_NAME} PUBLIC flow-core)
54 changes: 54 additions & 0 deletions examples/simple_module/include/Example.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) 2024,Cisco Systems, Inc.
// All rights reserved.

#pragma once

#include <flow/core/Node.hpp>
#include <flow/core/NodeData.hpp>

#include <string>

namespace flow::simple
{
class ExampleNode : public Node
{
public:
explicit ExampleNode(const std::string& uuid_str, const std::string& name, std::shared_ptr<Env> env)
: Node(uuid_str, flow::TypeName_v<ExampleNode>, name, std::move(env))
{
AddInput<std::string>("name", "Input name");
AddOutput<std::string>("greeting", "A greeting to the specified user");
}

virtual ~ExampleNode() = default;

protected:
void Compute() override
{
if (auto name_data = GetInputData<std::string>("name"))
{
const std::string& name = name_data->Get();
SetOutputData("greeting", flow::MakeNodeData("Hello " + name + "!"));
}
}

json SaveInputs() const override
{
if (auto name_data = GetInputData<std::string>("name"))
{
const std::string& name = name_data->Get();
return {{"name", name}};
}

return {};
}

void RestoreInputs(const json& j) override
{
if (j.contains("name"))
{
SetInputData("name", flow::MakeNodeData(j["name"].get_ref<const std::string&>()));
}
}
};
} // namespace flow::simple
29 changes: 29 additions & 0 deletions examples/simple_module/src/register.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "Example.hpp"

#include <flow/core/NodeFactory.hpp>

#ifdef FLOW_WINDOWS
#ifdef FLOW_SIMPLE_EXPORT
#define FLOW_SIMPLE_API __declspec(dllexport) FLOW_CORE_CALL
#else
#define FLOW_SIMPLE_API __declspec(dllimport) FLOW_CORE_CALL
#endif
#else
#define FLOW_SIMPLE_API
#endif

extern "C"
{
namespace flow::simple
{
void FLOW_SIMPLE_API RegisterModule(std::shared_ptr<flow::NodeFactory> factory)
{
factory->RegisterNodeClass<ExampleNode>("example", "Example");
}

void FLOW_SIMPLE_API UnregisterModule(std::shared_ptr<flow::NodeFactory> factory)
{
factory->UnregisterNodeClass<ExampleNode>("example");
}
} // namespace flow::simple
}