-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New class for return values of interface methods. #3051
Open
randaz81
wants to merge
2
commits into
robotology:master
Choose a base branch
from
randaz81:yarp_ret_value
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
#include <yarp/dev/ReturnValue.h> | ||
|
||
using namespace yarp::dev; | ||
|
||
yarp_ret_value::yarp_ret_value() | ||
{ | ||
} | ||
|
||
yarp_ret_value::yarp_ret_value(const bool& val) | ||
{ | ||
if (val) | ||
{ | ||
value_b = return_code::return_value_ok; | ||
} | ||
else | ||
{ | ||
value_b = return_code::return_value_error_generic; | ||
} | ||
} | ||
|
||
/*/yarp_ret_value::yarp_ret_value(const yarp_ret_value& other) | ||
{ | ||
this->value_b=other.value_b; | ||
}*/ | ||
|
||
yarp_ret_value& yarp_ret_value::operator&=(const yarp_ret_value& other) | ||
{ | ||
if (other.operator bool() == true) | ||
{ | ||
return *this; | ||
} | ||
else | ||
{ | ||
value_b = return_code::return_value_error_generic; | ||
} | ||
return *this; | ||
} | ||
|
||
yarp_ret_value& yarp_ret_value::operator=(const bool& bool_val) | ||
{ | ||
if (bool_val) | ||
{ | ||
value_b = return_code::return_value_ok; | ||
} | ||
else | ||
{ | ||
value_b = return_code::return_value_error_generic; | ||
} | ||
return *this; | ||
} | ||
|
||
std::string yarp_ret_value::toString() | ||
{ | ||
switch (value_b) | ||
{ | ||
case return_code::return_value_ok: | ||
return std::string("ok"); | ||
case return_code::return_value_unitialized: | ||
return std::string("return_value_unitialized"); | ||
case return_code::return_value_error_deprecated: | ||
return std::string("return_value_error_deprecated"); | ||
case return_code::return_value_error_generic: | ||
return std::string("return_value_error_generic"); | ||
case return_code::return_value_error_method_failed: | ||
return std::string("return_value_error_method_fail"); | ||
case return_code::return_value_error_not_implemented_by_device: | ||
return std::string("return_value_error_not_implemented_by_device"); | ||
case return_code::return_value_error_nws_nwc_communication_error: | ||
return std::string("return_value_error_nws_nwc_communication_error"); | ||
default: | ||
return std::string("unknown"); | ||
} | ||
} | ||
|
||
yarp_ret_value::operator bool() const | ||
{ | ||
return value_b == return_code::return_value_ok; | ||
} | ||
|
||
yarp_ret_value::yarp_ret_value(return_code code) | ||
{ | ||
value_b = code; | ||
} | ||
|
||
bool yarp_ret_value::operator == (const return_code& code) const | ||
{ | ||
if (code == this->value_b) return true; | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT) | ||
* SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
#ifndef YARP_RET_VALUE_H | ||
#define YARP_RET_VALUE_H | ||
|
||
#include <yarp/dev/api.h> | ||
#include <string> | ||
|
||
namespace yarp::dev { | ||
|
||
class YARP_dev_API yarp_ret_value | ||
{ | ||
public: | ||
enum class YARP_dev_API return_code | ||
{ | ||
return_value_ok = 0, | ||
return_value_error_generic = 1, | ||
return_value_error_not_implemented_by_device = 2, | ||
return_value_error_nws_nwc_communication_error = 3, | ||
return_value_error_deprecated = 4, | ||
return_value_error_method_failed = 5, | ||
return_value_unitialized = 100 | ||
}; | ||
|
||
private: | ||
return_code value_b = return_code::return_value_unitialized; | ||
|
||
public: | ||
yarp_ret_value(); | ||
yarp_ret_value(const bool& val); | ||
yarp_ret_value(return_code code); | ||
yarp_ret_value(const yarp_ret_value& other) = default; | ||
yarp_ret_value& operator&=(const yarp_ret_value& other); | ||
yarp_ret_value& operator=(const bool& bool_val); | ||
bool operator == (const return_code& code) const; | ||
std::string toString(); | ||
operator bool() const; | ||
}; | ||
|
||
} | ||
|
||
#endif // YARP_RET_VALUE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: "uninitialized".
Suggestion: isn't the "return_value_" prefix a bit verbose? I'm also thinking of an overload to LogStream so that this would be possible:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a nice idea! Just give me a little more time before proceeding since we need to edit a few things more before.