12#ifndef NROS_RCLCPP_RESULT_HPP
13#define NROS_RCLCPP_RESULT_HPP
17#include "rclcpp/detail/traits.hpp"
18#if defined(NROS_CPP_STD) || (__STDC_HOSTED__ + 0)
64#if defined(__has_cpp_attribute)
65#if __has_cpp_attribute(nodiscard) >= 201603L
66#if defined(__clang__) && __cplusplus < 201703L
67#define NROS_NODISCARD __attribute__((warn_unused_result))
69#define NROS_NODISCARD [[nodiscard]]
90#ifndef NROS_CPP_DEPRECATED_MSG
91#if defined(__has_cpp_attribute)
92#if __has_cpp_attribute(deprecated)
93#define NROS_CPP_DEPRECATED_MSG(msg) [[deprecated(msg)]]
97#ifndef NROS_CPP_DEPRECATED_MSG
98#if defined(__GNUC__) || defined(__clang__)
99#define NROS_CPP_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
101#define NROS_CPP_DEPRECATED_MSG(msg)
168 "ErrorCode numbering must match rcl_ret_t (issue #229)");
205template <
typename T>
class ResultOf;
230 explicit operator bool()
const {
return ok(); }
236 int32_t
raw()
const {
return static_cast<int32_t
>(code_); }
259#define RCLCPP_TRY(expr) \
261 ::rclcpp::Result _nros_r = (expr); \
262 if (!_nros_r.ok()) return _nros_r; \
278#ifndef RCLCPP_TRY_LOG
279#if defined(NROS_CPP_STD) || (__STDC_HOSTED__ + 0)
280#define RCLCPP_TRY_LOG(file, line, expr, ret) \
281 ::fprintf(stderr, "[nros] %s:%d %s -> %d\n", (file), (line), (expr), (int)(ret))
283#define RCLCPP_TRY_LOG(file, line, expr, ret) \
284 ((void)(file), (void)(line), (void)(expr), (void)(ret))
288#define RCLCPP_TRY_RET(expr, retval) \
290 ::rclcpp::Result _nros_r = (expr); \
291 if (!_nros_r.ok()) { \
292 RCLCPP_TRY_LOG(__FILE__, __LINE__, #expr, _nros_r.raw()); \
300#define RCLCPP_CHECK(expr) \
302 ::rclcpp::Result _nros_r = (expr); \
303 if (!_nros_r.ok()) { \
304 RCLCPP_TRY_LOG(__FILE__, __LINE__, #expr, _nros_r.raw()); \
337 e.value_ = ::rclcpp::tr::forward_rvalue(
value);
348 bool ok()
const {
return ok_; }
349 explicit operator bool()
const {
return ok_; }
352 const T&
value() const& {
return value_; }
353 T&&
value() && { return ::rclcpp::tr::forward_rvalue(value_); }
386#if defined(NROS_CPP_STD)
396class StatementResult :
public ::rclcpp::ResultOf<void> {
398 constexpr StatementResult(::rclcpp::ResultOf<void> r) : ::rclcpp::ResultOf<void>(r) {}
int32_t raw() const
Get the raw integer code (for FFI interop).
Definition result.hpp:236
bool ok() const
Returns true if the operation succeeded.
Definition result.hpp:227
constexpr ResultOf()
Default-construct a success.
Definition result.hpp:220
ErrorCode code() const
Get the underlying error code.
Definition result.hpp:233
static constexpr ResultOf success()
Named constructors.
Definition result.hpp:239
constexpr ResultOf(int32_t raw)
Construct from a raw FFI return value (int32_t).
Definition result.hpp:224
constexpr ResultOf(ErrorCode code)
Construct from a typed code.
Definition result.hpp:222
Definition result.hpp:332
T && value() &&
Definition result.hpp:353
bool ok() const
Definition result.hpp:348
T & value() &
Definition result.hpp:351
static ResultOf error(const Result &r)
Definition result.hpp:346
ErrorCode error() const
Definition result.hpp:355
static ResultOf ok(T value)
Definition result.hpp:334
Result error_as_result() const
Definition result.hpp:356
const T & value() const &
Definition result.hpp:352
static ResultOf error(ErrorCode code)
Definition result.hpp:340
Definition rclcpp.hpp:418
ErrorCode
Definition result.hpp:114
@ InvalidArgument
Null pointer, empty topic name, or out-of-range value.
Definition result.hpp:122
@ NotFound
Entity not found (topic, parameter, service…).
Definition result.hpp:124
@ Reentrant
A blocking call was made from inside a callback.
Definition result.hpp:150
@ PublishFailed
Publish failed.
Definition result.hpp:137
@ BadSequence
Operation invalid in the current state (bad call sequence).
Definition result.hpp:133
@ ServiceFailed
Service request/reply failed.
Definition result.hpp:135
@ AlreadyExists
Already exists (duplicate declare/register).
Definition result.hpp:126
@ Error
Generic failure not covered by a more specific code.
Definition result.hpp:118
@ NotInitialized
Definition result.hpp:131
@ Ok
Success.
Definition result.hpp:116
@ TransportError
Underlying zenoh-pico / DDS transport rejected the operation.
Definition result.hpp:154
@ Unsupported
Operation not implemented by the active backend.
Definition result.hpp:152
@ Full
Static pool exhausted (executor slots, subscription buffers, …).
Definition result.hpp:128
@ Timeout
Operation deadline elapsed before completion.
Definition result.hpp:120
@ Rejected
Definition result.hpp:146
@ SubscriptionFailed
Subscription create/take failed.
Definition result.hpp:139
@ TryAgain
Transient — no data ready yet (non-blocking take). Retry later.
Definition result.hpp:148
@ NotAllowed
Operation not allowed for this entity/backend.
Definition result.hpp:141
ResultOf< void > Result
Definition result.hpp:247
#define NROS_NODISCARD
Definition result.hpp:75