ReUseX  0.0.5
3D Point Cloud Processing for Building Reuse
Loading...
Searching...
No Matches
stage_bridge.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Povl Filip Sonne-Frederiksen
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#pragma once
6
7// Shared glue between the `rux create <stage>` subcommands and the library's
8// pipeline::run_stage (#284).
9//
10// The stage bodies themselves live in libs/reusex/src/pipeline/stages.cpp and
11// exist exactly once. What stays here is the part that is genuinely the CLI's
12// job: turning parsed flags into a parameter blob, and turning the library's
13// outcome back into a process exit code.
14
15#include "../global-params.hpp"
16
17#include <reusex/pipeline/stages.hpp>
18
19#include <fmt/format.h>
20#include <nlohmann/json.hpp>
21
22#include <functional>
23#include <string>
24#include <string_view>
25#include <type_traits>
26
27namespace rux {
28
35 if (result.ok)
36 return RuxError::SUCCESS;
37 if (result.invalid_input)
39 return RuxError::GENERIC;
40}
41
50 nlohmann::json object_ = nlohmann::json::object();
51
52 public:
53 template <typename T> StageParams &set(const char *key, const T &value) {
54 if constexpr (std::is_floating_point_v<T>)
55 object_[key] = nlohmann::json::parse(fmt::format("{}", value));
56 else
57 object_[key] = value;
58 return *this;
59 }
60
64 template <typename T>
65 StageParams &set_if(bool condition, const char *key, const T &value) {
66 return condition ? set(key, value) : *this;
67 }
68
69 std::string dump() const { return object_.dump(); }
70};
71
74 std::function<void(std::string_view stage, const std::string &params)>;
75
83
86bool capture_stage_params(std::string_view stage, const std::string &params);
87
88} // namespace rux
Accumulates stage parameters as a JSON object.
StageParams & set(const char *key, const T &value)
std::string dump() const
StageParams & set_if(bool condition, const char *key, const T &value)
Set key only when condition holds.
@ INVALID_ARGUMENT
@ GENERIC
@ SUCCESS
bool capture_stage_params(std::string_view stage, const std::string &params)
Called by each stage subcommand before it runs: true when a sink took params (the subcommand must the...
int exit_code_for(const reusex::pipeline::StageResult &result)
Map a library stage outcome onto a rux exit code.
std::function< void(std::string_view stage, const std::string &params)> StageParamsSink
Receives a subcommand's stage parameters instead of running the stage.
void set_stage_params_sink(StageParamsSink sink)
Test seam for "KopiƩr som rux-kommando" (Qt client): while a sink is set, rux create clouds|planes|ro...
Outcome of one stage execution.
Definition stages.hpp:92
bool invalid_input
The request was refused before/without doing the work because an input or a parameter was invalid,...
Definition stages.hpp:100
bool ok
The stage completed and wrote its outputs.
Definition stages.hpp:93