MCPcopy Create free account
hub / github.com/FastLED/FastLED / error_code

Class error_code

src/fl/stl/asio/error_code.h:31–67  ·  view source on GitHub ↗

Asio-compatible error code: numeric code + optional human-readable message. Maps to boost::system::error_code in Asio. Unlike fl::task::Error (string-only, heap allocation on every error), error_code is cheap to copy and supports quick boolean checks: if (ec) { /* error */ }

Source from the content-addressed store, hash-verified

29/// Unlike fl::task::Error (string-only, heap allocation on every error), error_code
30/// is cheap to copy and supports quick boolean checks: if (ec) { /* error */ }
31struct error_code {
32 errc code;
33 fl::string message; // optional human-readable detail
34
35 error_code() FL_NOEXCEPT : code(errc::success) {}
36 error_code(errc c) : code(c) {}
37 error_code(errc c, const fl::string &msg) : code(c), message(msg) {}
38 error_code(errc c, const char *msg) : code(c), message(msg) {}
39
40 /// Asio-style: true if error, false if success.
41 explicit operator bool() const { return code != errc::success; }
42
43 /// Convenience: true if no error.
44 bool ok() const { return code == errc::success; }
45
46 /// Convert from fl::task::Error for interop with existing FastLED code.
47 static error_code from_error(const fl::task::Error &e) {
48 if (e.is_empty()) {
49 return error_code();
50 }
51 return error_code(errc::unknown, e.message);
52 }
53
54 /// Convert to fl::task::Error for interop with existing FastLED code.
55 fl::task::Error to_error() const {
56 if (ok()) {
57 return fl::task::Error();
58 }
59 return fl::task::Error(message);
60 }
61
62 /// Convert from platform errno value.
63 static error_code from_errno(int platform_errno);
64
65 bool operator==(const error_code &o) const { return code == o.code; }
66 bool operator!=(const error_code &o) const { return code != o.code; }
67};
68
69} // namespace asio
70} // namespace fl

Callers 9

from_errorMethod · 0.85
from_errnoMethod · 0.85
connectMethod · 0.85
read_someMethod · 0.85
write_someMethod · 0.85
openMethod · 0.85
listenMethod · 0.85
acceptMethod · 0.85
spi_types.cpp.hppFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected