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#include <yarp/os/Vocab.h>
13
14#if __cplusplus >= 202002L
15#include <source_location>
16#endif
17
18#include <string>
19
20// If this macro is enabled (default value=enabled), a bool value cannot be automatically converted to ReturnValue.
21// Automatic conversions of this type should be generally avoided, because they make the code less clear.
22// It is thus preferable that user assigns a precise value to a ReturnValue.
23#define YARP_RETURNVALUE_DISABLE_BOOL_INPUT 1
24
25// If this macro is enabled (default value=disabled), a ReturnValue cannot be automatically converted to bool
26// unless explicitly requested using the bool() operator.
27// The following macro is used for testing/development purposes only.
28// If enabled, it will break backward compatibility with user-application code.
29#define YARP_RETURNVALUE_DISABLE_BOOL_OUTPUT 0
30
31namespace yarp::dev {
32
34{
35 public:
37 {
38
39 return_value_ok = yarp::os::createVocab32('o','k'),
40 return_value_error_generic = yarp::os::createVocab32('e', 'r', 'r', '1'),
41 return_value_error_not_implemented_by_device = yarp::os::createVocab32('e', 'r', 'r', '2'),
42 return_value_error_nws_nwc_communication_error = yarp::os::createVocab32('e', 'r', 'r', '3'),
43 return_value_error_deprecated = yarp::os::createVocab32('e', 'r', 'r', '4'),
44 return_value_error_method_failed = yarp::os::createVocab32('e', 'r', 'r', '5'),
45 return_value_error_not_ready = yarp::os::createVocab32('e', 'r', 'r', '6'),
46 return_value_uninitialized = yarp::os::createVocab32('m', 'i', 's', 's')
47 };
48
49 private:
50 return_code value_b = return_code::return_value_uninitialized;
51
52 public:
54 ~ReturnValue() = default;
55#if !YARP_RETURNVALUE_DISABLE_BOOL_INPUT
56 ReturnValue(const bool& val);
57#endif
59 ReturnValue(const ReturnValue& other) = default;
60 ReturnValue& operator && (const ReturnValue& other);
61 ReturnValue& operator &= (const ReturnValue& other);
62#if !YARP_RETURNVALUE_DISABLE_BOOL_INPUT
63 ReturnValue& operator=(const bool& bool_val);
64#endif
65 bool operator == (const return_code& code) const;
66 bool operator == (const ReturnValue& value) const;
67 std::string toString();
68#if !YARP_RETURNVALUE_DISABLE_BOOL_OUTPUT
69 operator bool() const;
70#else
71 explicit operator bool() const;
72#endif
73
74public:
75 bool read(yarp::os::ConnectionReader& connection) override;
76 bool write(yarp::os::ConnectionWriter& connection) const override;
77};
78
79#ifndef SWIG_PREPROCESSOR_SHOULD_SKIP_THIS
80#define ReturnValue_ok ReturnValue(yarp::dev::ReturnValue::return_code::return_value_ok)
81
82#if __cplusplus >= 202002L
83inline ReturnValue YARP_METHOD_NOT_YET_IMPLEMENTED(const std::source_location& location = std::source_location::current())
84{
85 yError("Method %s not yet implemented\n", location.function_name());
87}
88inline ReturnValue YARP_METHOD_DEPRECATED(const std::source_location& location = std::source_location::current())
89{
90 yError("Method %s has been deprecated\n", location.function_name());
92}
93#else
94inline ReturnValue yarp_method_not_implemented(const char* location)
95{
96 yError("Method %s not yet implemented\n", location);
98}
99#define YARP_METHOD_NOT_YET_IMPLEMENTED() yarp_method_not_implemented(__func__)
100inline ReturnValue yarp_method_deprecated(const char* location)
101{
102 yError("Method %s has been deprecated\n", location);
104}
105#define YARP_METHOD_DEPRECATED() yarp_method_deprecated(__func__)
106#endif
107#endif // SWIG_PREPROCESSOR_SHOULD_SKIP_THIS
108
109}
110
111#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:99
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)
ReturnValue yarp_method_not_implemented(const char *location)
Definition ReturnValue.h:94
constexpr yarp::conf::vocab32_t createVocab32(char a, char b=0, char c=0, char d=0)
Create a vocab from chars.
Definition Vocab32.h:27
#define YARP_dev_API
Definition api.h:18