Face Engine SDK  5.25.0
A face detection, recognition and tracking engine.
include/fsdk/Types/Result.h
00001 #pragma once
00002 
00003 #include <cstdint>
00004 
00005 namespace fsdk {
00006 
00007     template <typename E>
00008     struct ErrorTraits {
00009         static bool isOk(E) noexcept {
00010             return false;
00011         }
00012 
00013         static const char* toString(E) noexcept {
00014             return "NOT AVAILABLE";
00015         }
00016     };
00017 
00026     template <typename E>
00027     struct Result {
00029         using ErrorType = E;
00030         using Traits = ErrorTraits<E>;
00031 
00035         explicit Result(E error) noexcept
00036             : m_error(error) {
00037         }
00038 
00041         Result() noexcept
00042             : m_error(E::Ok) {
00043         }
00044 
00048         E getError() const noexcept {
00049             return m_error;
00050         }
00051 
00055         bool isError() const noexcept {
00056             return !isOk();
00057         }
00058 
00062         bool isOk() const noexcept {
00063             return Traits::isOk(m_error);
00064         }
00065 
00069         operator bool() const noexcept {
00070             return isOk();
00071         }
00072 
00080         operator int() const noexcept = delete;
00081 
00087         const char* what() const noexcept {
00088             return Traits::toString(getError());
00089         }
00090 
00091     private:
00092         E m_error; 
00093     };
00094 
00095     template <typename E>
00096     inline Result<E> makeResult(E error) noexcept {
00097         return Result<E>(error);
00098     }
00099 } // namespace fsdk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines