-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New class for return values of interface methods.
- Loading branch information
Showing
14 changed files
with
269 additions
and
24 deletions.
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/os/ReturnValue.h> | ||
|
||
using namespace yarp::os; | ||
|
||
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/os/api.h> | ||
#include <string> | ||
|
||
namespace yarp::os { | ||
|
||
class YARP_os_API yarp_ret_value | ||
{ | ||
public: | ||
enum class YARP_os_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.