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 <string>
23#include <type_traits>
24
25namespace rux {
26
33 if (result.ok)
34 return RuxError::SUCCESS;
35 if (result.invalid_input)
37 return RuxError::GENERIC;
38}
39
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
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
int exit_code_for(const reusex::pipeline::StageResult &result)
Map a library stage outcome onto a rux exit code.
Outcome of one stage execution.
Definition stages.hpp:88
bool invalid_input
The request was refused before/without doing the work because an input or a parameter was invalid,...
Definition stages.hpp:96
bool ok
The stage completed and wrote its outputs.
Definition stages.hpp:89