update HasReturnvaluesIF

1. Add new retval namespace which contains OK and FAIL returnvalue
2. Also contains makeCode constexpr function
3. Mark HasReturnvaluesIF::makeReturnCode deprecated

This prevents from having to implement an interface just to use a shorter
version of the general returnvalues. A namespace is better suited for this
I think
This commit is contained in:
Robin Müller 2022-07-26 10:22:05 +02:00
parent f11433e50f
commit b827bd8370
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC

View File

@ -10,11 +10,21 @@
#define MAKE_RETURN_CODE(number) ((INTERFACE_ID << 8) + (number))
typedef uint16_t ReturnValue_t;
namespace retval {
static constexpr ReturnValue_t OK = 0;
static constexpr ReturnValue_t FAILED = 1;
static constexpr ReturnValue_t makeCode(uint8_t classId, uint8_t number) {
return (static_cast<ReturnValue_t>(classId) << 8) + number;
}
} // namespace retval
class HasReturnvaluesIF {
public:
static const ReturnValue_t RETURN_OK = 0;
static const ReturnValue_t RETURN_FAILED = 1;
virtual ~HasReturnvaluesIF() {}
static const ReturnValue_t RETURN_OK = retval::OK;
static const ReturnValue_t RETURN_FAILED = retval::FAILED;
virtual ~HasReturnvaluesIF() = default;
/**
* It is discouraged to use the input parameters 0,0 and 0,1 as this
@ -23,8 +33,9 @@ class HasReturnvaluesIF {
* @param number
* @return
*/
static constexpr ReturnValue_t makeReturnCode(uint8_t classId, uint8_t number) {
return (static_cast<ReturnValue_t>(classId) << 8) + number;
[[deprecated("Use retval::makeCode instead")]] static constexpr ReturnValue_t makeReturnCode(
uint8_t classId, uint8_t number) {
return retval::makeCode(classId, number);
}
};