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

Result.h
1 #pragma once
2
3 #include <cstdint>
4
5 namespace fsdk
6 {
7
8 template<typename E>
9 struct ErrorTraits
10 {
11 static bool isOk(E) noexcept {
12 return false;
13 }
14
15 static const char* toString (E) noexcept {
16 return "NOT AVAILABLE";
17 }
18 };
19
28 template<typename E>
29 struct Result
30 {
32 using ErrorType = E;
33 using Traits = ErrorTraits<E>;
34
38 explicit Result(E error) noexcept
39 : m_error(error) {}
40
43 Result() noexcept
44 : m_error(E::Ok) {}
45
49 E getError() const noexcept {
50 return m_error;
51 }
52
56 bool isError() const noexcept {
57 return !isOk();
58 }
59
63 bool isOk() const noexcept {
64 return Traits::isOk(m_error);
65 }
66
70 operator bool () const noexcept {
71 return isOk();
72 }
73
79 const char* what() const noexcept {
80 return Traits::toString(getError());
81 }
82
83 private:
84 E m_error;
85 };
86
87 template<typename E>
88 inline Result<E> makeResult(E error) noexcept {
89 return Result<E>(error);
90 }
91 }
fsdk
SDK namespace.
Definition: IAGSEstimator.h:8
fsdk::Result::what
const char * what() const noexcept
Gets a textual description of the result.
Definition: Result.h:79
fsdk::Result::Result
Result() noexcept
Initializes result by default.
Definition: Result.h:43
fsdk::ErrorTraits
Definition: Result.h:10
fsdk::Result::isError
bool isError() const noexcept
Checks for an error.
Definition: Result.h:56
fsdk::Result::isOk
bool isOk() const noexcept
Checks for a success.
Definition: Result.h:63
fsdk::Result
A structure that encapsulates an action result enumeration.
Definition: Result.h:30
fsdk::Result::Result
Result(E error) noexcept
Initializes result.
Definition: Result.h:38
fsdk::Result::getError
E getError() const noexcept
Gets actual result value.
Definition: Result.h:49
fsdk::Result< R >::ErrorType
R ErrorType
Result value enumeration type.
Definition: Result.h:32