YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
ReturnValue.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025-2025 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef ReturnValue_H
7#define ReturnValue_H
8
9#include <yarp/dev/api.h>
10#include <yarp/os/Log.h>
11#include <yarp/os/Portable.h>
12
13#if __cplusplus >= 202002L
14#include <source_location>
15#endif
16
17#include <string>
18
19// If this macro is enabled (default value=enabled), a bool value cannot be automatically converted to ReturnValue.
20// Automatic conversions of this type should be generally avoided, because they make the code less clear.
21// It is thus preferable that user assigns a precise value to a ReturnValue.
22#define YARP_RETURNVALUE_DISABLE_BOOL_INPUT 1
23
24// If this macro is enabled (default value=disabled), a ReturnValue cannot be automatically converted to bool
25// unless explicitly requested using the bool() operator.
26// The following macro is used for testing/development purposes only.
27// If enabled, it will break backward compatibility with user-application code.
28#define YARP_RETURNVALUE_DISABLE_BOOL_OUTPUT 0
29
30namespace yarp::dev {
31
33{
34 public:
36 {
37 return_value_ok = 0,
38 return_value_error_generic = 1,
39 return_value_error_not_implemented_by_device = 2,
40 return_value_error_nws_nwc_communication_error = 3,
41 return_value_error_deprecated = 4,
42 return_value_error_method_failed = 5,
43 return_value_error_not_ready = 6,
44 return_value_uninitialized = 100
45 };
46
47 private:
48 return_code value_b = return_code::return_value_uninitialized;
49
50 public:
52 ~ReturnValue() = default;
53#if !YARP_RETURNVALUE_DISABLE_BOOL_INPUT
54 ReturnValue(const bool& val);
55#endif
57 ReturnValue(const ReturnValue& other) = default;
58 ReturnValue& operator && (const ReturnValue& other);
59 ReturnValue& operator &= (const ReturnValue& other);
60#if !YARP_RETURNVALUE_DISABLE_BOOL_INPUT
61 ReturnValue& operator=(const bool& bool_val);
62#endif
63 bool operator == (const return_code& code) const;
64 bool operator == (const ReturnValue& value) const;
65 std::string toString();
66#if !YARP_RETURNVALUE_DISABLE_BOOL_OUTPUT
67 operator bool() const;
68#else
69 explicit operator bool() const;
70#endif
71
72public:
73 bool read(yarp::os::ConnectionReader& connection) override;
74 bool write(yarp::os::ConnectionWriter& connection) const override;
75};
76
77#define ReturnValue_ok ReturnValue(yarp::dev::ReturnValue::return_code::return_value_ok)
78
79#if __cplusplus >= 202002L
80inline ReturnValue YARP_METHOD_NOT_YET_IMPLEMENTED(const std::source_location& location = std::source_location::current())
81{
82 yError("Method %s not yet implemented\n", location.function_name());
84}
85inline ReturnValue YARP_METHOD_DEPRECATED(const std::source_location& location = std::source_location::current())
86{
87 yError("Method %s has been deprecated\n", location.function_name());
89}
90#else
91inline ReturnValue yarp_method_not_implemented(const char* location)
92{
93 yError("Method %s not yet implemented\n", location);
95}
96#define YARP_METHOD_NOT_YET_IMPLEMENTED() yarp_method_not_implemented(__func__)
97inline ReturnValue yarp_method_deprecated(const char* location)
98{
99 yError("Method %s has been deprecated\n", location);
101}
102#define YARP_METHOD_DEPRECATED() yarp_method_deprecated(__func__)
103#endif
104
105
106}
107
108#endif // ReturnValue_H
bool operator==(const struct v4l2_control &left, const struct v4l2_control &right)
Definition CApiMock.h:65
std::string toString(const T &value)
convert an arbitrary type to string.
#define yError(...)
Definition Log.h:361
#define YARP_METHOD_DEPRECATED()
#define YARP_METHOD_NOT_YET_IMPLEMENTED()
Definition ReturnValue.h:96
ReturnValue(const ReturnValue &other)=default
@ return_value_error_deprecated
Command answer lost during network transmission. Status unknown.
An interface for reading from a network connection.
An interface for writing to a network connection.
This is a base class for objects that can be both read from and be written to the YARP network.
Definition Portable.h:25
For streams capable of holding different kinds of content, check what they actually have.
ReturnValue yarp_method_deprecated(const char *location)
Definition ReturnValue.h:97
ReturnValue yarp_method_not_implemented(const char *location)
Definition ReturnValue.h:91
#define YARP_dev_API
Definition api.h:18