| Face Engine SDK 5.34.0 A face detection, recognition and tracking engine.

Result.h
1 #pragma once
2
3 #include <cstdint>
4
5 namespace fsdk {
6
7 template <typename E>
8 struct ErrorTraits {
9 static bool isOk(E) noexcept {
10 return false;
11 }
12
13 static const char* toString(E) noexcept {
14 return "NOT AVAILABLE";
15 }
16 };
17
26 template <typename E>
27 struct Result {
29 using ErrorType = E;
30 using Traits = ErrorTraits<E>;
31
35 explicit Result(E error) noexcept
36 : m_error(error) {
37 }
38
41 Result() noexcept
42 : m_error(E::Ok) {
43 }
44
48 E getError() const noexcept {
49 return m_error;
50 }
51
55 bool isError() const noexcept {
56 return !isOk();
57 }
58
62 bool isOk() const noexcept {
63 return Traits::isOk(m_error);
64 }
65
69 operator bool() const noexcept {
70 return isOk();
71 }
72
80 operator int() const noexcept = delete;
81
87 const char* what() const noexcept {
88 return Traits::toString(getError());
89 }
90
91 private:
92 E m_error;
93 };
94
95 template <typename E>
96 inline Result<E> makeResult(E error) noexcept {
97 return Result<E>(error);
98 }
99 } // namespace fsdk
fsdk
SDK namespace.
Definition: IAGSEstimator.h:8
fsdk::Result
A structure that encapsulates an action result enumeration.
Definition: Result.h:27
fsdk::ErrorTraits
Definition: Result.h:8
fsdk::Result::what
const char * what() const noexcept
Gets a textual description of the result.
Definition: Result.h:87
fsdk::FSDKError::Ok
Ok.
fsdk::Result::Result
Result(E error) noexcept
Initializes result.
Definition: Result.h:35
fsdk::Result::getError
E getError() const noexcept
Gets actual result value.
Definition: Result.h:48
fsdk::Result::isError
bool isError() const noexcept
Checks for an error.
Definition: Result.h:55
fsdk::Result::Result
Result() noexcept
Initializes result by default.
Definition: Result.h:41
fsdk::Result< R >::ErrorType
R ErrorType
Result value enumeration type.
Definition: Result.h:29
fsdk::Result::isOk
bool isOk() const noexcept
Checks for a success.
Definition: Result.h:62