Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita9cc59b

Browse files
Introducing ReturnValue
The objective of ReturnValue is to maintain coherency with ErrorCodeclass in cases where a single value is used to represent both the errorand the return value
1 parentc2c4b20 commita9cc59b

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

‎api/ErrorCodes.h‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,38 @@ class ErrorCode {
2727
}
2828
};
2929

30+
/* ReturnValueClass is meant to represent all the cases where with a single value
31+
* we want to return an error, if the value is negative, or a meaningful result
32+
* if greater than or equal to 0.
33+
* In order to be retrocompatible with the previous definition boolean evaluation:
34+
* - It must return true, if the value is greater than or equal 0
35+
* - It must return false, if the value is negatie
36+
* - It must be evaluable as the primitive type associated with
37+
*/
38+
template<typename T>
39+
classReturnValueClass {
40+
public:
41+
constexprReturnValueClass(T value)
42+
: value(value >=0? value :0), error(value <0? value : ArduinoSuccess) {}
43+
44+
// it would be nice to have a default value on error to Success
45+
constexprReturnValueClass(T value,error_t error)
46+
: value(value), error(error) {}
47+
48+
const T value;
49+
consterror_t error;
50+
51+
constexproperatorbool()const {
52+
return error == ArduinoSuccess;
53+
}
54+
55+
constexproperatorT()const {
56+
return value;
57+
}
58+
};
59+
60+
using ReturnValue = ReturnValueClass<int>;
61+
using ReturnBoolValue = ReturnValueClass<bool>;
62+
using ReturnLongValue = ReturnValueClass<int64_t>;
3063

3164
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp