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

Commitc2c4b20

Browse files
Introducing ErrorCode
The objective of error code class to wrap an integer that may bereturned from a function that may fail for different reasons. Since weare not able to return values different from 0 in case of error in thearduino language we need to wrap them into this class and redefineboolean operator to mantain the same behaviour
1 parenta919d81 commitc2c4b20

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

‎api/ErrorCodes.h‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#pragma once
2+
#include<stdint.h>
3+
4+
namespacearduino {
5+
6+
typedefint_fast32_terror_t;
7+
8+
enum :error_t {
9+
ArduinoSuccess =0,
10+
ArduinoError =1,
11+
};
12+
13+
/* Error Codes:
14+
* In Arduino if a function returns 1 is considered to have run successfully,
15+
* any value different from 1 is considered an error.
16+
* Errors are generally represented with an int type that may vary in size depending on the platform.
17+
* For this reason in this representation error_t type is defined with an integer type with a defined size.
18+
*/
19+
classErrorCode {
20+
public:
21+
constexprErrorCode(int value): error(value ==1? ArduinoSuccess : ArduinoError) {}
22+
constexprErrorCode(error_t value): error(value) {}
23+
consterror_t error;
24+
25+
constexproperatorbool()const {
26+
return error == ArduinoSuccess;
27+
}
28+
};
29+
30+
31+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp