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]]
89#ifndef NROS_CPP_DEPRECATED_MSG
90#if defined(__has_cpp_attribute)
91#if __has_cpp_attribute(deprecated)
92#define NROS_CPP_DEPRECATED_MSG(msg) [[deprecated(msg)]]
96#ifndef NROS_CPP_DEPRECATED_MSG
97#if defined(__GNUC__) || defined(__clang__)
98#define NROS_CPP_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
100#define NROS_CPP_DEPRECATED_MSG(msg)
167 "ErrorCode numbering must match rcl_ret_t (issue #229)");
204template <
typename T>
class ResultOf;
226 bool ok()
const {
return code_ == ErrorCode::Ok; }
229 explicit operator bool()
const {
return ok(); }
258#define RCLCPP_TRY(expr) \
260 ::rclcpp::Result _nros_r = (expr); \
261 if (!_nros_r.ok()) return _nros_r; \
277#ifndef RCLCPP_TRY_LOG
278#if defined(NROS_CPP_STD) || (__STDC_HOSTED__ + 0)
279#define RCLCPP_TRY_LOG(file, line, expr, ret) \
280 ::fprintf(stderr, "[nros] %s:%d %s -> %d\n", (file), (line), (expr), (int)(ret))
282#define RCLCPP_TRY_LOG(file, line, expr, ret) \
283 ((void)(file), (void)(line), (void)(expr), (void)(ret))
287#define RCLCPP_TRY_RET(expr, retval) \
289 ::rclcpp::Result _nros_r = (expr); \
290 if (!_nros_r.ok()) { \
291 RCLCPP_TRY_LOG(__FILE__, __LINE__, #expr, _nros_r.raw()); \
299#define RCLCPP_CHECK(expr) \
301 ::rclcpp::Result _nros_r = (expr); \
302 if (!_nros_r.ok()) { \
303 RCLCPP_TRY_LOG(__FILE__, __LINE__, #expr, _nros_r.raw()); \
336 e.value_ = ::rclcpp::tr::forward_rvalue(value);
347 bool ok()
const {
return ok_; }
348 explicit operator bool()
const {
return ok_; }
352 T&&
value() && { return ::rclcpp::tr::forward_rvalue(value_); }
382using ::rclcpp::Result;
Definition client.hpp:129
Definition result.hpp:216
int32_t raw() const
Get the raw integer code (for FFI interop).
Definition result.hpp:235
bool ok() const
Returns true if the operation succeeded.
Definition result.hpp:226
constexpr ResultOf()
Default-construct a success.
Definition result.hpp:219
ErrorCode code() const
Get the underlying error code.
Definition result.hpp:232
static constexpr ResultOf success()
Named constructors.
Definition result.hpp:238
constexpr ResultOf(int32_t raw)
Construct from a raw FFI return value (int32_t).
Definition result.hpp:223
constexpr ResultOf(ErrorCode code)
Construct from a typed code.
Definition result.hpp:221
Definition result.hpp:331
T && value() &&
Definition result.hpp:352
bool ok() const
Definition result.hpp:347
T & value() &
Definition result.hpp:350
static ResultOf error(const Result &r)
Definition result.hpp:345
ErrorCode error() const
Definition result.hpp:354
static ResultOf ok(T value)
Definition result.hpp:333
Result error_as_result() const
Definition result.hpp:355
const T & value() const &
Definition result.hpp:351
static ResultOf error(ErrorCode code)
Definition result.hpp:339
bool ok()
Definition node.hpp:3031
ErrorCode
Definition result.hpp:113
@ InvalidArgument
Null pointer, empty topic name, or out-of-range value.
@ NotFound
Entity not found (topic, parameter, service…).
@ Reentrant
A blocking call was made from inside a callback.
@ PublishFailed
Publish failed.
@ BadSequence
Operation invalid in the current state (bad call sequence).
@ ServiceFailed
Service request/reply failed.
@ AlreadyExists
Already exists (duplicate declare/register).
@ Error
Generic failure not covered by a more specific code.
@ TransportError
Underlying zenoh-pico / DDS transport rejected the operation.
@ Unsupported
Operation not implemented by the active backend.
@ Full
Static pool exhausted (executor slots, subscription buffers, …).
@ Timeout
Operation deadline elapsed before completion.
@ SubscriptionFailed
Subscription create/take failed.
@ TryAgain
Transient — no data ready yet (non-blocking take). Retry later.
@ NotAllowed
Operation not allowed for this entity/backend.
#define NROS_NODISCARD
Definition result.hpp:75