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