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

ResultValue.h
1 #pragma once
2
3 #include <fsdk/Types/Result.h>
4
5 #include <cassert>
6 #include <type_traits>
7 #include <utility>
8
9 namespace fsdk {
20 template <typename R, typename V, class Enable = void>
21 struct ResultValue : Result<R> {};
22
23 template <typename R, typename V>
24 struct ResultValue<R, V, typename std::enable_if<std::is_copy_constructible<V>::value>::type> : Result<R> {
26 typedef R EnumType;
27
29 typedef V ValueType;
30
34 ResultValue(R result) noexcept
35 : Result<R>(result)
36 , m_value{} {
37 }
38
43 ResultValue(R result, const V& value) noexcept
44 : Result<R>(result)
45 , m_value(value) {
46 }
47
52 ResultValue(R result, V&& value) noexcept
53 : Result<R>(result)
54 , m_value(std::move(value)) {
55 }
56
61 const V& getValue() const noexcept {
62 assert(this->isOk() && "Acessing value of erroneous result.");
63 return m_value;
64 }
65
72 V&& takeValue() noexcept {
73 return std::move(m_value);
74 }
75
80 const V* operator->() const noexcept {
81 return &getValue();
82 }
83
84 protected:
85 V m_value;
86 };
87
97 template <typename R, typename V>
98 struct ResultValue<R, V, typename std::enable_if<std::is_copy_constructible<V>::value == false>::type> :
99 Result<R> {
101 typedef R EnumType;
102
104 typedef V ValueType;
105
109 ResultValue(R result) noexcept
110 : Result<R>(result)
111 , m_value{} {
112 }
113
118 ResultValue(R result, V&& value) noexcept
119 : Result<R>(result)
120 , m_value(std::move(value)) {
121 }
122
127 const V& getValue() const noexcept {
128 assert(this->isOk() && "Acessing value of erroneous result.");
129 return m_value;
130 }
131
138 V&& takeValue() noexcept {
139 return std::move(m_value);
140 }
141
146 const V* operator->() const noexcept {
147 return &getValue();
148 }
149
150 protected:
151 V m_value;
152 };
153
164 template <typename R, typename V>
165 inline ResultValue<R, typename std::remove_const<typename std::remove_reference<V>::type>::type>
166 makeResultValue(R result, V&& value) noexcept {
167 return ResultValue<R, typename std::remove_const<typename std::remove_reference<V>::type>::type>(
168 result,
169 std::forward<V>(value));
170 }
171 } // namespace fsdk
fsdk::ResultValue< R, V, typename std::enable_if< std::is_copy_constructible< V >::value==false >::type >::ValueType
V ValueType
Result value type.
Definition: ResultValue.h:104
fsdk
SDK namespace.
Definition: IAGSEstimator.h:8
fsdk::ResultValue< R, V, typename std::enable_if< std::is_copy_constructible< V >::value==false >::type >::takeValue
V && takeValue() noexcept
Gets result value as rvalue.
Definition: ResultValue.h:138
fsdk::ResultValue< R, V, typename std::enable_if< std::is_copy_constructible< V >::value >::type >::ResultValue
ResultValue(R result, V &&value) noexcept
Initializes result.
Definition: ResultValue.h:52
fsdk::Result
A structure that encapsulates an action result enumeration.
Definition: Result.h:27
fsdk::ResultValue< R, V, typename std::enable_if< std::is_copy_constructible< V >::value==false >::type >::EnumType
R EnumType
Result enumeration type.
Definition: ResultValue.h:101
fsdk::ResultValue< R, V, typename std::enable_if< std::is_copy_constructible< V >::value >::type >::EnumType
R EnumType
Result enumeration type.
Definition: ResultValue.h:26
fsdk::ResultValue< R, V, typename std::enable_if< std::is_copy_constructible< V >::value >::type >::ResultValue
ResultValue(R result, const V &value) noexcept
Initializes result.
Definition: ResultValue.h:43
fsdk::ResultValue< R, V, typename std::enable_if< std::is_copy_constructible< V >::value >::type >::getValue
const V & getValue() const noexcept
Gets result value.
Definition: ResultValue.h:61
fsdk::ResultValue< R, V, typename std::enable_if< std::is_copy_constructible< V >::value==false >::type >::m_value
V m_value
Actual value.
Definition: ResultValue.h:151
fsdk::ResultValue< R, V, typename std::enable_if< std::is_copy_constructible< V >::value >::type >::takeValue
V && takeValue() noexcept
Gets result value as rvalue.
Definition: ResultValue.h:72
fsdk::ResultValue< R, V, typename std::enable_if< std::is_copy_constructible< V >::value==false >::type >::getValue
const V & getValue() const noexcept
Gets result value.
Definition: ResultValue.h:127
fsdk::makeResultValue
ResultValue< R, typename std::remove_const< typename std::remove_reference< V >::type >::type > makeResultValue(R result, V &&value) noexcept
Addon for Result to output some value aside the result.
Definition: ResultValue.h:166
fsdk::ResultValue
Addon for Result to output some value aside the result. Specialization for copiable types...
Definition: ResultValue.h:21
fsdk::ResultValue< R, V, typename std::enable_if< std::is_copy_constructible< V >::value==false >::type >::operator->
const V * operator->() const noexcept
Gets result value.
Definition: ResultValue.h:146
fsdk::ResultValue< R, V, typename std::enable_if< std::is_copy_constructible< V >::value==false >::type >::ResultValue
ResultValue(R result, V &&value) noexcept
Initializes result.
Definition: ResultValue.h:118
fsdk::ResultValue< R, V, typename std::enable_if< std::is_copy_constructible< V >::value >::type >::ResultValue
ResultValue(R result) noexcept
Initializes result.
Definition: ResultValue.h:34
fsdk::ResultValue< R, V, typename std::enable_if< std::is_copy_constructible< V >::value >::type >::ValueType
V ValueType
Result value type.
Definition: ResultValue.h:29
fsdk::ResultValue< R, V, typename std::enable_if< std::is_copy_constructible< V >::value==false >::type >::ResultValue
ResultValue(R result) noexcept
Initializes result.
Definition: ResultValue.h:109
fsdk::ResultValue< R, V, typename std::enable_if< std::is_copy_constructible< V >::value >::type >::operator->
const V * operator->() const noexcept
Gets result value.
Definition: ResultValue.h:80
fsdk::ResultValue< R, V, typename std::enable_if< std::is_copy_constructible< V >::value >::type >::m_value
V m_value
Actual value.
Definition: ResultValue.h:85
fsdk::Result< R >::isOk
bool isOk() const noexcept
Checks for a success.
Definition: Result.h:62