ReUseX
0.0.5
3D Point Cloud Processing for Building Reuse
Toggle main menu visibility
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
27
namespace
rux
{
28
34
inline
int
exit_code_for
(
const
reusex::pipeline::StageResult
&result) {
35
if
(result.
ok
)
36
return
RuxError::SUCCESS
;
37
if
(result.
invalid_input
)
38
return
RuxError::INVALID_ARGUMENT
;
39
return
RuxError::GENERIC
;
40
}
41
49
class
StageParams
{
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
73
using
StageParamsSink
=
74
std::function<void(std::string_view stage,
const
std::string ¶ms)>;
75
82
void
set_stage_params_sink
(
StageParamsSink
sink);
83
86
bool
capture_stage_params
(std::string_view stage,
const
std::string ¶ms);
87
88
}
// namespace rux
rux::StageParams
Accumulates stage parameters as a JSON object.
Definition
stage_bridge.hpp:49
rux::StageParams::set
StageParams & set(const char *key, const T &value)
Definition
stage_bridge.hpp:53
rux::StageParams::dump
std::string dump() const
Definition
stage_bridge.hpp:69
rux::StageParams::set_if
StageParams & set_if(bool condition, const char *key, const T &value)
Set key only when condition holds.
Definition
stage_bridge.hpp:65
global-params.hpp
INVALID_ARGUMENT
@ INVALID_ARGUMENT
Definition
global-params.hpp:39
GENERIC
@ GENERIC
Definition
global-params.hpp:37
SUCCESS
@ SUCCESS
Definition
global-params.hpp:36
rux
Definition
stage_bridge.hpp:27
rux::capture_stage_params
bool capture_stage_params(std::string_view stage, const std::string ¶ms)
Called by each stage subcommand before it runs: true when a sink took params (the subcommand must the...
rux::exit_code_for
int exit_code_for(const reusex::pipeline::StageResult &result)
Map a library stage outcome onto a rux exit code.
Definition
stage_bridge.hpp:34
rux::StageParamsSink
std::function< void(std::string_view stage, const std::string ¶ms)> StageParamsSink
Receives a subcommand's stage parameters instead of running the stage.
Definition
stage_bridge.hpp:73
rux::set_stage_params_sink
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...
reusex::pipeline::StageResult
Outcome of one stage execution.
Definition
stages.hpp:92
reusex::pipeline::StageResult::invalid_input
bool invalid_input
The request was refused before/without doing the work because an input or a parameter was invalid,...
Definition
stages.hpp:100
reusex::pipeline::StageResult::ok
bool ok
The stage completed and wrote its outputs.
Definition
stages.hpp:93
apps
rux
include
create
stage_bridge.hpp
Generated by
1.18.0