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 <string>
23
#include <type_traits>
24
25
namespace
rux
{
26
32
inline
int
exit_code_for
(
const
reusex::pipeline::StageResult
&result) {
33
if
(result.
ok
)
34
return
RuxError::SUCCESS
;
35
if
(result.
invalid_input
)
36
return
RuxError::INVALID_ARGUMENT
;
37
return
RuxError::GENERIC
;
38
}
39
47
class
StageParams
{
48
nlohmann::json object_ = nlohmann::json::object();
49
50
public
:
51
template
<
typename
T>
StageParams
&
set
(
const
char
*key,
const
T &value) {
52
if
constexpr
(std::is_floating_point_v<T>)
53
object_[key] = nlohmann::json::parse(fmt::format(
"{}"
, value));
54
else
55
object_[key] = value;
56
return
*
this
;
57
}
58
62
template
<
typename
T>
63
StageParams
&
set_if
(
bool
condition,
const
char
*key,
const
T &value) {
64
return
condition ?
set
(key, value) : *
this
;
65
}
66
67
std::string
dump
()
const
{
return
object_.dump(); }
68
};
69
70
}
// namespace rux
rux::StageParams
Accumulates stage parameters as a JSON object.
Definition
stage_bridge.hpp:47
rux::StageParams::set
StageParams & set(const char *key, const T &value)
Definition
stage_bridge.hpp:51
rux::StageParams::dump
std::string dump() const
Definition
stage_bridge.hpp:67
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:63
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:25
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:32
reusex::pipeline::StageResult
Outcome of one stage execution.
Definition
stages.hpp:88
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:96
reusex::pipeline::StageResult::ok
bool ok
The stage completed and wrote its outputs.
Definition
stages.hpp:89
apps
rux
include
create
stage_bridge.hpp
Generated by
1.17.0